claude-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese@rules/routing.md
@rules/routing.md
Claude Code Skill
Claude Code Skill
Source of truth: https://code.claude.com/docs/en/cli-reference.
Defaults
默认设置
| Parameter | Default |
|---|---|
| Model selection | Use Claude Code CLI default unless the user explicitly asks for |
| Effort | Use CLI default unless the user explicitly asks for |
| Permission mode | |
| Headless mode | |
| CI / scripted run | Add |
| Resume target | |
Do NOT ask the user for model or effort unless explicitly requested.
| 参数 | 默认值 |
|---|---|
| 模型选择 | 除非用户明确要求使用 |
| 工作力度 | 除非用户明确要求使用 |
| 权限模式 | |
| 无头模式 | |
| CI/脚本化运行 | 添加 |
| 恢复目标 | 当前目录中最新会话使用 |
除非用户明确要求,否则不要询问用户关于模型或工作力度的选择。
Routing
路由规则
Use this skill when the request actually needs the CLI or a separate Claude Code session.
claude- Read rules/routing.md before building a command when the request might be out of scope.
- Route away to direct editing or another skill when the user wants generic writing, documentation cleanup, or local edits without needing the CLI itself.
claude
当请求确实需要使用 CLI或独立的Claude Code会话时,使用此技能。
claude- 当请求可能超出范围时,在构建命令前阅读rules/routing.md。
- 当用户需要通用写作、文档清理或无需CLI的本地编辑时,将请求转至直接编辑或其他技能。
claude
Examples
示例
Positive triggers:
- "Use Claude Code to review this repository and summarize the risks."
- "Run in print mode and analyze this architecture."
claude - "Continue the last Claude Code session and ask it to finish the patch."
- "Resume the claude session and apply the next fix."
auth-refactor - "Use so this CI step does not pick up local hooks."
claude --bare -p
Negative triggers:
- "Rewrite this runbook for readability."
- "Create a new skill for our repo."
Boundary trigger:
- "Research Claude Code permissions and tell me what they do."
Use this skill only if the user wants the CLI involved; otherwise route to research or direct documentation work.
claude
正向触发场景:
- "Use Claude Code to review this repository and summarize the risks."
- "Run in print mode and analyze this architecture."
claude - "Continue the last Claude Code session and ask it to finish the patch."
- "Resume the claude session and apply the next fix."
auth-refactor - "Use so this CI step does not pick up local hooks."
claude --bare -p
负向触发场景:
- "Rewrite this runbook for readability."
- "Create a new skill for our repo."
边界触发场景:
- "Research Claude Code permissions and tell me what they do."
仅当用户希望涉及CLI时使用此技能;否则转至研究或直接文档处理工作。
claude
Critical: Print Mode
关键:打印模式
Always use / for non-interactive Claude Code runs. Positional prompts without start the interactive REPL instead, so a script that omits will hang waiting for a TTY.
-p--print-p-pbash
undefined对于非交互式Claude Code运行,始终使用/。不带的位置提示符会启动交互式REPL,因此省略的脚本会挂起等待TTY输入。
-p--print-p-pbash
undefinedNon-interactive (headless / SDK)
非交互式(无头/SDK)
claude --permission-mode default -p "your prompt here"
claude --permission-mode default -p "your prompt here"
Interactive REPL (initial prompt only — does NOT exit)
交互式REPL(仅初始提示符——不会退出)
claude "your prompt here"
`-p` is the canonical SDK/CI entrypoint. The CLI was previously called "headless mode"; the `-p` flag is unchanged.claude "your prompt here"
`-p`是标准的SDK/CI入口点。该CLI之前被称为“无头模式”;`-p`标志保持不变。Bare Mode for CI and Scripts
CI和脚本的裸模式
Add for any scripted or CI invocation. It skips auto-discovery of hooks, skills, plugins, MCP servers, auto memory, and CLAUDE.md so the call returns the same result on every machine. Bare mode also skips the OAuth keychain, so it requires , , or an passed through .
--bareANTHROPIC_API_KEYANTHROPIC_AUTH_TOKENapiKeyHelper--settingsbash
ANTHROPIC_API_KEY=$KEY claude --bare -p "Summarize the diff" --allowedTools "Read"For pipelines that need a long-lived OAuth token instead of an API key, generate one with and export it as (note: bare mode does NOT read — use or when is set).
claude setup-tokenCLAUDE_CODE_OAUTH_TOKENCLAUDE_CODE_OAUTH_TOKENANTHROPIC_API_KEYapiKeyHelper--bare对于任何脚本化或CI调用,添加。它会跳过钩子、技能、插件、MCP服务器、自动内存和CLAUDE.md的自动发现,使调用在每台机器上都返回相同的结果。裸模式还会跳过OAuth密钥链,因此需要、或通过传递的。
--bareANTHROPIC_API_KEYANTHROPIC_AUTH_TOKEN--settingsapiKeyHelperbash
ANTHROPIC_API_KEY=$KEY claude --bare -p "Summarize the diff" --allowedTools "Read"对于需要长期OAuth令牌而非API密钥的流水线,使用生成令牌并将其导出为(注意:裸模式不会读取——设置时请使用或)。
claude setup-tokenCLAUDE_CODE_OAUTH_TOKENCLAUDE_CODE_OAUTH_TOKEN--bareANTHROPIC_API_KEYapiKeyHelperRunning a Task
执行任务
Read references/recipes.md for concrete command recipes before changing permission modes, resuming a session, restricting tools, or adding extra directories.
在更改权限模式、恢复会话、限制工具或添加额外目录之前,请阅读references/recipes.md获取具体的命令示例。
Permission Mode Selection
权限模式选择
Six modes are supported. Pick the loosest mode the task safely allows.
| Flag | When to use |
|---|---|
| General Claude Code usage with normal approval prompts |
| Read-only analysis or planning with no file changes or shell execution |
| The user explicitly wants Claude Code to write files (also auto-approves common filesystem commands like |
| Long autonomous tasks where prompt fatigue matters; a server-side classifier blocks risky actions but does not replace review |
| Locked-down CI: only |
| Containers / VMs only — equivalent to |
Auto mode requires Claude Code v2.1.83+ and is gated by plan, admin policy, model, and provider; if the CLI reports it as unavailable, do not retry.
支持六种模式。选择任务安全允许的最宽松模式。
| 标志 | 使用场景 |
|---|---|
| 带有正常批准提示的常规Claude Code使用 |
| 只读分析或规划,不修改文件或执行shell命令 |
| 用户明确希望Claude Code写入文件(也会自动批准常见的文件系统命令,如 |
| 长期自主任务,避免提示疲劳;服务器端分类器会阻止危险操作,但不能替代人工审核 |
| 锁定的CI环境:仅允许 |
| 仅适用于容器/虚拟机——等同于 |
自动模式需要Claude Code v2.1.83+,并受计划、管理员策略、模型和提供商限制;如果CLI报告该模式不可用,请不要重试。
Command Discipline
命令规范
- Start from .
claude --permission-mode default -p "your prompt here" - Add or
--model <model>only when the user explicitly asks.--effort <level> - Use only when the user wants something other than
--output-format. Supported values:text(default),text,json.stream-json - For schema-validated structured output, pair with
--output-format json.--json-schema '<JSON Schema>' - Add and/or
--max-turns <N>for autonomous print-mode runs that must not loop forever.--max-budget-usd <dollars> - Use in print mode when a graceful degrade beats a hard failure on overload.
--fallback-model <name> - Use when the task needs files outside the launch directory. (
--add-dir <path>grants file access; it does NOT load--add-dirconfiguration from the added directory, except for.claude/.).claude/skills/ - Restrict tools with ,
--allowedTools, or--disallowedTools(use--toolsto disable all built-ins,--tools ""for all, or a comma list like--tools "default")."Bash,Edit,Read" - Add to / replace the system prompt with ,
--append-system-prompt,--append-system-prompt-file, or--system-prompt.--system-prompt-file - Load MCP servers with ; add
--mcp-config <file-or-json>to ignore every other MCP source.--strict-mcp-config - Ask before using . Prefer
--dangerously-skip-permissionsfor normal file edits.--permission-mode acceptEdits
- 从开始构建命令。
claude --permission-mode default -p "your prompt here" - 仅当用户明确要求时,添加或
--model <model>。--effort <level> - 仅当用户需要非格式的输出时,使用
text。支持的值:--output-format(默认)、text、json。stream-json - 对于模式验证的结构化输出,将与
--output-format json配合使用。--json-schema '<JSON Schema>' - 对于必须避免无限循环的自主打印模式运行,添加和/或
--max-turns <N>。--max-budget-usd <dollars> - 当在过载情况下优雅降级优于硬失败时,在打印模式下使用。
--fallback-model <name> - 当任务需要启动目录之外的文件时,使用。(
--add-dir <path>授予文件访问权限;它不会加载添加目录中的--add-dir配置,.claude/除外。).claude/skills/ - 使用、
--allowedTools或--disallowedTools限制工具(使用--tools禁用所有内置工具,--tools ""启用所有工具,或使用逗号分隔的列表如--tools "default")。"Bash,Edit,Read" - 使用、
--append-system-prompt、--append-system-prompt-file或--system-prompt添加或替换系统提示符。--system-prompt-file - 使用加载MCP服务器;添加
--mcp-config <file-or-json>以忽略所有其他MCP源。--strict-mcp-config - 使用前请询问用户。对于常规文件编辑,优先使用
--dangerously-skip-permissions。--permission-mode acceptEdits
Resuming a Session
恢复会话
bash
undefinedbash
undefinedLatest session in the current directory
当前目录中的最新会话
claude --continue -p "continue the previous task" # short: claude -c -p "..."
claude --continue -p "continue the previous task" # 简写:claude -c -p "..."
Specific session by ID or by display name
通过ID或显示名称恢复特定会话
claude --resume "auth-refactor" -p "continue with this follow-up" # short: -r
claude --resume <session-id> -p "continue with this follow-up"
claude --resume "auth-refactor" -p "continue with this follow-up" # 简写:-r
claude --resume <session-id> -p "continue with this follow-up"
Pin a UUID so a script always reuses the same session
固定UUID,使脚本始终重用同一个会话
claude --session-id 550e8400-e29b-41d4-a716-446655440000 -p "..." # must be a valid UUID
claude --session-id 550e8400-e29b-41d4-a716-446655440000 -p "..." # 必须是有效的UUID
Resume sessions linked to a pull request
恢复与拉取请求关联的会话
claude --from-pr 123 -p "address review comments"
Use `--continue` for the latest conversation in the current directory.
Use `--resume` for a specific session by **ID or by display name** (set with `--name` / `-n`, or by `/rename` mid-session).
Use `--session-id` only with a real UUID — the CLI rejects other strings.
When resuming, keep the existing session's behavior unless the user explicitly asks to change the model, effort, or permission mode.
Add `--fork-session` only when the user wants to branch from the existing session instead of reusing it.claude --from-pr 123 -p "address review comments"
使用`--continue`恢复当前目录中的最新对话。
使用`--resume`通过**ID或显示名称**恢复特定会话(通过`--name`/`-n`设置,或在会话中使用`/rename`设置)。
仅当使用真实UUID时才使用`--session-id`——CLI会拒绝其他字符串。
恢复会话时,保持现有会话的行为,除非用户明确要求更改模型、工作力度或权限模式。
仅当用户希望从现有会话分支而非重用时,添加`--fork-session`。After Completion
完成后操作
- Summarize the result, including any warnings or partial output.
- Tell the user they can resume with (
claude --continue),-c(claude --resume <id-or-name>), or-r.claude --from-pr <pr> - Ask whether to continue, adjust the prompt, or switch back to direct work.
- 总结结果,包括任何警告或部分输出。
- 告知用户可以使用(
claude --continue)、-c(claude --resume <id-or-name>)或-r恢复会话。claude --from-pr <pr> - 询问用户是否继续、调整提示符或切换回直接工作模式。
Critical Evaluation
关键评估
Treat Claude Code as a colleague, not an authority.
- Trust your own grounded knowledge when you are confident.
- Verify disagreements with current docs or primary sources before accepting a claim.
- Remember that a separate Claude Code session can still be wrong or stale.
- Let the user decide when there is genuine ambiguity.
将Claude Code视为同事,而非权威。
- 当你有把握时,相信自己的扎实知识。
- 在接受某个说法之前,先通过当前文档或原始来源验证分歧。
- 记住,独立的Claude Code会话仍然可能出错或信息过时。
- 当存在真正的歧义时,让用户决定。
Authentication
身份验证
The CLI reads credentials in this precedence order: cloud provider env vars ( / / ) → → → → → subscription OAuth from .
CLAUDE_CODE_USE_BEDROCK_VERTEX_FOUNDRYANTHROPIC_AUTH_TOKENANTHROPIC_API_KEYapiKeyHelperCLAUDE_CODE_OAUTH_TOKEN/login- Browser login: run once and follow the prompt, or
claude(useclaude auth loginfor Console billing,--consoleto force SSO).--sso - Inspect / sign out: or
claude auth statusfrom inside a session;/statusorclaude auth logoutto clear credentials./logout - Long-lived OAuth for CI: prints a token; export it as
claude setup-token(not read byCLAUDE_CODE_OAUTH_TOKEN).--bare - Direct API: set for
ANTHROPIC_API_KEY,X-Api-KeyforANTHROPIC_AUTH_TOKENthrough a gateway.Authorization: Bearer
CLI按以下优先级读取凭据:云提供商环境变量(//)→ → → → → 来自的订阅OAuth。
CLAUDE_CODE_USE_BEDROCK_VERTEX_FOUNDRYANTHROPIC_AUTH_TOKENANTHROPIC_API_KEYapiKeyHelperCLAUDE_CODE_OAUTH_TOKEN/login- 浏览器登录:运行一次并按照提示操作,或运行
claude(使用claude auth login进行控制台计费,--console强制使用SSO)。--sso - 检查/登出:运行或在会话内使用
claude auth status;运行/status或在会话内使用claude auth logout清除凭据。/logout - CI用长期OAuth令牌:会打印一个令牌;将其导出为
claude setup-token(裸模式不会读取此令牌)。CLAUDE_CODE_OAUTH_TOKEN - 直接API:设置用于
ANTHROPIC_API_KEY,设置X-Api-Key用于通过网关的ANTHROPIC_AUTH_TOKEN。Authorization: Bearer
Error Handling
错误处理
- : tell the user Claude Code CLI is not installed; they can run
command not found: claudeafter setup.claude install stable - Auth errors: confirm precedence above (e.g. an unset may be needed when a subscription is active), then re-run
unset ANTHROPIC_API_KEYorclaude auth loginto confirm.claude auth status - Permission blocks: retry with an appropriate (
--permission-modefor read-only,planfor file edits) or adjustacceptEdits/--allowedTools. Do not escalate to--disallowedToolswithout explicit user approval.--dangerously-skip-permissions - Session not found: run without an argument to pick from a list, or switch to
claude --resumefor the current directory;claude --continuerequires a UUID.--session-id - Auto-mode unavailable: this is gated by plan, admin policy, model, and provider — it is not a transient outage; fall back to or
default.acceptEdits - Invalid flag or model errors: check , then re-run with supported options.
claude --helpdoes not list every flag — consult the CLI reference for the full list.claude --help
- :告知用户Claude Code CLI未安装;他们可以在设置后运行
command not found: claude。claude install stable - 身份验证错误:确认上述优先级(例如,当订阅处于活动状态时,可能需要取消设置),然后重新运行
unset ANTHROPIC_API_KEY或claude auth login确认。claude auth status - 权限阻止:使用适当的(只读操作使用
--permission-mode,文件编辑使用plan)重试,或调整acceptEdits/--allowedTools。未经用户明确批准,不要升级到--disallowedTools。--dangerously-skip-permissions - 会话未找到:不带参数运行从列表中选择,或切换到
claude --resume恢复当前目录的会话;claude --continue需要UUID。--session-id - 自动模式不可用:这受计划、管理员策略、模型和提供商限制——不是临时故障; fallback到或
default模式。acceptEdits - 无效标志或模型错误:检查,然后使用支持的选项重新运行。
claude --help并未列出所有标志——请查阅CLI参考获取完整列表。claude --help