全部教程Claude Code 速查手册(2026 完整版)

Claude Code 速查手册(2026 完整版)

我是 OpenClaw 的作者 Quentin。这份速查手册是我自己日常翻的那一份——把 Claude Code 从 0.1 用到现在所有需要查的东西,整理在一页里。Ctrl/Cmd+F 比看视频快。

5 秒接入拼车,再回来读这份手册

curl -fsSL https://cp.bizq.net/setup.sh | bash -s -- claude-max-20x

1. 安装

平台命令
macOS / Linux(推荐)curl -fsSL https://claude.ai/install.sh | bash
Homebrewbrew install anthropic/claude/claude-code
Windows(PowerShell)irm https://claude.ai/install.ps1 | iex
通过 npmnpm install -g @anthropic-ai/claude-code

启动:

claude              # 在当前目录启动交互模式
claude /path/to/dir # 指定项目目录

升级:

claude update                              # 自更新
npm install -g @anthropic-ai/claude-code   # 如果用的是 npm

OpenClaw 用户不需要手动配 base URL:拼车通道写在 auth.profiles.anthropic:carpool 里,与 Claude Code 自身配置完全隔离。


2. 配置命令

claude config list                         # 看全部
claude config get model                    # 看单项
claude config set model claude-sonnet-4-6  # 改全局
claude config set --project model opus-4-7 # 改项目级(写到 .claude/)
claude config add allowed-tools Bash       # 列表型 +1
claude config remove allowed-tools Bash    # 列表型 -1

--project 写到 .claude/settings.json--user 写到 ~/.claude/settings.json。优先级:项目 > 用户 > 默认。


3. 快捷键(交互模式内)

按键行为
Esc中断当前生成
Esc Esc跳到上一条消息(可重新编辑)
Shift+Tab在「常规 / 自动接受 / 计划」三模式间循环
Ctrl+V粘贴图片到终端(macOS 用这个,不是 Cmd+V)
Tab文件路径自动补全
# 开头把这一行直接追加到 CLAUDE.md
! 开头进入 Bash 模式直接跑命令,不消耗 token
/ 开头触发斜杠命令
Up/Down浏览历史输入

4. 检查点 / 撤销

Claude Code 每次工具调用前自动建检查点。回滚:

回滚              # 回到上一个检查点
撤销              # 撤销「回滚」本身

配合 Git 用更稳——别把 checkpoint 当唯一防线。


5. 斜杠命令(内置)

命令用途
/help帮助
/exit /quit退出
/clear清空对话历史
/init在当前项目生成 CLAUDE.md
/compact压缩上下文(保留摘要)
/cost看本次会话 token 消耗
/mcp看 MCP 服务器状态
/agents管理子代理
/permissions管理工具权限
/review触发代码审查
/resume选历史会话继续
/login /logout切换账户

6. 自定义斜杠命令

放在 .claude/commands/<name>.md(项目级)或 ~/.claude/commands/<name>.md(个人级)。

最简版:

---
description: 跑一遍 lint 并修
---
 
请运行 `npm run lint`,把每一处 error 修掉,再跑一次确认通过。

带位置参数:

---
description: 解决 GitHub issue
argument-hint: <issue-number>
---
 
`gh issue view $1`,分析、改代码、提 PR。

带模型覆盖:

---
description: 用 Opus 重构
model: claude-opus-4-7
---
 
重构 $ARGUMENTS 这个文件,目标:减少圈复杂度、抽公共函数。

调用:/lint/solve-issue 482


7. 无头模式(Headless)

非交互、可脚本化:

claude -p "总结这段日志" < error.log
claude -p "生成迁移 SQL" --output-format json
claude --print --dangerously-skip-permissions "批量重命名"

输出格式:

--output-format用途
text(默认)纯文本
json单个 JSON 对象(含 cost、usage)
stream-json逐事件 JSON 流,喂给监控

多轮:

SESSION=$(claude -p "起一个新项目" --output-format json | jq -r .session_id)
claude -p --resume "$SESSION" "加 Dockerfile"
claude -p --resume "$SESSION" "写 GitHub Actions"

CI 例子(安全审计):

claude -p \
  --allowed-tools "Read Grep" \
  --disallowed-tools "Bash Write Edit" \
  "审查 src/ 中所有路径拼接,列出可能的路径遍历漏洞" \
  > audit.md

8. 代理技能(Agent Skills)

模块化能力包,按需加载,比纯系统提示词便宜得多。

命令作用
/agentsSkills启用 / 禁用技能
~/.claude/skills/<name>/个人技能目录
.claude/skills/<name>/项目技能目录

最简结构:

.claude/skills/sql-reviewer/
├── SKILL.md          # 触发条件 + 系统提示
└── references/
    └── postgres.md   # 按需加载的参考资料

SKILL.md frontmatter:

---
name: sql-reviewer
description: 审查 SQL 查询,标注性能与安全问题
allowed-tools: [Read, Grep]
---

技能 vs 斜杠命令:

斜杠命令技能
触发用户主动 /cmd模型自己判断要不要用
上下文一次性塞进去渐进式(先 SKILL.md,需要才读 references)
适合流程固定的操作一类领域知识

9. 插件(Plugins)

把命令、技能、子代理、Hooks 打包分发。

/plugin marketplace add <github-url>     # 加市场
/plugin install <plugin-name>            # 装
/plugin list                             # 看已装
/plugin remove <plugin-name>             # 卸载

本地开发:

mkdir -p my-plugin/{commands,skills,agents,hooks}
# 在 my-plugin/plugin.json 写元数据
/plugin marketplace add file:///abs/path/to/my-plugin

10. MCP 服务器

claude mcp list                                # 看全部
claude mcp get <name>                          # 看单个
claude mcp add <name> <command> [args...]      # stdio 方式
claude mcp add-json -s user <name> '<json>'    # JSON 方式
claude mcp add --transport sse <name> <url>    # SSE
claude mcp remove <name>                       # 删

-s user = 写到 ~/.claude.json(全局);不写 -s = 项目级。

常装的几个:

# Playwright(浏览器自动化)
claude mcp add playwright -s user -- npx @playwright/mcp@latest
 
# Context7(最新版库文档)
claude mcp add-json -s user context7 '{"command":"npx","args":["-y","@upstash/context7-mcp"]}'
 
# Sequential Thinking
claude mcp add sequential-thinking -s user -- npx -y @modelcontextprotocol/server-sequential-thinking
 
# Filesystem
claude mcp add filesystem -s user -- npx -y @modelcontextprotocol/server-filesystem ~/Documents
 
# GitHub
claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=$TOKEN -- npx "@modelcontextprotocol/server-github"

OAuth 类(Asana / Linear / Notion / Stripe / Vercel / Supabase / Cloudflare 等)走 claude mcp add --transport http <name> <oauth-url>,初次使用会弹浏览器授权。


11. Git Worktree(并行开发)

主仓库忙着跑测试,开个 worktree 让 Claude Code 改另一个分支。

git worktree add ../proj-hotfix hotfix/bug-1234
cd ../proj-hotfix
claude

模型对比:A 个 worktree 用 Sonnet,B 个 worktree 用 Opus,跑同一道题,看谁的方案好。

清理:

git worktree list
git worktree remove ../proj-hotfix

12. 子代理(Sub-agents)

把专项工作分流出去,不污染主对话上下文。

放在:

  • .claude/agents/<name>.md 项目级
  • ~/.claude/agents/<name>.md 个人级

文件格式:

---
name: debugger
description: 拿到错误信息后,定位、复现、修复
tools: [Read, Edit, Bash, Grep]
model: claude-sonnet-4-6
---
 
你是一个专业 debugger……(系统提示)

调用:

> /agents
> @debugger 这个 stacktrace 是怎么回事?

或主对话里直接说「让 debugger 看一下」。


13. 权限模型

.claude/settings.json 里写:

{
  "permissions": {
    "allow": ["Bash(npm test)", "Bash(git status)", "Read", "Grep"],
    "deny":  ["Bash(rm -rf*)", "Bash(curl*)", "Write(./.env)"],
    "ask":   ["Edit", "Bash"]
  }
}

allow 自动放行,deny 直接拒绝,ask 弹确认。Bash(...) 里支持 glob。

企业级(团队默认):

{
  "permissions": {
    "defaultMode": "askForBash",
    "deny": ["Bash(sudo*)", "Bash(rm -rf*)", "Read(./.env)"],
    "mcp": {
      "github": { "allow": ["read_*"], "deny": ["delete_*"] }
    }
  }
}

14. Hooks

在事件发生时自动跑命令。.claude/settings.json

{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash", "hooks": [{ "type": "command", "command": "echo $TOOL_INPUT >> ~/.claude/audit.log" }] }
    ],
    "PostToolUse": [
      { "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "npm run lint --silent" }] }
    ],
    "Stop": [
      { "hooks": [{ "type": "command", "command": "say done" }] }
    ]
  }
}

事件清单:

事件触发时机
SessionStart启动会话
UserPromptSubmit用户回车前
PreToolUse工具调用前(可拦)
PostToolUse工具调用后
Notification系统通知
Stop助手停止响应
SubagentStop子代理结束
PreCompact自动压缩前
SessionEnd会话退出

安全提醒:Hooks 是你机器上以你身份执行任意命令——别从不信任的源装含 hooks 的插件。


15. CLAUDE.md 写什么

这个文件每次请求自动注入。建议写:

  • 项目栈:语言、框架、版本
  • 目录约定:src/ tests/ migrations/ 各放什么
  • 命令约定:跑测试、起 dev、build 的命令
  • 风格:是否禁用某些语法、命名规则
  • 不要做的事:禁止改 migrations/ 里的旧文件、禁止 console.log

/init 自动生成第一版,然后用 # 在对话中持续追加。


16. 拼车与 OpenClaw

OpenClaw 是开源 AI Agent 框架。我把 Claude Code 拼车通道做进了 OpenClaw 的认证层,所以——

curl -fsSL https://cp.bizq.net/setup.sh | bash -s -- claude-max-20x

这条命令做的事:装 OpenClaw(如缺)、拉拼车 blueprint、写 auth.profiles.anthropic:carpool、烟雾测试。请求路径还是直连 api.anthropic.com,我们只在 token 层做账号轮转,不经过我们的服务器

查用量:

openclaw carpool usage              # 自己的
openclaw carpool fleet              # 全车队(车主)
openclaw doctor --carpool           # 健康检查

退出:openclaw carpool leave 一行干净拆除。


立即开始

curl -fsSL https://cp.bizq.net/setup.sh | bash -s -- claude-max-20x

把这页加书签,遇到问题 Ctrl+F 搜关键字基本能找到。


相关文章