命令帮助系统
系统介绍 Claude Code 的帮助系统——claude --help、claude help 子命令、交互模式 /help、Tab 补全、在线文档查阅技巧,让你不查文档也能找到答案。
每次升级 Claude Code 都可能多一些新命令、新标志。要把所有命令都背下来既不现实也没必要。Claude Code 有完善的内置帮助系统,加上 Tab 补全和命令猜测,绝大多数时候你不用打开浏览器就能找到答案。
这篇文章把帮助系统的所有入口讲一遍:CLI 帮助、交互模式 /help、Tab 补全、错误时的”你是不是想说”、还有官方文档怎么高效查。每种方式都给真实输出例子。
五种帮助入口
| 入口 | 在哪用 | 看什么 |
|---|---|---|
claude --help | 终端 | 所有 CLI 命令和顶层标志 |
claude help <subcommand> | 终端 | 某个子命令的详细用法 |
/help | 交互界面 | 所有斜杠命令 |
| Tab 补全 | 终端 + 交互界面 | 当前位置可用的命令/参数 |
| 官方文档 | 浏览器 | 完整说明、最佳实践、改动日志 |
按”我手头有什么”找最合适的入口。
1. claude --help:CLI 总览
最常用的入口。在终端任何地方敲:
claude --help
输出(节选,实际更长):
Usage: claude [options] [command]
Claude Code - AI coding assistant in your terminal
Options:
-v, --version output version
-p, --print [prompt] Print response and exit
-c, --continue Continue last conversation
-r, --resume [sessionId] Resume conversation
--model <name> Choose model (sonnet, opus, haiku, ...)
--system-prompt <prompt> Override system prompt
--append-system-prompt <text> Append to system prompt
--allowedTools <tools> Comma-separated allowed tools
--disallowedTools <tools> Comma-separated disallowed tools
--permission-mode <mode> plan|acceptEdits|bypassPermissions|default
--dangerously-skip-permissions Skip ALL permission prompts
--output-format <format> text|json|stream-json
--input-format <format> text|stream-json
--max-turns <n> Limit tool-use turns
--verbose Verbose logging
-h, --help display help
Commands:
config Edit Claude Code config
mcp Manage MCP servers
update Update Claude Code
doctor Run diagnostic checks
help [command] Display help for command
这个输出能告诉你的:
- 有哪些子命令(
config、mcp、update、doctor) - 顶层标志大概有什么
- 参数的简写(
-p等于--print)
不能告诉你的:
- 子命令的具体用法(要进一步用
claude help <name>) - 每个标志值的合法范围(要看在线文档)
2. claude help <subcommand>:子命令详解
知道了子命令名,但不知道怎么用?查子命令帮助:
claude help mcp
输出:
Usage: claude mcp [options] [command]
Manage MCP (Model Context Protocol) servers
Options:
-h, --help display help
Commands:
add <name> [config] Add a new MCP server
remove <name> Remove an MCP server
list List configured MCP servers
status [name] Check connection status
serve Run as MCP server (advanced)
继续往下钻:
claude help mcp add
输出:
Usage: claude mcp add [options] <name> [args...]
Add a new MCP server
Options:
-t, --transport <type> Transport type (stdio|sse|http) [default: stdio]
-e, --env <KEY=VAL> Set environment variable (repeatable)
-s, --scope <scope> user|project|local [default: user]
-h, --help display help
Examples:
claude mcp add github
claude mcp add -t http github https://api.example.com
claude mcp add -e API_KEY=xxx custom-server
Examples 那一段非常重要。Claude Code 大部分子命令的帮助都带例子,照着改就能用。
两种语法等价:
# 这两个一样
claude help mcp
claude mcp --help
习惯用哪种都行。我个人偏爱 claude help xxx,因为它跟 man xxx 更像。
3. 交互模式 /help
启动 REPL 后:
claude
在对话里输入:
> /help
输出(节选):
Available slash commands:
Conversation:
/clear Clear conversation history
/compact Compact history to save tokens
/exit Exit Claude Code
Configuration:
/config Edit configuration
/model Change current model
/permissions Edit permission rules
/hooks Edit hooks
/login Sign in
/logout Sign out
Information:
/status Show session status
/cost Show token usage and cost
/release-notes Show what's new
/bug Submit a bug report
Project:
/init Create CLAUDE.md
/review Request code review
Custom:
(No custom slash commands defined)
Type /help <command> for details
每个斜杠命令也可以查详细:
> /help compact
/compact - Compact conversation history
Reduces token usage by summarizing earlier messages while keeping
key context. Useful for long sessions before starting new topics.
Usage:
/compact # Auto-decide what to keep
/compact <focus> # Keep details related to <focus>
Example:
/compact React hooks # Compact but keep React hooks discussion
/help <command> 是很多人不知道的细节。它对每个斜杠命令都有效。
4. Tab 补全:最快的入口
Tab 补全是没有上面任何记忆负担的方式。在两个地方都能用:
终端里
$ claude --mo<Tab>
$ claude --model ← 自动补全
$ claude --model <Tab>
claude-haiku-4-7 claude-sonnet-4-7 claude-opus-4-7 ← 列出可选值
要让终端补全工作,需要先安装补全脚本。Claude Code 提供了:
# Bash
claude completion bash > ~/.local/share/bash-completion/completions/claude
# Zsh
claude completion zsh > "${fpath[1]}/_claude"
# Fish
claude completion fish > ~/.config/fish/completions/claude.fish
然后重启 shell 或 source 一下配置文件。
交互界面里
进入 REPL 后,敲 / 然后按 Tab:
> /<Tab>
clear compact config cost exit help hooks init
login logout model permissions release-notes review
status bug
继续敲字符再 Tab,会缩小范围:
> /co<Tab>
compact config cost
Tab 补全的好处是永远是最新的——升级 Claude Code 后新增的命令会自动出现,不用查文档。
5. 错误时的提示
打错命令时 Claude Code 会给你建议:
$ claude --modle claude-opus-4-7
error: unknown option '--modle'
Did you mean '--model'?
$ claude mcp adde my-server
error: unknown command 'adde'
Did you mean 'add'?
斜杠命令也一样:
> /clera
Unknown command: /clera
Did you mean: /clear?
这种”猜测”是 Levenshtein 距离算法做的,相差 1-2 个字符基本都能猜对。
6. 官方文档:深度参考
CLI 帮助适合速查,遇到下面这些情况要去官方文档:
- 看 hook 的所有事件类型和数据结构
- 看 MCP 协议规范
- 看完整的 settings.json schema
- 看版本变更
- 看最佳实践教程
官方文档地址:
https://docs.claude.com/en/docs/claude-code/
主要章节:
| 章节 | 内容 |
|---|---|
| Overview | 入门 |
| CLI Reference | 命令完整参考 |
| Settings | settings.json 全字段 |
| Hooks | hook 事件、数据结构、安全 |
| MCP | MCP 配置和开发 |
| SDK | TypeScript/Python SDK |
| Subagents | 子智能体配置 |
| Common Workflows | 常见工作流 |
一个高效查文档的小技巧: 直接用 Claude Code 自己去查。开个新会话:
claude -p "查一下 Claude Code 的 PostToolUse hook 接收什么参数, \
从 docs.claude.com 找答案" \
--allowedTools "WebFetch"
它会自己 fetch 文档页,给你提炼答案。
7. 用 Claude 自己问 Claude
最被忽视的”帮助方式”——直接问 Claude Code 自己。
$ claude -p "我想让 Claude 在改完代码后自动跑测试, 配 hook 怎么写?"
输出(节选):
你需要在 ~/.claude/settings.json 里加一个 PostToolUse hook,
监听 Edit 和 Write 工具。配置示例:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [{
"type": "command",
"command": "npm test"
}]
}
]
}
}
...
Claude Code 自己受过它自身配置的训练,回答相关问题往往比你查文档快。建议优先这样问:
- “如何用 -p 模式跳过权限确认?”
- “/compact 和 /clear 区别?”
- “怎么把 Claude 集成到 GitHub Action?”
实战:场景到入口的对照
| 我想知道 | 用什么 |
|---|---|
| Claude 都有哪些子命令 | claude --help |
claude mcp 怎么用 | claude help mcp |
| 对话里能输入什么斜杠命令 | /help |
/compact 具体怎么用 | /help compact |
--model 接哪些值 | Tab 补全 |
| 我打错了一个标志 | 看错误信息的建议 |
| hook 完整参数列表 | 官方文档 |
| 最佳实践 | 官方文档 + 直接问 Claude |
常见问题
Q: Tab 补全没生效怎么办?
第一步看是不是装了补全脚本(参考前面 claude completion 那段)。第二步看 shell 是不是 bash/zsh/fish 之一——其他 shell 可能不支持。第三步重启 shell 或开新窗口。
# 验证补全脚本是否被加载
type _claude # zsh
complete -p claude # bash
Q: claude --help 输出太长,怎么找特定标志?
管道 grep:
claude --help | grep -A 1 "model"
claude --help | grep "format"
或者用 less 翻页:
claude --help | less
Q: claude help xxx 和 claude xxx --help 哪个权威?
完全一样,都是同一份帮助文本。无需纠结。
Q: 有没有 man claude?
Claude Code 暂不提供 man page。要看长文档建议用 claude --help | less 或访问在线文档。
Q: 如何查看某个版本新增了什么?
进 REPL 后输入:
> /release-notes
会显示当前版本的更新内容。也可以在 GitHub 看 release:
https://github.com/anthropics/claude-code/releases
Q: 我自己写的斜杠命令在 /help 里看得到吗?
看得到。把命令文件放在 ~/.claude/commands/(全局)或 ./.claude/commands/(项目级)下,会自动出现在 /help 输出的 Custom 区域。
快速参考:四个动作记一辈子
任何命令、任何场景,记住这四个动作就够:
- 猜不出命令 → 在终端
claude --help,在对话/help - 知道命令不知道用法 →
claude help <name>或/help <name> - 不想敲完整名 → Tab 补全
- 想要详细说明 → 直接问 Claude(
claude -p "...")
帮助系统不是用来”全部背下来”的。它是用来”我需要的时候立刻能找到”的。
标记本节教程为已读
记录您的学习进度,方便后续查看。