claude-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClaude Code Headless Mode
Claude Code 无界面模式
Use this skill when the job should be executed through Claude Code itself, not solved inline. Focus on commands and workflows that match current stable Claude Code behavior.
当任务需要通过Claude Code本身执行而非在线解决时,使用此技能。重点关注与当前稳定版Claude Code行为匹配的命令和工作流。
Core Rules
核心规则
- Treat on the target machine as the compatibility floor. CLI flags move faster than blog posts and copied examples.
claude --help - Permission rule syntax varies by build. Anthropic docs often show forms like , while the installed
Bash(git diff *)help on this machine still showsclaude 2.1.71. Mirror the syntax shown by the target machine'sBash(git:*).claude --help - Default to the model the user already configured through , settings, or
/model.ANTHROPIC_MODEL - Do not add unless the user explicitly asked for a model override or the workflow must pin a model for reproducibility.
--model - Prefer over
--append-system-promptunless replacing the default Claude Code behavior is intentional.--system-prompt - Default to safe automation. If the user wants a truly unattended run, use explicit permission rules or ; reserve
dontAskfor isolated environments.bypassPermissions
- 以目标机器上的作为兼容性基准。CLI标志的更新速度快于博客文章和复制的示例。
claude --help - 权限规则语法因版本而异。Anthropic文档通常展示这类格式,但本机安装的
Bash(git diff *)帮助文档仍显示claude 2.1.71。请遵循目标机器Bash(git:*)中展示的语法。claude --help - 默认使用用户已通过、设置或
/model环境变量配置的模型。ANTHROPIC_MODEL - 除非用户明确要求覆盖模型,或工作流必须固定模型以保证可复现性,否则不要添加参数。
--model - 除非有意替换Claude Code的默认行为,否则优先使用而非
--append-system-prompt。--system-prompt - 默认采用安全自动化方式。如果用户需要真正无人值守的运行,请使用明确的权限规则或模式;仅在隔离环境中使用
dontAsk模式。bypassPermissions
Quick Verification
快速验证
Run these checks before giving advanced advice:
bash
claude --version
claude auth status --text
claude --helpIf installation or updates look odd, use:
bash
claude doctor在提供高级建议前,先运行以下检查:
bash
claude --version
claude auth status --text
claude --help如果安装或更新出现异常,使用:
bash
claude doctorInstallation Guidance
安装指南
- Anthropic's getting-started docs still show as the standard install path.
npm install -g @anthropic-ai/claude-code - Newer builds may also support native installer flows and .
claude install - If the user needs installation help, point them to the official Claude Code setup docs and verify the result with rather than assuming one installer path is universal.
claude doctor
- Anthropic的入门文档仍将作为标准安装路径。
npm install -g @anthropic-ai/claude-code - 新版本可能还支持原生安装程序流程和命令。
claude install - 如果用户需要安装帮助,请引导他们查看官方Claude Code设置文档,并通过验证安装结果,而非假设某一种安装路径是通用的。
claude doctor
Headless Command Patterns
无界面命令模式
Basic Non-Interactive Run
基础非交互式运行
Use / for non-interactive execution:
-p--printbash
claude -p "summarize the repository architecture"Add when the caller needs machine-readable output:
--output-format jsonbash
claude -p "review the auth layer for risks" --output-format json使用/参数执行非交互式任务:
-p--printbash
claude -p "summarize the repository architecture"当调用方需要机器可读输出时,添加:
--output-format jsonbash
claude -p "review the auth layer for risks" --output-format jsonModel Selection
模型选择
- Omit by default.
--model - If the user explicitly wants a model override, use .
claude --model <alias-or-name> ... - For persistent defaults, prefer settings () or
model.ANTHROPIC_MODEL - For third-party deployments, pin models via settings or environment variables instead of bolting onto every command example.
--model
- 默认省略参数。
--model - 如果用户明确要求覆盖模型,使用。
claude --model <别名或名称> ... - 如需持久化默认设置,优先使用配置()或
model环境变量。ANTHROPIC_MODEL - 对于第三方部署,通过设置或环境变量固定模型,而非在每个命令示例中都添加参数。
--model
Permission Modes
权限模式
Claude Code supports these permission modes:
| Mode | Use |
|---|---|
| Interactive exploration. Prompts on first use of write/bash-style tools. |
| Recommended starting point for coding automation. Auto-accepts edits, but command execution can still prompt. |
| Analysis only. No file changes or command execution. |
| Auto-denies anything not already approved by permission rules. Good for unattended-but-constrained runs. |
| Skips prompts entirely. Only for strong sandbox / container / VM isolation. |
Important clarifications:
- is the skill's recommended default, not the CLI default.
acceptEdits - If the user says "no prompts at all," prefer permission rules or with explicit allow rules.
dontAsk - Only recommend when the environment is already isolated and the user accepts the risk.
bypassPermissions - For read-only analysis, prefer plus
--toolsordefault; do not reach forplanjust to suppress prompts.bypassPermissions
Claude Code支持以下权限模式:
| 模式 | 用途 |
|---|---|
| 交互式探索。首次使用写入/类Bash工具时会提示确认。 |
| 编码自动化的推荐起始模式。自动接受编辑,但命令执行仍可能触发提示。 |
| 仅分析模式。不修改文件或执行命令。 |
| 自动拒绝所有未被权限规则预先批准的操作。适用于无人值守但受约束的运行场景。 |
| 完全跳过提示。仅适用于强隔离的沙箱/容器/VM环境。 |
重要说明:
- 是本技能推荐的默认模式,而非CLI的默认模式。
acceptEdits - 如果用户要求“完全无提示”,优先使用权限规则或带有明确允许规则的模式。
dontAsk - 仅当环境已隔离且用户接受风险时,才推荐使用模式。
bypassPermissions - 对于只读分析,优先使用搭配
--tools或default模式;不要仅为了抑制提示就使用plan。bypassPermissions
Tool Availability vs Permission Approval
工具可用性与权限批准
Do not mix these up:
- restricts which built-in tools are available at all.
--tools - pre-approves specific tools or tool rules so Claude does not prompt for them.
--allowedTools - removes tools or rules from context.
--disallowedTools
Permission rules follow or syntax.
ToolTool(specifier)Use wildcard rules when the command will include arguments:
- Good:
Bash(git diff *) - Good:
Bash(npm run test *) - Risky for real use: because it matches only the exact literal command
Bash(find)find
If the local CLI help shows colon syntax such as , use that form on that machine. The important part is to allow an argument-aware rule rather than an exact literal command.
Bash(find:*)If the user wants Claude limited to a narrow tool family, you should usually use both and : defines the hard boundary, removes prompts inside that boundary.
--tools--allowedTools--tools--allowedTools请勿混淆这两个概念:
- 限制可用的内置工具范围。
--tools - 预先批准特定工具或工具规则,避免Claude触发提示。
--allowedTools - 从上下文移除指定工具或规则。
--disallowedTools
权限规则遵循或语法。
ToolTool(指定符)当命令包含参数时,使用通配符规则:
- 推荐:
Bash(git diff *) - 推荐:
Bash(npm run test *) - 实际使用有风险:(仅匹配字面命令
Bash(find))find
如果本地CLI帮助文档显示这类冒号语法,请在该机器上使用此格式。关键是使用支持参数的规则,而非精确匹配字面命令。
Bash(find:*)如果用户希望将Claude限制在特定工具家族内,通常应同时使用和:定义硬边界,移除边界内操作的提示。
--tools--allowedTools--tools--allowedToolsOutput Formats
输出格式
- : default human-readable output
text - : one final structured result
json - : event stream for long-running automation
stream-json
Do not promise a fixed JSON schema unless you have validated it on the target version. Prefer wording like "returns a final result object with response text, timing, and session metadata."
- :默认的人类可读输出
text - :单个最终结构化结果
json - :适用于长时间运行自动化的事件流
stream-json
除非已在目标版本上验证过固定JSON Schema,否则不要承诺固定的JSON格式。建议使用类似“返回包含响应文本、计时信息和会话元数据的最终结果对象”的表述。
Commonly Safe Flags
常用安全标志
These are appropriate starting points on current stable builds:
--append-system-prompt--allowedTools--disallowedTools--tools--permission-mode--output-format--mcp-config- /
--continue--resume - /
--settings--setting-sources --session-id--add-dir--max-budget-usd- for print mode
--fallback-model
以下是当前稳定版中适合作为起始选项的标志:
--append-system-prompt--allowedTools--disallowedTools--tools--permission-mode--output-format--mcp-config- /
--continue--resume - /
--settings--setting-sources --session-id--add-dir--max-budget-usd- (适用于打印模式)
--fallback-model
Version-Sensitive Flags
版本敏感标志
Published docs sometimes mention flags that are absent from the installed binary on a given machine. Before emitting less-common flags, verify them with .
claude --help已发布的文档有时会提及当前安装版本中不存在的标志。在使用不常见的标志前,请通过验证其存在性。
claude --helpRecommended Command Templates
推荐命令模板
Read-Only Analysis
只读分析
bash
claude -p "count the total lines of code in this repo, grouped by language" \
--permission-mode default \
--tools "Bash,Read" \
--allowedTools "Read" "Bash(find:*)" "Bash(wc:*)"bash
claude -p "count the total lines of code in this repo, grouped by language" \
--permission-mode default \
--tools "Bash,Read" \
--allowedTools "Read" "Bash(find:*)" "Bash(wc:*)"Safe Edit Run
安全编辑运行
bash
claude -p "fix the failing login test and rerun the relevant test command" \
--permission-mode acceptEdits \
--tools "Bash,Read,Edit,Write" \
--allowedTools "Read" "Edit" "Write" "Bash(npm test *)"bash
claude -p "fix the failing login test and rerun the relevant test command" \
--permission-mode acceptEdits \
--tools "Bash,Read,Edit,Write" \
--allowedTools "Read" "Edit" "Write" "Bash(npm test *)"JSON Report
JSON报告
bash
claude -p "review the repository for security issues and produce a concise report" \
--output-format json \
--append-system-prompt "Focus on concrete findings, exploitability, and mitigations."bash
claude -p "review the repository for security issues and produce a concise report" \
--output-format json \
--append-system-prompt "Focus on concrete findings, exploitability, and mitigations."Resume a Session
恢复会话
bash
claude -r "$session_id" -p "continue by updating the tests and summarizing what changed"bash
claude -r "$session_id" -p "continue by updating the tests and summarizing what changed"Continue the Most Recent Session
继续最近的会话
bash
claude -c -p "continue with the next step"bash
claude -c -p "continue with the next step"Use MCP Tools
使用MCP工具
bash
claude -p "investigate the API latency spike" \
--permission-mode acceptEdits \
--mcp-config monitoring-tools.json \
--allowedTools "Read" "mcp__datadog__*" "mcp__prometheus__*"bash
claude -p "investigate the API latency spike" \
--permission-mode acceptEdits \
--mcp-config monitoring-tools.json \
--allowedTools "Read" "mcp__datadog__*" "mcp__prometheus__*"Fully Unattended Execution in an Isolated Environment
隔离环境中的完全无人值守执行
Use only when the environment is already sandboxed:
bash
claude -p "run the migration and fix the resulting type errors" \
--permission-mode bypassPermissions \
--tools "Bash,Read,Edit,Write"仅在环境已沙箱化时使用:
bash
claude -p "run the migration and fix the resulting type errors" \
--permission-mode bypassPermissions \
--tools "Bash,Read,Edit,Write"Execution Workflow
执行工作流
- Confirm the user wants Claude Code CLI rather than an inline answer.
- Verify the installed CLI shape with if you plan to use uncommon flags.
claude --help - Choose the least-permissive mode that still fits the task.
- Build the command without unless the user explicitly asked for an override.
--model - Restrict tools with when safety or predictability matters.
--tools - Use for prompt-free approval of known-safe actions.
--allowedTools - Return exact commands plus short caveats about assumptions and safety.
- 确认用户需要的是Claude Code CLI而非在线解答。
- 如果计划使用不常见的标志,先通过验证当前安装的CLI支持情况。
claude --help - 选择既能满足任务需求又权限最低的模式。
- 构建命令时默认不添加参数,除非用户明确要求覆盖模型。
--model - 当安全性或可预测性很重要时,使用限制可用工具。
--tools - 使用预先批准已知安全的操作,避免触发提示。
--allowedTools - 返回精确的命令或命令序列,并附上关于假设前提和安全注意事项的简短说明。
When To Pause
何时暂停操作
Pause only when one of these is materially unclear:
- The user wants a specific model or provider behavior that requires pinning.
- They asked for a fully unattended run in an environment that is not clearly sandboxed.
- The workflow depends on a Claude Code feature that is not visible in .
claude --help
Otherwise, proceed and give the best current command.
仅当以下情况存在明显不确定性时才暂停:
- 用户需要特定模型或供应商行为,必须固定模型版本。
- 用户要求在未明确沙箱化的环境中进行完全无人值守运行。
- 工作流依赖的Claude Code功能未在中显示。
claude --help
否则,继续操作并提供当前最优的命令。
Final Response Expectations
最终响应要求
When using this skill, the output should usually include:
- the exact command or command sequence
- a one-line note that the configured Claude model is being used by default
- any permission or isolation caveat
- the resume command if the workflow is meant to continue later
使用本技能时,输出通常应包含:
- 精确的命令或命令序列
- 一行说明:默认使用已配置的Claude模型
- 任何权限或隔离相关的注意事项
- 如果工作流需要后续继续,提供恢复命令
References
参考资料
- for extended patterns
references/examples.md
- 包含扩展模式示例
references/examples.md