mcpField
S
slash-commands

slash-commands

github.com/parcadeiAgent 工作流3.9k491 次安装39 周前更新
代码仓库

关于 slash-commands

面向 Claude Code 用户的斜杠命令参考技能,介绍如何创建和使用用户触发的提示词,并说明命令文件、参数、Bash 执行、文件引用及其与 skills 的区别。

主要功能

  1. 01内置命令参考
  2. 02项目和个人命令设置
  3. 03YAML 前置元数据与参数
  4. 04在提示词中执行 Bash
  5. 05文件引用与命名空间
  6. 06MCP 服务提供的命令

适用场景

  1. 01创建可复用的项目或个人提示词
  2. 02为命令添加参数和文件引用
  3. 03在加载提示词前运行 Bash 命令
  4. 04选择使用斜杠命令或 skills

MCP 相关

说明 MCP 服务可将提示词作为斜杠命令提供,并给出调用示例。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/parcadei/continuous-claude-v3 --skill slash-commands

安装后在 Claude Code 中输入/slash-commands确认已加载。

详细介绍

斜杠命令参考

使用 /command-name 语法创建并使用由用户触发的提示词。

适用场景

  • “如何创建斜杠命令?”
  • “有哪些斜杠命令可用?”
  • “在我的命令中添加 bash”
  • “在命令中使用文件引用”
  • “斜杠命令与技能有什么区别?”

内置命令

命令用途
/clear清除对话历史记录
/compact聚焦并压缩对话
/config打开设置界面
/cost显示 Token 用量
/agents管理子 Agent
/mcp管理 MCP 服务
/memory编辑 CLAUDE.md 文件
/model选择 AI 模型
/review请求代码审查
/resume恢复会话
/help获取使用帮助

创建命令

项目命令
mkdir -p .claude/commands
cat > .claude/commands/optimize.md << 'EOF'
---
description: Analyze code for performance issues
---

Review this code for:
- Performance bottlenecks
- Memory leaks
- Caching opportunities
EOF
个人命令
mkdir -p ~/.claude/commands
cat > ~/.claude/commands/review.md << 'EOF'
---
description: Security-focused code review
---

Check for vulnerabilities:
- Input validation
- SQL injection
- XSS risks
EOF

命令文件格式

---
description: Brief description for /help
allowed-tools: [Bash, Read, Write]  # Optional
argument-hint: "[file] [type]"       # Optional
---

Your markdown instructions here.
Use $1, $2 for arguments or $ARGUMENTS for all.

执行 Bash

在加载提示词前,使用 ! 前缀运行 bash:

---
allowed-tools: Bash(git:*), Bash(grep:*)
description: Git commit helper
---

Current status: !`git status`
Staged changes: !`git diff --staged`
Recent commits: !`git log --oneline -5`

Based on these changes, suggest a commit message.

规则:

  • 必须在 frontmatter 中声明 allowed-tools: Bash(...)
  • 使用反引号:!`command`
  • 输出会包含在 Claude 的上下文中

文件引用

使用 @ 前缀包含文件:

Review against @.claude/STYLE_GUIDE.md

Compare:
- @src/old.js
- @src/new.js

Refactor files matching @src/**/*.util.ts

参数

---
argument-hint: "[pr-number] [priority]"
---

Review PR #$1 with priority: $2

# Or use all arguments:
Fix issue #$ARGUMENTS

用法:

/review-pr 456 high
# $1 = "456", $2 = "high"

命名空间

使用子目录进行组织:

.claude/commands/
├── frontend/
│   └── component.md    → /component (project:frontend)
└── backend/
    └── endpoint.md     → /endpoint (project:backend)

MCP 斜杠命令

MCP 服务会将提示词作为命令公开:

/mcp__github__list_prs
/mcp__github__pr_review 456
/mcp__jira__create_issue "Bug" high

斜杠命令与技能的区别

方面斜杠命令技能
调用方式显式:/command自动发现
文件单个 .md 文件包含 SKILL.md 的目录
使用场景快速提示词复杂工作流

使用斜杠命令的场景: 经常输入的提示词、简单模板
使用技能的场景: 复杂工作流、多个文件、自动发现

示例:完整的 Git 提交命令

---
description: Generate semantic commit message
allowed-tools: Bash(git:*), Read
argument-hint: "[type]"
---

# Semantic Commit Generator

Staged files: !`git diff --name-only --cached`

Diff preview:
!`git diff --cached | head -100`

Generate a conventional commit message.
Type: $1 (feat/fix/docs/style/refactor/perf/test/chore)

Format: `<type>(<scope>): <subject>`

用法: /commit feat

评论

支持 Markdown