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

Defaults

默认设置

ParameterDefault
Model selectionUse Claude Code CLI default unless the user explicitly asks for
--model
EffortUse CLI default unless the user explicitly asks for
--effort
Permission mode
--permission-mode default
Headless mode
-p
/
--print
CI / scripted runAdd
--bare
so the call ignores local hooks, plugins, MCP, and CLAUDE.md
Resume target
claude --continue
(
-c
) for the latest session in the current directory;
claude --resume
(
-r
) for a session by ID or display name
Do NOT ask the user for model or effort unless explicitly requested.
参数默认值
模型选择除非用户明确要求使用
--model
,否则使用Claude Code CLI的默认设置
工作力度除非用户明确要求使用
--effort
,否则使用CLI的默认设置
权限模式
--permission-mode default
无头模式
-p
/
--print
CI/脚本化运行添加
--bare
,使调用忽略本地钩子、插件、MCP和CLAUDE.md
恢复目标当前目录中最新会话使用
claude --continue
-c
);通过ID或显示名称恢复会话使用
claude --resume
-r
除非用户明确要求,否则不要询问用户关于模型或工作力度的选择。

Routing

路由规则

Use this skill when the request actually needs the
claude
CLI or a separate Claude Code session.
  • 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
    claude
    CLI itself.
当请求确实需要使用
claude
CLI或独立的Claude Code会话时,使用此技能。
  • 当请求可能超出范围时,在构建命令前阅读rules/routing.md
  • 当用户需要通用写作、文档清理或无需
    claude
    CLI的本地编辑时,将请求转至直接编辑或其他技能。

Examples

示例

Positive triggers:
  • "Use Claude Code to review this repository and summarize the risks."
  • "Run
    claude
    in print mode and analyze this architecture."
  • "Continue the last Claude Code session and ask it to finish the patch."
  • "Resume the
    auth-refactor
    claude session and apply the next fix."
  • "Use
    claude --bare -p
    so this CI step does not pick up local hooks."
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
    claude
    CLI involved; otherwise route to research or direct documentation work.
正向触发场景:
  • "Use Claude Code to review this repository and summarize the risks."
  • "Run
    claude
    in print mode and analyze this architecture."
  • "Continue the last Claude Code session and ask it to finish the patch."
  • "Resume the
    auth-refactor
    claude session and apply the next fix."
  • "Use
    claude --bare -p
    so this CI step does not pick up local hooks."
负向触发场景:
  • "Rewrite this runbook for readability."
  • "Create a new skill for our repo."
边界触发场景:
  • "Research Claude Code permissions and tell me what they do." 仅当用户希望涉及
    claude
    CLI时使用此技能;否则转至研究或直接文档处理工作。

Critical: Print Mode

关键:打印模式

Always use
-p
/
--print
for non-interactive Claude Code runs. Positional prompts without
-p
start the interactive REPL instead, so a script that omits
-p
will hang waiting for a TTY.
bash
undefined
对于非交互式Claude Code运行,始终使用
-p
/
--print
。不带
-p
的位置提示符会启动交互式REPL,因此省略
-p
的脚本会挂起等待TTY输入。
bash
undefined

Non-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
--bare
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
ANTHROPIC_API_KEY
,
ANTHROPIC_AUTH_TOKEN
, or an
apiKeyHelper
passed through
--settings
.
bash
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
claude setup-token
and export it as
CLAUDE_CODE_OAUTH_TOKEN
(note: bare mode does NOT read
CLAUDE_CODE_OAUTH_TOKEN
— use
ANTHROPIC_API_KEY
or
apiKeyHelper
when
--bare
is set).
对于任何脚本化或CI调用,添加
--bare
。它会跳过钩子、技能、插件、MCP服务器、自动内存和CLAUDE.md的自动发现,使调用在每台机器上都返回相同的结果。裸模式还会跳过OAuth密钥链,因此需要
ANTHROPIC_API_KEY
ANTHROPIC_AUTH_TOKEN
或通过
--settings
传递的
apiKeyHelper
bash
ANTHROPIC_API_KEY=$KEY claude --bare -p "Summarize the diff" --allowedTools "Read"
对于需要长期OAuth令牌而非API密钥的流水线,使用
claude setup-token
生成令牌并将其导出为
CLAUDE_CODE_OAUTH_TOKEN
(注意:裸模式不会读取
CLAUDE_CODE_OAUTH_TOKEN
——设置
--bare
时请使用
ANTHROPIC_API_KEY
apiKeyHelper
)。

Running 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.
FlagWhen to use
--permission-mode default
General Claude Code usage with normal approval prompts
--permission-mode plan
Read-only analysis or planning with no file changes or shell execution
--permission-mode acceptEdits
The user explicitly wants Claude Code to write files (also auto-approves common filesystem commands like
mkdir
,
mv
,
cp
)
--permission-mode auto
Long autonomous tasks where prompt fatigue matters; a server-side classifier blocks risky actions but does not replace review
--permission-mode dontAsk
Locked-down CI: only
permissions.allow
rules and the read-only command set may run; everything else is auto-denied
--permission-mode bypassPermissions
Containers / VMs only — equivalent to
--dangerously-skip-permissions
, requires explicit user approval, and offers no protection against prompt injection
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.
支持六种模式。选择任务安全允许的最宽松模式。
标志使用场景
--permission-mode default
带有正常批准提示的常规Claude Code使用
--permission-mode plan
只读分析或规划,不修改文件或执行shell命令
--permission-mode acceptEdits
用户明确希望Claude Code写入文件(也会自动批准常见的文件系统命令,如
mkdir
mv
cp
--permission-mode auto
长期自主任务,避免提示疲劳;服务器端分类器会阻止危险操作,但不能替代人工审核
--permission-mode dontAsk
锁定的CI环境:仅允许
permissions.allow
规则和只读命令集运行;其他所有操作都会被自动拒绝
--permission-mode bypassPermissions
仅适用于容器/虚拟机——等同于
--dangerously-skip-permissions
,需要用户明确批准,且对提示注入无保护
自动模式需要Claude Code v2.1.83+,并受计划、管理员策略、模型和提供商限制;如果CLI报告该模式不可用,请不要重试。

Command Discipline

命令规范

  • Start from
    claude --permission-mode default -p "your prompt here"
    .
  • Add
    --model <model>
    or
    --effort <level>
    only when the user explicitly asks.
  • Use
    --output-format
    only when the user wants something other than
    text
    . Supported values:
    text
    (default),
    json
    ,
    stream-json
    .
  • For schema-validated structured output, pair
    --output-format json
    with
    --json-schema '<JSON Schema>'
    .
  • Add
    --max-turns <N>
    and/or
    --max-budget-usd <dollars>
    for autonomous print-mode runs that must not loop forever.
  • Use
    --fallback-model <name>
    in print mode when a graceful degrade beats a hard failure on overload.
  • Use
    --add-dir <path>
    when the task needs files outside the launch directory. (
    --add-dir
    grants file access; it does NOT load
    .claude/
    configuration from the added directory, except for
    .claude/skills/
    .)
  • Restrict tools with
    --allowedTools
    ,
    --disallowedTools
    , or
    --tools
    (use
    --tools ""
    to disable all built-ins,
    --tools "default"
    for all, or a comma list like
    "Bash,Edit,Read"
    ).
  • Add to / replace the system prompt with
    --append-system-prompt
    ,
    --append-system-prompt-file
    ,
    --system-prompt
    , or
    --system-prompt-file
    .
  • Load MCP servers with
    --mcp-config <file-or-json>
    ; add
    --strict-mcp-config
    to ignore every other MCP source.
  • Ask before using
    --dangerously-skip-permissions
    . Prefer
    --permission-mode acceptEdits
    for normal file edits.
  • 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-config <file-or-json>
    加载MCP服务器;添加
    --strict-mcp-config
    以忽略所有其他MCP源。
  • 使用
    --dangerously-skip-permissions
    前请询问用户。对于常规文件编辑,优先使用
    --permission-mode acceptEdits

Resuming a Session

恢复会话

bash
undefined
bash
undefined

Latest 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>
    (
    -r
    ), or
    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 (
CLAUDE_CODE_USE_BEDROCK
/
_VERTEX
/
_FOUNDRY
) →
ANTHROPIC_AUTH_TOKEN
ANTHROPIC_API_KEY
apiKeyHelper
CLAUDE_CODE_OAUTH_TOKEN
→ subscription OAuth from
/login
.
  • Browser login: run
    claude
    once and follow the prompt, or
    claude auth login
    (use
    --console
    for Console billing,
    --sso
    to force SSO).
  • Inspect / sign out:
    claude auth status
    or
    /status
    from inside a session;
    claude auth logout
    or
    /logout
    to clear credentials.
  • Long-lived OAuth for CI:
    claude setup-token
    prints a token; export it as
    CLAUDE_CODE_OAUTH_TOKEN
    (not read by
    --bare
    ).
  • Direct API: set
    ANTHROPIC_API_KEY
    for
    X-Api-Key
    ,
    ANTHROPIC_AUTH_TOKEN
    for
    Authorization: Bearer
    through a gateway.
CLI按以下优先级读取凭据:云提供商环境变量(
CLAUDE_CODE_USE_BEDROCK
/
_VERTEX
/
_FOUNDRY
)→
ANTHROPIC_AUTH_TOKEN
ANTHROPIC_API_KEY
apiKeyHelper
CLAUDE_CODE_OAUTH_TOKEN
→ 来自
/login
的订阅OAuth。
  • 浏览器登录:运行一次
    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

错误处理

  • command not found: claude
    : tell the user Claude Code CLI is not installed; they can run
    claude install stable
    after setup.
  • Auth errors: confirm precedence above (e.g. an unset
    unset ANTHROPIC_API_KEY
    may be needed when a subscription is active), then re-run
    claude auth login
    or
    claude auth status
    to confirm.
  • Permission blocks: retry with an appropriate
    --permission-mode
    (
    plan
    for read-only,
    acceptEdits
    for file edits) or adjust
    --allowedTools
    /
    --disallowedTools
    . Do not escalate to
    --dangerously-skip-permissions
    without explicit user approval.
  • Session not found: run
    claude --resume
    without an argument to pick from a list, or switch to
    claude --continue
    for the current directory;
    --session-id
    requires a UUID.
  • Auto-mode unavailable: this is gated by plan, admin policy, model, and provider — it is not a transient outage; fall back to
    default
    or
    acceptEdits
    .
  • Invalid flag or model errors: check
    claude --help
    , then re-run with supported options.
    claude --help
    does not list every flag — consult the CLI reference for the full list.
  • command not found: claude
    :告知用户Claude Code CLI未安装;他们可以在设置后运行
    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
    恢复当前目录的会话;
    --session-id
    需要UUID。
  • 自动模式不可用:这受计划、管理员策略、模型和提供商限制——不是临时故障; fallback到
    default
    acceptEdits
    模式。
  • 无效标志或模型错误:检查
    claude --help
    ,然后使用支持的选项重新运行。
    claude --help
    并未列出所有标志——请查阅CLI参考获取完整列表。