@rules/routing.md
Claude Code Skill<output_language>
Default all user-facing deliverables, saved artifacts, reports, plans, generated docs, summaries, handoff notes, commit/message drafts, and validation notes to Korean, even when this canonical skill file is written in English.
Preserve source code identifiers, CLI commands, file paths, schema keys, JSON/YAML field names, API names, package names, proper nouns, and quoted source excerpts in their required or original language.
Use a different language only when the user explicitly requests it, an existing target artifact must stay in another language for consistency, or a machine-readable contract requires exact English tokens. If a localized template or reference exists (for example *.ko.md or *.ko.json), prefer it for user-facing artifacts.
</output_language>
Source of truth: https://code.claude.com/docs/en/cli-reference.
<instruction_contract>
| Field | Contract |
|---|---|
| Intent | Build or explain a safe claude CLI invocation when the user explicitly asks for Claude Code. |
| Scope | Owns command construction, resume/session flags, permission mode choice, tool restrictions, auth guidance, and result summarization for claude. |
| Authority | User intent and local project rules come first; the linked Claude Code CLI reference is the source of truth for CLI flags. |
| Evidence | Ground the answer in the command shape, CLI output, support-file guidance, and any warnings/errors observed. |
| Tools | Use shell execution only when the user wants the CLI run; otherwise provide the command or route away. |
| Output | Return the exact command used or recommended, summarize output/warnings, and preserve CLI tokens verbatim. |
| Verification | Check that non-interactive runs use -p, permission mode matches the requested authority, and dangerous bypass is gated. |
| Stop condition | Stop after the requested command is constructed or run and its result, warnings, or blocker are reported. |
</instruction_contract>
Defaults
| Parameter | Default |
|---|---|
| Model selection | Use Claude Code CLI default unless the user explicitly asks for --model |
| Effort | Use CLI default unless the user explicitly asks for --effort |
| Permission mode | --permission-mode default |
| Headless mode | -p / --print |
| CI / scripted run | Add --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.
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
claudeCLI itself.
Examples
Positive examples:
- "Use Claude Code to review this repository and summarize the risks."
- "Run
claudein print mode and analyze this architecture." - "Continue the last Claude Code session and ask it to finish the patch."
- "Resume the
auth-refactorclaude session and apply the next fix." - "Use
claude --bare -pso this CI step does not pick up local hooks."
Negative examples:
- "Rewrite this runbook for readability."
- "Create a new skill for our repo."
Boundary examples:
- "Research Claude Code permissions and tell me what they do."
Use this skill only if the user wants the
claudeCLI involved; otherwise route to research or direct documentation work.
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.
# Non-interactive (headless / SDK)
claude --permission-mode default -p "your prompt here"
# Interactive REPL (initial prompt only — does NOT exit)
claude "your prompt here"
-p is the canonical SDK/CI entrypoint. The CLI was previously called "headless mode"; the -p flag is unchanged.
Bare Mode for CI and Scripts
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.
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).
Running a Task
Read references/recipes.md for concrete command recipes before changing permission modes, resuming a session, restricting tools, or adding extra directories.
Permission Mode Selection
Six modes are supported. Pick the loosest mode the task safely allows.
| Flag | When 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.
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-formatonly when the user wants something other thantext. Supported values:text(default),json,stream-json. - For schema-validated structured output, pair
--output-format jsonwith--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-dirgrants 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-configto ignore every other MCP source. - Ask before using
--dangerously-skip-permissions. Prefer--permission-mode acceptEditsfor normal file edits.
Resuming a Session
# Latest session in the current directory
claude --continue -p "continue the previous task" # short: claude -c -p "..."
# Specific session by ID or by display name
claude --resume "auth-refactor" -p "continue with this follow-up" # short: -r
claude --resume <session-id> -p "continue with this follow-up"
# Pin a UUID so a script always reuses the same session
claude --session-id 550e8400-e29b-41d4-a716-446655440000 -p "..." # must be a valid 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.
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), orclaude --from-pr <pr>. - Ask whether to continue, adjust the prompt, or switch back to direct work.
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.
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
claudeonce and follow the prompt, orclaude auth login(use--consolefor Console billing,--ssoto force SSO). - Inspect / sign out:
claude auth statusor/statusfrom inside a session;claude auth logoutor/logoutto clear credentials. - Long-lived OAuth for CI:
claude setup-tokenprints a token; export it asCLAUDE_CODE_OAUTH_TOKEN(not read by--bare). - Direct API: set
ANTHROPIC_API_KEYforX-Api-Key,ANTHROPIC_AUTH_TOKENforAuthorization: Bearerthrough a gateway.
Error Handling
command not found: claude: tell the user Claude Code CLI is not installed; they can runclaude install stableafter setup.- Auth errors: confirm precedence above (e.g. an unset
unset ANTHROPIC_API_KEYmay be needed when a subscription is active), then re-runclaude auth loginorclaude auth statusto confirm. - Permission blocks: retry with an appropriate
--permission-mode(planfor read-only,acceptEditsfor file edits) or adjust--allowedTools/--disallowedTools. Do not escalate to--dangerously-skip-permissionswithout explicit user approval. - Session not found: run
claude --resumewithout an argument to pick from a list, or switch toclaude --continuefor the current directory;--session-idrequires a UUID. - Auto-mode unavailable: this is gated by plan, admin policy, model, and provider — it is not a transient outage; fall back to
defaultoracceptEdits. - Invalid flag or model errors: check
claude --help, then re-run with supported options.claude --helpdoes not list every flag — consult the CLI reference for the full list.
<validation_checklist>
- The request explicitly needs the
claudeCLI or a separate Claude Code session. - Non-interactive runs use
-p/--print; positional prompts are not used for automation. - Permission mode matches the task:
planfor read-only,acceptEditsonly for explicit file edits, and bypass only after explicit approval in an isolated environment. - Scripted or CI runs use
--barewhen reproducibility and local-hook isolation are required. - Final output includes the command shape, observed result, warnings, and any auth/session/permission blocker.
</validation_checklist>