commands提供了调用claude预定义能力的快捷方式。
内置命令#
内置命令覆盖了绝大多数使用场景与功能。在claude中输入 /查看完整列表,或输入 /后跟任何字母进行过滤。
| 命令 | 用途 |
|---|---|
/add-dir <path> | 添加工作目录 |
/agents | 管理代理配置 |
/branch [name] | 将对话分支到新会话(别名:/fork)。注意:/fork在v2.1.77中重命名为 /branch |
/btw <question> | 不添加到历史的旁注问题 |
/chrome | 配置Chrome浏览器集成 |
/clear | 清除对话(别名:/reset、/new) |
/color [color|default] | 设置提示栏颜色 |
/compact [instructions] | 使用可选聚焦指令压缩对话 |
/config | 打开设置(别名:/settings) |
/context | 以彩色网格可视化上下文使用情况 |
/copy [N] | 将助手响应复制到剪贴板;w写入文件 |
/cost | 显示token使用统计 |
/desktop | 在桌面应用中继续(别名:/app) |
/diff | 未提交更改的交互式diff查看器 |
/doctor | 诊断安装健康状态 |
/effort [low|medium|high|xhigh|max|auto] | 通过交互式箭头键滑块设置努力级别。级别:low → medium → high → xhigh(v2.1.111新增)→ max。Opus 4.7默认为 xhigh;max仅限Opus 4.7 |
/exit | 退出REPL(别名:/quit) |
/export [filename] | 将当前对话导出到文件或剪贴板 |
/extra-usage | 配置速率限制的额外使用 |
/fast [on|off] | 切换快速模式 |
/feedback | 提交反馈(别名:/bug) |
/focus | 切换焦点视图(v2.1.110新增;替换 Ctrl+O用于焦点切换) |
/help | 显示帮助 |
/hooks | 查看钩子配置 |
/ide | 管理IDE集成 |
/init | 初始化 CLAUDE.md。设置 CLAUDE_CODE_NEW_INIT=1以启用交互式流程 |
/insights | 生成会话分析报告 |
/install-github-app | 设置GitHub Actions应用 |
/install-slack-app | 安装Slack应用 |
/keybindings | 打开键绑定配置 |
/less-permission-prompts | 分析最近的Bash/MCP工具调用并将优先级允许列表添加到 .claude/settings.json以减少权限提示(v2.1.111新增) |
/login | 切换Anthropic账户 |
/logout | 退出Anthropic账户 |
/mcp | 管理MCP服务器和OAuth |
/memory | 编辑 CLAUDE.md,切换自动内存 |
/mobile | 移动应用的二维码(别名:/ios、/android) |
/model [model] | 使用左右箭头选择模型以调整努力 |
/passes | 分享Claude Code免费周 |
/permissions | 查看/更新权限(别名:/allowed-tools) |
/plan [description] | 进入规划模式 |
/plugin | 管理插件 |
/proactive | /loop的别名(v2.1.105新增) |
/powerup | 通过带动画演示的交互式课程发现功能 |
/privacy-settings | 隐私设置(仅Pro/Max) |
/release-notes | 查看更新日志 |
/recap | 返回会话时显示会话回顾/摘要(v2.1.108新增) |
/reload-plugins | 重新加载活动插件 |
/remote-control | 从claude.ai远程控制(别名:/rc) |
/remote-env | 配置默认远程环境 |
/rename [name] | 重命名会话 |
/resume [session] | 恢复对话(别名:/continue) |
/review | 已弃用 — 安装 code-review插件代替 |
/rewind | 回溯对话和/或代码(别名:/checkpoint) |
/sandbox | 切换沙箱模式 |
/schedule [description] | 创建/管理云端计划任务 |
/security-review | 分析分支的安全漏洞 |
/skills | 列出可用技能 |
/stats | 可视化每日使用情况、会话、连续天数 |
/stickers | 订购Claude Code贴纸 |
/status | 显示版本、模型、账户 |
/statusline | 配置状态栏 |
/tasks | 列出/管理后台任务 |
/team-onboarding | 从项目的Claude Code设置生成队友入门指南(v2.1.101新增) |
/terminal-setup | 配置终端键绑定 |
/theme | 更改颜色主题 |
/tui | 切换全屏TUI(文本用户界面)模式,无闪烁渲染(v2.1.110新增) |
/ultraplan <prompt> | 在ultraplan会话中起草计划,在浏览器中审查 |
/ultrareview | 基于云的多代理分析全面代码审查(v2.1.111新增) |
/undo | /rewind的别名(v2.1.108新增) |
/upgrade | 打开升级页面以获得更高计划层级 |
/usage | 显示计划使用限制和速率限制状态 |
/voice | 切换按住说话语音听询 |
自定义命令#
最新版本Claude Code已经将commands合并到skills中,具体细节可参考 claude code教程:skills
| 方法 | 位置 | 状态 |
|---|---|---|
| 技能(推荐) | .claude/skills/<name>/SKILL.md | 当前标准 |
| 传统命令 | .claude/commands/<name>.md | 仍然工作 |
如果技能和命令共享相同名称,技能优先。例如,当同时存在 .claude/commands/review.md和 .claude/skills/review/SKILL.md时,使用技能版本。
以下几个示例将从格式约束、内容结构上展示如何创建自定义命令。
示例1:代码优化#
---
description: Analyze code for performance issues and suggest optimizations
---
# Code Optimization
Review the provided code for the following issues in order of priority:
1. **Performance bottlenecks** - identify O(n²) operations, inefficient loops
2. **Memory leaks** - find unreleased resources, circular references
3. **Algorithm improvements** - suggest better algorithms or data structures
4. **Caching opportunities** - identify repeated computations
5. **Concurrency issues** - find race conditions or threading problems
Format your response with:
- Issue severity (Critical/High/Medium/Low)
- Location in code
- Explanation
- Recommended fix with code example示例2:API文档生成#
---
description: Create comprehensive API documentation from source code
---
# API Documentation Generator
Generate API documentation by:
1. Scanning all files in `/src/api/`
2. Extracting function signatures and JSDoc comments
3. Organizing by endpoint/module
4. Creating markdown with examples
5. Including request/response schemas
6. Adding error documentation
Output format:
- Markdown file in `/docs/api.md`
- Include curl examples for all endpoints
- Add TypeScript types示例3:代码提交#
---
description: Create git commit with dynamic context from repository
allowed-tools: Bash(git add:*), Bash(git commit:*), Bash(git status:*), Bash(git diff:*), Bash(git log:*)
---
# Git Commit with Context
Create a git commit with relevant repository context.
## Steps
1. Run in parallel to gather context:
- `git status` - show working tree status
- `git diff` - show both staged and unstaged changes
- `git log -1 --oneline` - show recent commit message
2. Analyze all staged and newly added changes
3. Draft a concise commit message:
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
- Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
- Do not commit files that likely contain secrets (.env, credentials.json, etc). Warn the user if they specifically request to commit those files
- Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
- Ensure it accurately reflects the changes and their purpose
4. Run sequentially:
- Add relevant untracked files
- Create commit with message
- Run git status after commit to verify success