Skip to content

斜杠命令

内置斜杠命令

命令用途
/add-dir添加额外的工作目录
/agents管理用于专门任务的自定义 AI 子代理
/bashes列出并管理后台任务
/bug报告错误
/clear清除对话历史
/compact [instructions]压缩对话
/config打开设置界面
/context将当前上下文使用情况可视化
/cost显示令牌使用统计信息
/doctor检查 Claude Code 安装的健康状况
/exit退出 REPL
/export [filename]将当前对话导出到文件
/help获取使用帮助
/hooks管理工具事件的钩子配置
/init使用 CLAUDE.md 指南初始化项目
/login切换 Anthropic 账户
/logout从 Anthropic 账户登出
/mcp管理 MCP 服务器连接
/memory编辑 CLAUDE.md 内存文件
/model选择或更改 AI 模型
/permissions查看或更新权限
/review请求代码审查
/sandbox启用沙箱化 bash 工具
/status显示版本、模型、账户信息
/vim进入 vim 模式

自定义斜杠命令

自定义斜杠命令允许您将经常使用的提示定义为 Markdown 文件。

项目命令

存储在您的存储库中并与您的团队共享的命令。

位置: .claude/commands/

bash
mkdir -p .claude/commands
echo "Analyze the performance of this code:" > .claude/commands/optimize.md

使用: > /optimize

个人命令

在所有项目中可用的命令。

位置: ~/.claude/commands/

bash
mkdir -p ~/.claude/commands
echo "Review this code for security vulnerabilities:" > ~/.claude/commands/security-review.md

使用: > /security-review

功能

命名空间

在子目录中组织命令。位于 .claude/commands/frontend/component.md 的文件创建命令 /component,描述显示"(project:frontend)"。

参数

使用 $ARGUMENTS 的所有参数

markdown
Find and fix issue #$ARGUMENTS.

使用: > /fix-issue 123

使用 $1、$2 等的单个参数

markdown
Create a $1 component named $2.

使用: > /create-component button MyButton

Bash 命令执行

使用 ! 前缀在斜杠命令运行之前执行 bash 命令:

markdown
!git diff --staged
Review the staged changes above.

文件引用

使用 @ 前缀在命令中包含文件内容:

markdown
Review the code in @src/main.ts

前置事项

yaml
---
description: Analyze code performance
allowed-tools: Read, Grep, Glob
model: sonnet
---

Analyze the performance of this code...

MCP 斜杠命令

MCP 服务器可以将提示公开为斜杠命令:

> /mcp__github__list_prs
> /mcp__github__pr_review 456

技能与斜杠命令

方面斜杠命令代理技能
复杂性简单提示复杂功能
结构单个 .md 文件带有 SKILL.md + 资源的目录
发现显式调用自动(基于上下文)
范围项目或个人项目或个人

使用斜杠命令:快速、经常使用的提示 使用技能:具有结构的全面功能

aicodex 文档网站