Type: docs Syncs the tutorial, its translations and root docs to **Claude Code 2.1.322** (previous sync: v2.1.316, #230). The audit covered every changelog entry for 2.1.317, 2.1.318, 2.1.319, 2.1.321 and 2.1.322, plus the official docs pages for each affected feature. npm `latest` is 2.1.322. 49 files changed (46 in the sync commit, plus `fa/` and `ko/03-skills` in review round 1 and `ko/claude_concepts_guide.md` in round 3). P0 0 · P1 15 · P2 6 (deferred) · P3 30 + 1 blocked · P4 3. ## P1: outdated claims (mirrored to translations) - **Fable 5.2 (v2.1.321).** The `10-cli` model table gains a Fable 5.2 row (1M context, default effort `medium`), and Fable 5.1 becomes the previous model. - The Fable alias note now says `fable` resolves to Fable 5.2 (Fable 5 in Claude apps gateway sessions). - `best` now resolves to the same model as `opus`. - A saved `claude-fable-5-1` pick moves to `fable` on Pro/Max/Ultra, and on Team/Enterprise when the organization's settings allow. - Pricing: $8/$40 per Mtok, with $0.20 per Mtok cache reads. - The FAQ and QUICK_REFERENCE model lists name Fable 5.2. - **Fast mode on Fable 5.2 (v2.1.321, $16/$80):** added to `/fast` in `01-slash-commands`, CATALOG, the `10-cli` fast-mode note and the `CLAUDE_CODE_OPUS_4_6_FAST_MODE_OVERRIDE` row. - **`ultrathink`** now lists Fable 5.2 in `09`, `10-cli` and `claude_concepts_guide`. - **Scheduled tasks (`09`)**: - Recurring tasks expire after 7 days, not 3. - Tasks are restored on `--resume`/`--continue`, except expired tasks, past-due one-shots and a self-paced `/loop`. - Recurring jitter is "up to half the gap, at most 30 min" (`*/5` isn't delayed). - One-shots scheduled for `:00`/`:30` run up to 90 s early. - **Subagent and teammate effort (v2.1.317):** on a different model they use that model's saved effort or its default, not the session's (`04-subagents`, `10-cli`). - **`switchModelsOnFlag` (v2.1.318):** subagents never pause. With "Ask each time", a flagged subagent request fails instead of switching models. - **Background commands:** the default limit is 10 minutes in a `-p` run whose prompt is passed as text (the fix is in v2.1.321). - **Mods Claude writes (v2.1.321):** in `auto`/`bypassPermissions` they turn on without asking. They don't load in `dontAsk` or in `-p` outside those modes. ## P3: additions (English only) - **`01-slash-commands`:** - `/model` "More models" row (v2.1.319/321). - `/context` sends Claude only the table. - `/ide` no longer installs the extension from an IDE terminal (v2.1.318). - `/tasks` "Earlier in this session". - `/claude-api latency-optimize`, also added in `03-skills`, CATALOG and the concepts guide. - **`03-skills`:** two new limits on nested-skill loading: under the Bash sandbox (v2.1.319), and `.claude/skills` inside `~/.claude/plugins` (v2.1.321). The skills docs page doesn't list these exceptions yet; the source is the changelog. - **`04-subagents`:** background subagents move a shell command to the background after 3 min, and `SendMessage` reaches a busy background agent sooner. - **`06-hooks`:** - Agent SDK `onFailure: "block"` / `on_failure="block"`. - An `mcp_tool` hook refuses the call when it can't read the answer (>16 MiB). - `defer` works only with a single tool call; `tool_deferred_unavailable` and `CLAUDE_CODE_DROP_UNAVAILABLE_DEFERRED_TOOL`. - PostToolUse runs after a `Ctrl+Enter` interrupt (10 s). - **`07-plugins`:** - `$.model.fork` `effort` and `prompt.submit` in the user turn. - `${CLAUDE_PLUGIN_ROOT}` in `subagentStatusLine`. - Plugin updates install new dependencies. - Managed `extraKnownMarketplaces` take-over rules. - **`08-checkpoints`:** `/rewind` after `/branch` (fixed in v2.1.319). - **`09-advanced-features`:** - `/tasks` row. - Background command notifications show only the start and end of a command over 1,000 characters. - `claude remote-control --settings <file>`, and sessions keep their folder. - OTel `anthropic.plan`, `anthropic.seat_type`, `anthropic.provider`, `anthropic.custom_base_url`. - Three v2.1.319 trust-hardening items. - Auto-mode `-p` exits 1 when no safety check was available. - Monitor WebSocket watches follow Bash rules. - **`10-cli`:** - Fast mode on Google Cloud's Agent Platform: Fable 5.2 only, regions `global`/`us`/`eu`, v2.1.322. - `claude auth status` `loginExpiresAt`. - `claude -p` `credential_expires_at` and the 10-day stderr warning. - Bash permission hardening: `which` with flags, `timeout` wrappers, exact ask vs. broader deny, `cp`/`mv` by path. - Agent view `--agent` dispatch default. - `MCP_PROTOCOL_NEGOTIATION` 7-day skip. - New rows for `CLAUDE_CODE_DISABLE_FEATURE_FLAGS`, `CLAUDE_CODE_DISABLE_NESTED_SESSION_ID` and `permissions.denyInsteadOfPrompting`. ## P4: cosmetic - Root `README.md`: the version badge, "latest" line and "Current version" line now say v2.1.322 / November 2026. - `10-cli`: the resume hint repeats launch flags (v2.1.317). - `08-checkpoints`: directory symlinks are no longer followed by rewind (v2.1.319). Every file the sync commit changed has a refreshed footer: November 12, 2026 and 2.1.322, with localized labels and dates in translations. `fa/03-skills` and `ko/03-skills` got only the S1 `effort` row fix in round 1, and their footers were left as they were (2.1.316 and 2.1.310), because the rest of those files was not synced to 2.1.322. For the same reason, `ko/claude_concepts_guide.md` got only the round-3 Fable rows and keeps its 2.1.310 footer. ## Translation coverage - **vi, ko, fa:** carry every P1 change whose text exists in that locale. - **ja, uk:** carry the P1 changes to the sections they have: `ultrathink`, scheduled tasks, the `effort` row and QUICK_REFERENCE; the README FAQ in ja and uk. - **zh:** condensed. Only the stale model lists were fixed (README FAQ, QUICK_REFERENCE). zh has no model table, fast-mode note, scheduled-tasks section or `effort` row. - **`vi/README.md`:** has no FAQ, so Task 2.9 had nothing to change there. - **ko is partly stale from before this run.** Its module footers were still at 2.1.310, and some 2.1.316 content is missing, such as the `CLAUDE_CODE_SUBAGENT_EFFORT` sentence and `env` row. This PR adds the 2.1.322 P1 changes but does not backfill 2.1.316. - **Locale README stamps:** the ko and fa READMEs still show v2.1.310 in their badge and "latest" lines. Each locale tracks its own sync state, so they were left as they are. - **P3 additions are English only.** ## Review round 1 fixes (`docs: address review of v2.1.322 sync`) Each change was checked again against model-config, env-vars, skills or the raw changelog before it was written. - **S1:** the `03-skills` `effort` row and the `01` `/effort` row now list Fable 5.2, and give it a `medium` default. The `/effort` row also gives `high` for Fable 5.1 and Fable 5 (model-config: "Fable 5.2, Opus 5.5, Sonnet 5.5, and Haiku 5.5 default to `medium`… Other models in the effort levels table default to `high`"). Also changed in fa and ko. - **S2:** `09` `remote-control --settings`: "If the file changes, no new session starts until you restart `claude remote-control`" (CL 2.1.321). English only. - **S3:** the `10-cli` `claude agents` note now names the five flags from CL 2.1.321. English only. - **S4:** the `03-skills` nested-skill exceptions are now attributed to the changelog in the text: "The changelog adds two exceptions that the skills docs don't list yet". English only. - **S5:** the `CLAUDE_CODE_DISABLE_FEATURE_FLAGS` row now says that with the variable set, Remote Control and the other features that need feature-flag fetching are unavailable (env-vars). English only. - **S7:** wrong effort claims removed from sentences this PR rewrote: - `ja/09` and `uk/09` now translate the English effort-level, `xhigh` and default lists. - In `ja/10-cli` and `uk/10-cli`, the false "`max` is exclusive to Opus 4.x" clause is dropped. The English sentence has no such clause. - **N1:** "from v2.1.257 until v2.1.321" in `10-cli`, fa, ko and vi. - **N2:** the `/context` row now says the 10-row limit applies to the table Claude reads. No locale has this row text. - **N4:** the Fable models were added to the `09` effort-level, `xhigh` and default lists in en, fa, ko and vi (ja and uk via S7). In `claude_concepts_guide`, Fable 5.2, 5.1 and 5 rows were added to the model/effort table, and the Fable models to its `xhigh`/`max` note, in en and fa. - **N5:** the `CLAUDE_CODE_SUBAGENT_EFFORT` row now says only what CL 2.1.317 says: a subagent on a different model from the main conversation uses that model's saved effort level or its default, instead of the session's. The old wording said such a subagent "never inherits". How the variable ranks against that rule isn't stated by any source. Also changed in fa and vi; ko has no row. - **N8:** "where Fable is available" was restored to the pre-v2.1.321 `best` behaviour, in en, fa, ko and vi. ## Review round 2 fixes (`docs: add Fable models to the effort-level bullet in 09`) - Added the Fable models to the `09` "Opus 5 / Opus 4.8" effort bullet (en, fa, ko, vi): Fable 5.2 defaults to `medium`, Fable 5.1 and Fable 5 to `high`, and all of them support `xhigh` and `max`. - Added the Fable models to the en `10-cli` `CLAUDE_CODE_EFFORT_LEVEL` row. ## Review round 3 fixes (`docs: align model and effort lists with model-config (v2.1.322 sync)`) The model and effort lists changed in this round now match model-config.md (effort table, default-effort rule and 1M list, re-fetched before editing). The lists still behind are under Follow-ups. - **en (R2-S1):** the Fable models were added to the remaining `09` effort lists (the "Effort level" heading line and three `CLAUDE_CODE_EFFORT_LEVEL` code comments) and to the `10-cli` "Effort Levels" paragraph and its code comment. The paragraph now gives Fable 5.2 a `medium` default, matching the model table above it. - **fa, ko, vi (R2-S1, R2-S2):** mirrored the same lines, and brought the `10-cli` `CLAUDE_CODE_EFFORT_LEVEL` row in line with en. `ko/claude_concepts_guide.md` gains the Fable 5.2, 5.1 and 5 rows, and its `xhigh`/`max` note names the Fable models, as in en and fa. - **ja, uk (R2-S2, R2-S3):** removed the false "`xhigh` is Opus 4.7-only" and "`max` is Opus 4.7/4.6-only" claims from `09` and `10-cli`. The support and `xhigh` lists now match model-config, and the model lists in the `CLAUDE_CODE_EFFORT_LEVEL` row are translated from en. - **ja, uk `04-subagents` (R2-S4):** the `effort` row and the frontmatter comment now list `xhigh`. - **Haiku 4.5 context (R2-N2, factual part only):** `uk/10-cli` listed Haiku 4.5 at 1M tokens. It's now 200K, matching en `10-cli` and model-config's 1M list, which doesn't include Haiku 4.5. The same cell in `ja/10-cli` was fixed too. - Merged `main` (#246, scripts only). ## Learner skills No changes landed. Three edits are pending because writes to `.claude/skills/**` were refused by the permission system in this run: - `lesson-quiz` `question-bank.md` Lesson 09 Q5 explanation: add Fable 5.2 to the `ultrathink` model list (P1). - `self-assessment` `topic-recommendations.md` and its `SKILL.md` mirror, Advanced Features focus line: same change (P1). - Lesson 04 Q10 explanation: optional `/tasks` "Earlier in this session" note (P3). No correct answer letter changes, and all 100 `Review` pointers still resolve. Exact text for the follow-up (from the round-1 review, §6): 1. `.claude/skills/lesson-quiz/references/question-bank.md:718` (Lesson 09 Q5, Explanation): - old: ``Since v2.1.311, typed in the interactive terminal on Opus 5.5, Sonnet 5.5, Haiku 5.5, or Fable 5.1 through Anthropic's API, it also runs that turn at `xhigh` effort,`` - new: ``Since v2.1.311, typed in the interactive terminal on Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.2 (v2.1.321+), or Fable 5.1 through Anthropic's API, it also runs that turn at `xhigh` effort,`` 2. `.claude/skills/self-assessment/SKILL.md:351` **and** `.claude/skills/self-assessment/references/topic-recommendations.md:73` (identical lines): - old: ``and the `ultrathink` keyword, which runs that turn at `xhigh` effort on Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1 (v2.1.311+)`` - new: ``and the `ultrathink` keyword, which runs that turn at `xhigh` effort on Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.2, and Fable 5.1 (v2.1.311+; Fable 5.2 needs v2.1.321+)`` 3. Version bumps: `lesson-quiz/SKILL.md` `version: 1.6.4` → `1.6.5`; `self-assessment/SKILL.md` `version: 2.5.7` → `2.5.8`. 4. Footer stamps: `question-bank.md` and `topic-recommendations.md`, 2.1.316 → 2.1.322. Optionally add `https://code.claude.com/docs/en/model-config#use-ultrathink-for-one-off-deep-reasoning` to Sources; it is already listed in both. 5. Optional (P3): Lesson 04 Q10 explanation, a note on the `/tasks` "Earlier in this session" row. It changes no letter. ## Needs maintainer decision (P2, not applied) 1. **Self-paced `/loop` ending.** - Repo: says nothing about how a no-interval `/loop` ends. - Docs: "If an iteration ends without either rescheduling or stopping, Claude Code schedules one fallback wakeup about 20 minutes later". - Changelog 2.1.319: self-paced `/loop` now ends "instead of scheduling a fallback wakeup; set `CLAUDE_CODE_LOOP_KEEPALIVE=1` to keep the old behavior". - https://code.claude.com/docs/en/scheduled-tasks#stop-a-loop 2. **Auto mode with telemetry or feature flags off.** - Repo (`10-cli` `CLAUDE_CODE_AUTO_MODE_SERVER` row, `09`): "Set to `0` to use Claude Code's own auto-mode classifier requests instead of server-side review". - Docs: when the review is dropped, "Claude Code falls back to its own classifier requests". - Changelog 2.1.319: calls the server can't check "are asked about or denied, with no fallback to the built-in classifier". - https://code.claude.com/docs/en/permission-modes#server-side-classifier-review 3. **MCP tasks.** - Repo (`05-mcp`): public beta since v2.1.304, needs feature-flag fetching (not Bedrock, Vertex, Foundry or telemetry off). - Docs: same. - Changelog 2.1.319: terminal support moves tasks to the background, works without feature-flag fetching, and adds `CLAUDE_CODE_DISABLE_MCP_TASK_BACKGROUND` and `CLAUDE_CODE_DISABLE_MCP_TASKS`. The second variable is only in the changelog. - https://code.claude.com/docs/en/mcp#mcp-tasks-that-run-on-the-server 4. **`deniedMcpServers` URL entries.** - Repo (`05-mcp`): "`serverUrl` | A remote server URL, exact or with `*` wildcards". - Changelog 2.1.318: URL entries also block Anthropic-provided servers and cloud-session connectors. - Docs: "a `serverUrl` pattern written for the connector's own URL doesn't match it". - https://code.claude.com/docs/en/mcp#how-connectors-reach-claude-code 5. **`CLAUDE_CODE_PLUGIN_DIR_WATCH`.** - Repo (`07-plugins`): has only a generic hot-reload note. - Changelog 2.1.321: headless sessions now reload `.claude/skills` mods, and `=0` turns this off. - Docs: reloading covers `--plugin-dir` mods, is on in interactive sessions, and "Set to `1` to turn it on in non-interactive sessions". - https://code.claude.com/docs/en/env-vars#variables 6. **Mods' own tool calls.** - Repo (`07-plugins`): says nothing about prompting. - Changelog 2.1.321: `$.tool.call` and `$.mcp.call` "raise no permission prompt, even under your own ask rules". - Docs: "`$.mcp.call` | Calls a tool on a connected MCP server, under the session's permission rules". - https://code.claude.com/docs/en/plugins/mods/admin#review-what-a-mod-can-do ## Follow-ups (separate PRs) - **Stamps only (review N3 + N6):** add Fable 5.2 to the "Compatible Models" footers (88 lines; root files still list Fable 5.1 as newest, and module files lack Opus 5.5, Sonnet 5.5 and Haiku 5.5). Align the locale README badges and "latest" lines: ja 2.1.119, zh and uk 2.1.112, ko and fa 2.1.310. - **ko catch-up sync (review N7):** backfill 2.1.316 in ko: the Opus 4.8 fast-mode deprecation, the `CLAUDE_CODE_SUBAGENT_EFFORT` sentence and row, and the v2.1.311 `ultrathink` model list. - **Learner skills (review S6):** apply the exact text under "Learner skills" above once `.claude/skills/**` is writable. - **"Effort Levels (…)" headings (review R2-N1):** `10-cli` and its locale copies name only some models in the heading. They were left unchanged because renaming them changes the anchors. - **Opus 4.6 row (R2-N4):** `claude_concepts_guide.md` (and fa, ko) has no Opus 4.6 row, but the note below the table mentions it. The Sonnet 4.6 row's "1M tokens" also needs the `[1m]`-variant qualifier. - **`high`-default lists (R2-N5):** the `01` `/effort` row and the `10-cli` `CLAUDE_CODE_EFFORT_LEVEL` row (and their locale copies) leave Opus 4.6 and Sonnet 4.6 out of the `high` default. - **ja/uk/zh/vi effort catch-up (R2-N6):** the `/effort` rows in `ja/01`, `uk/01`, `zh/01` and `vi/01` still say `max` needs Opus 4.7 or Opus 4.6. `ja/claude_concepts_guide.md:3061` has an Opus 4.7-era table. - **uk/ja `10-cli` model tables (rest of R2-N2):** `uk/10-cli` `--effort` lacks `xhigh`, its model table is Opus 4.6-era (and Opus 4.6 / Sonnet 4.6 reach 1M only through `[1m]`), and it says "Opus 4.6 підтримує…". The `ja/10-cli` model table is Opus 4.7-era. - **`06-hooks` context-limit comment:** the `CONTEXT_LIMIT` comment's 1M list leaves out the Fable models and Opus 4.7, and lists Sonnet 4.6, which reaches 1M only through `[1m]` (also in fa, ko and vi). This predates the PR. - **ja/uk stale model lists:** `ja/09:228` and `uk/09:220` ("all models (Opus 4.7/4.6, Sonnet 4.6, Haiku 4.5)"), and `ja/10-cli:717-719` (the "Opus 4.7" heading and paragraph, the counterpart of en `10-cli:853`). In ja and uk, the 2.1.322 stamp covers the sections those files have; these older lists are tracked here. ## Validation `pre-commit run --all-files` passes: markdown-lint, cross-references, link-check (247 URLs) and markdown-rendering in all five hooked languages, plus the Python checks. The Mermaid hooks were skipped with `SKIP=mermaid,vietnamese-mermaid,japanese-mermaid,korean-mermaid,persian-mermaid` because their `language: node` environment fails to install under pre-commit 4.7.0. `python scripts/check_mermaid.py --strict` was run directly instead: Pele rendered all 416 blocks. The pre-edit baseline was also all green. For the round-1 fixes, `pre-commit run --files` on the 20 changed files passes, with the same Mermaid SKIP; the `language: node` install error was reproduced. `check_mermaid.py --strict` (416 blocks) and `check_cross_references.py` (675 files) also pass. For round 3, pre-commit on the 15 changed files passes, with the same Mermaid SKIP. `check_cross_references.py` (676 files after the merge), `check_mermaid.py --strict` (416 blocks) and `pytest scripts/tests/` (234 passed, after merging #246) also pass. ## Sources - https://raw.githubusercontent.com/anthropics/claude-code/main/CHANGELOG.md (2.1.317–2.1.322) and https://code.claude.com/docs/en/changelog - https://www.npmjs.com/package/@anthropic-ai/claude-code - https://code.claude.com/docs/en/model-config - https://code.claude.com/docs/en/fast-mode - https://code.claude.com/docs/en/scheduled-tasks - https://code.claude.com/docs/en/remote-control - https://code.claude.com/docs/en/errors - https://code.claude.com/docs/en/settings-reference#permissions-denyinsteadofprompting - https://code.claude.com/docs/en/env-vars - https://code.claude.com/docs/en/hooks - https://code.claude.com/docs/en/agent-sdk/hooks - https://code.claude.com/docs/en/tools-reference - https://code.claude.com/docs/en/plugins/mods/create - https://code.claude.com/docs/en/plugins/org - https://code.claude.com/docs/en/skills - https://code.claude.com/docs/en/commands - https://code.claude.com/docs/en/vs-code - https://code.claude.com/docs/en/agent-view - https://code.claude.com/docs/en/mcp - https://code.claude.com/docs/en/permissions - https://code.claude.com/docs/en/permission-modes - https://code.claude.com/docs/en/cli-reference
CLI リファレンス
概観
Claude Code CLI(Command Line Interface)は Claude Code を操作する主要な手段である。クエリの実行、セッション管理、モデル設定、開発ワークフローへの組み込みを行う強力なオプション群を備えている。
アーキテクチャ
graph TD
A["User Terminal"] -->|"claude [options] [query]"| B["Claude Code CLI"]
B -->|Interactive| C["REPL Mode"]
B -->|"--print"| D["Print Mode (SDK)"]
B -->|"--resume"| E["Session Resume"]
C -->|Conversation| F["Claude API"]
D -->|Single Query| F
E -->|Load Context| F
F -->|Response| G["Output"]
G -->|text/json/stream-json| H["Terminal/Pipe"]
ランタイムとパッケージング
v2.1.113 以降、Claude Code CLI は npm のオプション依存を介して プラットフォーム別のネイティブバイナリ(macOS、Linux、Windows)を起動する。バイナリはインストール時に OS とアーキテクチャに合わせて選択される — 旧来のバンドル JavaScript ランタイムは macOS / Linux ではもはやデフォルトではない。
推奨インストール方法はネイティブインストーラーである(curl -fsSL https://claude.ai/install.sh | bash、Windows では irm https://claude.ai/install.ps1 | iex)。公式 README では npm によるインストールは非推奨とされている。ネイティブインストーラー、Homebrew(brew install --cask claude-code)、または WinGet(winget install Anthropic.ClaudeCode)を推奨する。参考までに、npm install -g @anthropic-ai/claude-code(Node.js 22 以上)はプラットフォーム別のオプション依存関係を通じて同じネイティブバイナリをインストールする。npm 12 では Claude Code の postinstall ステップがデフォルトでスキップされるため、このインストールは Error: claude native binary not installed. で終わる。ネイティブインストーラーに切り替えるか、Fix an npm 12 install の手順に従うこと。
ダウンロードホスト(v2.1.116+): ネイティブバイナリ成果物は https://downloads.claude.ai/claude-code-releases から配信される。
企業ネットワーク/プロキシ環境: ネットワークが明示的な許可リストを必要とする場合、プロキシのエグレスルールに
downloads.claude.ai(およびhttps://downloads.claude.ai/claude-code-releases)を追加すること。以前storage.googleapis.comまたは npm レジストリのみを許可していた環境は更新が必要で、未対応のままだとclaude updateや初回インストールが失敗する。
旧来の JavaScript バンドルは Windows 用および固定利用の環境向けに引き続き提供される。これらのインストールでは Glob と Grep が引き続きファーストクラスツールとして同梱される(ツール 節の Glob/Grep 注記を参照)。
CLI コマンド
| コマンド | 説明 | 例 |
|---|---|---|
claude |
対話型 REPL を起動 | claude |
claude "query" |
初期プロンプト付きで REPL を起動 | claude "explain this project" |
claude -p "query" |
プリントモード - クエリ実行後に終了 | claude -p "explain this function" |
cat file | claude -p "query" |
パイプ入力を処理 | cat logs.txt | claude -p "explain" |
claude -c |
直近の会話を継続 | claude -c |
claude -c -p "query" |
プリントモードで継続 | claude -c -p "check for type errors" |
claude -r "<session>" "query" |
ID または名前でセッション再開 | claude -r "auth-refactor" "finish this PR" |
claude update |
最新版に更新 | claude update |
/doctor(スラッシュコマンド) |
インストール、設定、プラグインの健全性を診断する。v2.1.116 以降は Claude が応答中でも開ける ようになり、ステータスアイコンをインライン表示し、f キーで検出された問題を自動修正する |
REPL 内で /doctor を実行 |
claude mcp |
MCP サーバーを設定 | MCP のドキュメント を参照 |
claude mcp serve |
Claude Code を MCP サーバーとして起動 | claude mcp serve |
claude agents |
設定済みのサブエージェントを一覧表示 | claude agents |
claude auto-mode defaults |
自動モードのデフォルトルールを JSON で出力 | claude auto-mode defaults |
claude remote-control |
リモートコントロールサーバーを起動(サーバーモード、ローカルの対話セッションなし。複数セッションを扱う、--capacity デフォルト 32) |
claude remote-control --name "My Project" |
claude --remote-control [name] |
リモートコントロールを有効にした対話セッションを起動(エイリアス --rc) |
claude --rc |
claude plugin |
プラグインを管理(インストール・有効化・無効化) | claude plugin install my-plugin |
claude plugin tag [path] |
[path] のプラグインに対し {name}--v{version} のリリース git タグを作成。plugin.json と(存在すれば)マーケットプレイスのエントリが一致しているか検証する(v2.1.118+) |
claude plugin tag ./my-plugin |
claude install [version] |
指定したネイティブバイナリのバージョンをインストール。stable、latest、明示的なバージョン文字列を受け付ける |
claude install 2.1.119 |
claude auth login |
ログイン(--email、--sso をサポート) |
claude auth login --email user@example.com |
claude auth logout |
現在のアカウントからログアウト | claude auth logout |
claude auth status |
認証状態を確認(ログイン中なら exit 0、未ログインなら 1) | claude auth status |
主要フラグ
| フラグ | 説明 | 例 |
|---|---|---|
-p, --print |
対話モードを使わず応答を出力 | claude -p "query" |
-c, --continue |
直近の会話を読み込む | claude --continue |
-r, --resume |
ID または名前で特定セッションを再開 | claude --resume auth-refactor |
-v, --version |
バージョン番号を出力 | claude -v |
-w, --worktree |
隔離された git ワークツリーで起動 | claude -w |
-n, --name |
セッションの表示名 | claude -n "auth-refactor" |
--from-pr <url-or-number> |
プル/マージリクエストに紐づくセッションを再開する。v2.1.119 以降は GitHub(クラウド + Enterprise)、GitLab MR、Bitbucket PR の URL を受け付ける(以前は GitHub.com のみ) | claude --from-pr 42 または claude --from-pr https://gitlab.example.com/org/repo/-/merge_requests/17 |
--cloud [description|session_id|url] |
指定した説明で claude.ai 上にクラウドセッションを作成、またはセッション ID か claude.ai/code の URL で既存セッションに接続 | claude --cloud "implement API" |
--remote "task" |
--cloud の非推奨エイリアス(既存セッションに接続する形式も含む)。--cloud を使うこと |
claude --remote "implement API" |
--remote-control, --rc |
リモートコントロール付きの対話セッション | claude --rc |
--teleport |
web セッションをローカルで再開 | claude --teleport |
--teammate-mode |
エージェントチームの表示モード | claude --teammate-mode tmux |
--bare |
最小モード(フック、スキル、プラグイン、MCP、自動メモリ、CLAUDE.md をスキップ) | claude --bare |
--enable-auto-mode |
自動権限モードを解禁(Opus 4.7 の Max 加入者には不要) | claude --enable-auto-mode |
--channels |
MCP チャンネルプラグインを購読。各エントリは plugin:<name>@<marketplace> の形式でタグ付けする必要があり、名前のみの指定は拒否される |
claude --channels plugin:discord@my-marketplace |
--chrome / --no-chrome |
Chrome ブラウザ統合を有効化/無効化 | claude --chrome |
--effort |
思考労力レベルを設定 | claude --effort high |
--init / --init-only |
--init はセッション前に初期化(Setup)フックを実行する(print モードのみ)。--init-only は Setup と SessionStart フックを実行して終了する |
claude -p --init "query" |
--maintenance |
セッション前にメンテナンス(Setup)フックを実行する(print モードのみ) | claude -p --maintenance "query" |
--disable-slash-commands |
すべてのスキルとスラッシュコマンドを無効化 | claude --disable-slash-commands |
--no-session-persistence |
セッション保存を無効化(プリントモード) | claude -p --no-session-persistence "query" |
--exclude-dynamic-system-prompt-sections |
プロンプトキャッシュヒット率向上のため、システムプロンプトから動的セクションを除外 | claude -p --exclude-dynamic-system-prompt-sections "query" |
対話モードとプリントモード
graph LR
A["claude"] -->|Default| B["Interactive REPL"]
A -->|"-p flag"| C["Print Mode"]
B -->|Features| D["Multi-turn conversation<br>Tab completion<br>History<br>Slash commands"]
C -->|Features| E["Single query<br>Scriptable<br>Pipeable<br>JSON output"]
対話モード(デフォルト):
# 対話セッションを開始
claude
# 初期プロンプト付きで開始
claude "explain the authentication flow"
プリントモード(非対話):
# 単一クエリ実行後に終了
claude -p "what does this function do?"
# ファイル内容を処理
cat error.log | claude -p "explain this error"
# 他のツールとチェーン
claude -p "list todos" | grep "URGENT"
モデルと設定
| フラグ | 説明 | 例 |
|---|---|---|
--model |
モデルを設定(sonnet、opus、haiku、または完全名) | claude --model opus |
--fallback-model |
過負荷時の自動フォールバックモデル | claude -p --fallback-model sonnet "query" |
--agent |
セッションに使うエージェントを指定 | claude --agent my-custom-agent |
--agents |
JSON でカスタムサブエージェントを定義 | Agents の設定 を参照 |
--effort |
労力レベルを設定(low、medium、high、xhigh、max) | claude --effort xhigh |
モデル選択の例
# 複雑なタスクには Opus 5.5
claude --model opus "design a caching strategy"
# 速いタスクには Haiku(Anthropic API では v2.1.293 以降 Haiku 5.5、Bedrock・Vertex・Foundry では Haiku 4.5)
claude --model haiku -p "format this JSON"
# モデル名のフルネーム指定
claude --model claude-sonnet-4-6 "review this code"
# 信頼性のためフォールバック付き
claude -p --model opus --fallback-model sonnet "analyze architecture"
# opusplan(Opus が計画、Sonnet が実装)
claude --model opusplan "design and implement the caching layer"
システムプロンプトのカスタマイズ
| フラグ | 説明 | 例 |
|---|---|---|
--system-prompt |
デフォルトプロンプト全体を置き換える | claude --system-prompt "You are a Python expert" |
--system-prompt-file |
ファイルからプロンプトを読み込み、デフォルトのプロンプトを置き換える | claude -p --system-prompt-file ./prompt.txt "query" |
--append-system-prompt |
デフォルトプロンプトに追記 | claude --append-system-prompt "Always use TypeScript" |
システムプロンプトの例
# 完全カスタムなペルソナ
claude --system-prompt "You are a senior security engineer. Focus on vulnerabilities."
# 特定の指示を追加
claude --append-system-prompt "Always include unit tests with code examples"
# 複雑なプロンプトをファイルから読み込み
claude -p --system-prompt-file ./prompts/code-reviewer.txt "review main.py"
システムプロンプトフラグの比較
| フラグ | 挙動 | 対話 | プリント |
|---|---|---|---|
--system-prompt |
デフォルトのシステムプロンプト全体を置き換える | ✅ | ✅ |
--system-prompt-file |
ファイルのプロンプトに置き換える | ✅ | ✅ |
--append-system-prompt |
デフォルトに追記する | ✅ | ✅ |
すべてのシステムプロンプトフラグは対話モードとプリントモードの両方で動作する(ファイル形式は v2.1.69 以降)。--system-prompt と --system-prompt-file はデフォルトのプロンプトを置き換え、append 系のフラグはそれに追加する。
ツールと権限の管理
| フラグ | 説明 | 例 |
|---|---|---|
--tools |
利用可能な組み込みツールを制限 | claude -p --tools "Bash,Edit,Read" "query" |
--allowedTools |
確認なしで実行できるツール | "Bash(git log:*)" "Read" |
--disallowedTools |
コンテキストから除外するツール | "Bash(rm:*)" "Edit" |
--dangerously-skip-permissions |
全ての権限プロンプトをスキップ | claude --dangerously-skip-permissions |
--permission-mode |
指定した権限モードで開始 | claude --permission-mode auto |
--permission-prompt-tool |
権限処理用の MCP ツール | claude -p --mcp-config ./mcp.json --permission-prompt-tool mcp__permissions__approve "query" |
--enable-auto-mode |
自動権限モードを解禁 | claude --enable-auto-mode |
Glob / Grep 注記(v2.1.113+): ネイティブな macOS/Linux ビルドでは、
GlobとGrepは独立したファーストクラスツールではなく、Bash ツール経由で呼び出される組み込みのbfsおよびugrepバイナリとして提供される。Windows 版および npm バンドル(JS)版では引き続きスタンドアロンツールとして公開される。サブエージェントのallowedTools/disallowedToolsリストでは、バックエンド側の置換は透過的なため、どのプラットフォームでも設定では引き続きGlob/Grepを参照すればよい。
PowerShell の自動承認(v2.1.119): PowerShell ツールのコマンドは、Bash コマンドとまったく同じ方式で権限モードによる自動承認が可能になった。
Bash(...)ルールで使うのと同じマッチャ構文で PowerShell の権限を絞り込める — 例:PowerShell(Get-ChildItem:*)。
権限の例
# コードレビュー用の読み取り専用モード
claude --permission-mode plan "review this codebase"
# 安全なツールのみに制限
claude --tools "Read,Grep,Glob" -p "find all TODO comments"
# 特定の git コマンドを確認なしで許可
claude --allowedTools "Bash(git status:*)" "Bash(git log:*)"
# 危険な操作をブロック
claude --disallowedTools "Bash(rm -rf:*)" "Bash(git push --force:*)"
出力とフォーマット
| フラグ | 説明 | オプション | 例 |
|---|---|---|---|
--output-format |
出力フォーマット指定(プリントモード) | text、json、stream-json |
claude -p --output-format json "query" |
--input-format |
入力フォーマット指定(プリントモード) | text、stream-json |
claude -p --input-format stream-json |
--verbose |
詳細ログを有効化 | claude --verbose |
|
--include-partial-messages |
ストリーミングイベントを含める | stream-json が必要 |
claude -p --output-format stream-json --include-partial-messages "query" |
--json-schema |
スキーマに沿って検証された JSON を取得 | claude -p --json-schema '{"type":"object"}' "query" |
|
--max-budget-usd |
プリントモードでの最大支出額。v2.1.217以降、上限に達するとバックグラウンドで実行中のサブエージェントも停止し、新規のサブエージェント起動も拒否される(以前はバックグラウンドエージェントは上限を超えても実行され続けていた) | claude -p --max-budget-usd 5.00 "query" |
出力フォーマットの例
# プレーンテキスト(デフォルト)
claude -p "explain this code"
# プログラムから扱うための JSON
claude -p --output-format json "list all functions in main.py"
# リアルタイム処理向けのストリーミング JSON
claude -p --output-format stream-json "generate a long report"
# スキーマ検証付きの構造化出力
claude -p --json-schema '{"type":"object","properties":{"bugs":{"type":"array"}}}' \
"find bugs in this code and return as JSON"
ワークスペースとディレクトリ
| フラグ | 説明 | 例 |
|---|---|---|
--add-dir |
追加の作業ディレクトリを指定 | claude --add-dir ../apps ../lib |
--setting-sources |
カンマ区切りの設定ソース | claude --setting-sources user,project |
/configの永続化(v2.1.119):/configコマンドで対話的に行った変更は~/.claude/settings.jsonに書き込まれ、通常の優先順位チェーン(policy → local → project → user)に組み込まれるようになった。v2.1.119 以前は一部の/config変更がセッション限定だった。完全な優先順位については メモリと設定 を参照。 |--settings| ファイルまたは JSON から設定を読み込む |claude --settings ./settings.json| |--plugin-dir| ディレクトリからプラグインを読み込む(複数指定可) |claude --plugin-dir ./my-plugin|
複数ディレクトリの例
# 複数のプロジェクトディレクトリを横断作業
claude --add-dir ../frontend ../backend ../shared "find all API endpoints"
# カスタム設定の読み込み
claude --settings '{"model":"opus","verbose":true}' "complex task"
MCP の設定
| フラグ | 説明 | 例 |
|---|---|---|
--mcp-config |
JSON から MCP サーバーを読み込む | claude --mcp-config ./mcp.json |
--strict-mcp-config |
指定した MCP 設定のみを使う | claude --strict-mcp-config --mcp-config ./mcp.json |
--channels |
MCP チャンネルプラグインを購読。各エントリは plugin:<name>@<marketplace> の形式でタグ付けする必要があり、名前のみの指定は拒否される |
claude --channels plugin:discord@my-marketplace |
MCP の例
# GitHub MCP サーバーの読み込み
claude --mcp-config ./github-mcp.json "list open PRs"
# 厳密モード - 指定したサーバーのみ
claude --strict-mcp-config --mcp-config ./production-mcp.json "deploy to staging"
セッション管理
| フラグ | 説明 | 例 |
|---|---|---|
--session-id |
特定セッション ID(UUID)を使用 | claude --session-id "550e8400-..." |
--fork-session |
再開時に新しいセッションを作成 | claude --resume abc123 --fork-session |
セッションの例
# 直前の会話を継続
claude -c
# 名前付きセッションを再開
claude -r "feature-auth" "continue implementing login"
# 試行錯誤のためセッションをフォーク
claude --resume feature-auth --fork-session "try alternative approach"
# 特定のセッション ID を使用
claude --session-id "550e8400-e29b-41d4-a716-446655440000" "continue"
セッションのフォーク
既存セッションから分岐したブランチを作成し試行錯誤する:
# 別アプローチを試すためにセッションをフォーク
claude --resume abc123 --fork-session "try alternative implementation"
# カスタムメッセージ付きでフォーク
claude -r "feature-auth" --fork-session "test with different architecture"
ユースケース:
- 元のセッションを失わずに別実装を試す
- 並行して複数のアプローチを試行錯誤する
- 成功した作業からバリエーションのブランチを作る
- メインセッションに影響を与えずに破壊的な変更を試す
元のセッションは変更されず、フォークは新しい独立セッションになる。
高度な機能
| フラグ | 説明 | 例 |
|---|---|---|
--chrome |
Chrome ブラウザ統合を有効化 | claude --chrome |
--no-chrome |
Chrome ブラウザ統合を無効化 | claude --no-chrome |
--ide |
利用可能なら IDE と自動接続 | claude --ide |
--max-turns |
エージェントターンを制限(非対話) | claude -p --max-turns 3 "query" |
--debug |
フィルタ付きデバッグモードを有効化(フィルタは = 形式でのみ適用) |
claude --debug=api,mcp |
--enable-lsp-logging |
詳細な LSP ログを有効化 | claude --enable-lsp-logging |
--betas |
API リクエストのベータヘッダ | claude --betas interleaved-thinking |
--plugin-dir |
ディレクトリからプラグインを読み込む(複数指定可) | claude --plugin-dir ./my-plugin |
--enable-auto-mode |
自動権限モードを解禁 | claude --enable-auto-mode |
--effort |
思考労力レベルを設定 | claude --effort high |
--bare |
最小モード(フック、スキル、プラグイン、MCP、自動メモリ、CLAUDE.md をスキップ) | claude --bare |
--channels |
MCP チャンネルプラグインを購読(plugin:<name>@<marketplace> 形式でタグ付け) |
claude --channels plugin:discord@my-marketplace |
--tmux |
ワークツリー用に tmux セッションを作成(--worktree が必要) |
claude --worktree feature-x --tmux |
--fork-session |
再開時に新しいセッション ID を作成 | claude --resume abc --fork-session |
--max-budget-usd |
最大支出額(プリントモード)。上限に達するとバックグラウンドのサブエージェントも停止する (v2.1.217) | claude -p --max-budget-usd 5.00 "query" |
--json-schema |
検証付き JSON 出力 | claude -p --json-schema '{"type":"object"}' "q" |
プラットフォームとテーマの注記(v2.1.112)
- Windows 版の PowerShell ツール: Windows 向けに専用の PowerShell ツールがロールアウトされ、環境変数で制御できる。
- 「Auto(ターミナルに合わせる)」テーマ: 新しい "Auto (match terminal)" テーマで Claude Code のライト/ダーク表示をターミナルと同期できる。
- 静かな権限プロンプト: 読み取り専用の
Bash呼び出しとGlobパターンは権限プロンプトを発生させなくなった。
高度な例
# 自律アクション数を制限
claude -p --max-turns 5 "refactor this module"
# API 呼び出しをデバッグ
claude --debug=api "test query"
# IDE 統合を有効化
claude --ide "help me with this file"
Agents の設定
--agents フラグはセッションに対するカスタムサブエージェントを定義する JSON オブジェクトを受け取る。
Agents の JSON フォーマット
{
"agent-name": {
"description": "Required: when to invoke this agent",
"prompt": "Required: system prompt for the agent",
"tools": ["Optional", "array", "of", "tools"],
"model": "optional: sonnet|opus|haiku"
}
}
必須フィールド:
description- エージェントを使う場面の自然言語による説明prompt- エージェントの役割と挙動を定義するシステムプロンプト
任意フィールド:
tools- 利用可能なツールの配列(省略時は全ツールを継承)- 形式:
["Read", "Grep", "Glob", "Bash"]
- 形式:
model- 使用するモデル:sonnet、opus、haiku
完全な Agents の例
{
"code-reviewer": {
"description": "Expert code reviewer. Use proactively after code changes.",
"prompt": "You are a senior code reviewer. Focus on code quality, security, and best practices.",
"tools": ["Read", "Grep", "Glob", "Bash"],
"model": "sonnet"
},
"debugger": {
"description": "Debugging specialist for errors and test failures.",
"prompt": "You are an expert debugger. Analyze errors, identify root causes, and provide fixes.",
"tools": ["Read", "Edit", "Bash", "Grep"],
"model": "opus"
},
"documenter": {
"description": "Documentation specialist for generating guides.",
"prompt": "You are a technical writer. Create clear, comprehensive documentation.",
"tools": ["Read", "Write"],
"model": "haiku"
}
}
Agents コマンドの例
# カスタムエージェントをインラインで定義
claude --agents '{
"security-auditor": {
"description": "Security specialist for vulnerability analysis",
"prompt": "You are a security expert. Find vulnerabilities and suggest fixes.",
"tools": ["Read", "Grep", "Glob"],
"model": "opus"
}
}' "audit this codebase for security issues"
# ファイルからエージェントを読み込み
claude --agents "$(cat ~/.claude/agents.json)" "review the auth module"
# 他のフラグと組み合わせ
claude -p --agents "$(cat agents.json)" --model sonnet "analyze performance"
エージェントの優先順位
複数のエージェント定義が存在する場合、以下の優先順位で読み込まれる:
- CLI 定義(
--agentsフラグ) - セッション固有 - プロジェクトレベル(
.claude/agents/) - 現在のプロジェクト - ユーザーレベル(
~/.claude/agents/) - 全プロジェクト
CLI 定義のエージェントは、当該セッションにおいてプロジェクトおよびユーザーのエージェントを上書きする。プロジェクトレベルのエージェントは、名前が衝突した場合にユーザーレベルのエージェントを上書きする。プラグインレベルのエージェントを含む完全な優先順位表は Lesson 04 — サブエージェント を参照。
価値の高いユースケース
1. CI/CD への組み込み
Claude Code を CI/CD パイプラインに組み込み、コードレビュー、テスト、ドキュメント生成を自動化する。
GitHub Actions の例:
name: AI Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: Run Code Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p --output-format json \
--max-turns 5 \
"Review the changes in this PR for:
- Security vulnerabilities
- Performance issues
- Code quality
Output as JSON with 'issues' array" > review.json
- name: Post Review Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = JSON.parse(fs.readFileSync('review.json', 'utf8'));
// Process and post review comments
Jenkins パイプライン:
pipeline {
agent any
stages {
stage('AI Review') {
steps {
sh '''
claude -p --output-format json \
--max-turns 3 \
"Analyze test coverage and suggest missing tests" \
> coverage-analysis.json
'''
}
}
}
}
2. スクリプトのパイプ処理
ファイル、ログ、データを Claude に流し込んで分析する。
ログ解析:
# エラーログの分析
tail -1000 /var/log/app/error.log | claude -p "summarize these errors and suggest fixes"
# アクセスログ内のパターン抽出
cat access.log | claude -p "identify suspicious access patterns"
# git 履歴の要約
git log --oneline -50 | claude -p "summarize recent development activity"
コード処理:
# 特定ファイルのレビュー
cat src/auth.ts | claude -p "review this authentication code for security issues"
# ドキュメントの生成
cat src/api/*.ts | claude -p "generate API documentation in markdown"
# TODO の抽出と優先順位付け
grep -r "TODO" src/ | claude -p "prioritize these TODOs by importance"
3. マルチセッションのワークフロー
複数の会話スレッドで複雑なプロジェクトを管理する。
# フィーチャーブランチ用セッションを開始
claude -r "feature-auth" "let's implement user authentication"
# 後で同じセッションを継続
claude -r "feature-auth" "add password reset functionality"
# 別アプローチを試すためフォーク
claude --resume feature-auth --fork-session "try OAuth instead"
# 別の機能のセッションへ切り替え
claude -r "feature-payments" "continue with Stripe integration"
4. カスタムエージェントの設定
チームのワークフロー向けに専門エージェントを定義する。
# エージェント設定をファイルに保存
cat > ~/.claude/agents.json << 'EOF'
{
"reviewer": {
"description": "Code reviewer for PR reviews",
"prompt": "Review code for quality, security, and maintainability.",
"model": "opus"
},
"documenter": {
"description": "Documentation specialist",
"prompt": "Generate clear, comprehensive documentation.",
"model": "sonnet"
},
"refactorer": {
"description": "Code refactoring expert",
"prompt": "Suggest and implement clean code refactoring.",
"tools": ["Read", "Edit", "Glob"]
}
}
EOF
# セッションでエージェントを使用
claude --agents "$(cat ~/.claude/agents.json)" "review the auth module"
5. バッチ処理
一貫した設定で複数クエリを処理する。
# 複数ファイルの処理
for file in src/*.ts; do
echo "Processing $file..."
claude -p --model haiku "summarize this file: $(cat $file)" >> summaries.md
done
# バッチコードレビュー
find src -name "*.py" -exec sh -c '
echo "## $1" >> review.md
cat "$1" | claude -p "brief code review" >> review.md
' _ {} \;
# 全モジュールのテスト生成
for module in $(ls src/modules/); do
claude -p "generate unit tests for src/modules/$module" > "tests/$module.test.ts"
done
6. セキュリティを意識した開発
権限制御で安全に運用する。
# 読み取り専用のセキュリティ監査
claude --permission-mode plan \
--tools "Read,Grep,Glob" \
"audit this codebase for security vulnerabilities"
# 危険なコマンドをブロック
claude --disallowedTools "Bash(rm:*)" "Bash(curl:*)" "Bash(wget:*)" \
"help me clean up this project"
# 制限付き自動化
claude -p --max-turns 2 \
--allowedTools "Read" "Glob" \
"find all hardcoded credentials"
7. JSON API としての利用
jq のパースと組み合わせて、Claude をプログラム可能な API として活用する。
# 構造化された分析を取得
claude -p --output-format json \
--json-schema '{"type":"object","properties":{"functions":{"type":"array"},"complexity":{"type":"string"}}}' \
"analyze main.py and return function list with complexity rating"
# jq で処理に組み込む(スキーマ出力は .structured_output に入る)
claude -p --output-format json \
--json-schema '{"type":"object","properties":{"endpoints":{"type":"array"}}}' \
"list all API endpoints" | jq '.structured_output.endpoints[]'
# スクリプト内で利用
RESULT=$(claude -p --output-format json \
--json-schema '{"type":"object","properties":{"secure":{"type":"boolean"},"issues":{"type":"array"}},"required":["secure","issues"]}' \
"is this code secure?" < code.py)
if echo "$RESULT" | jq -e '.structured_output.secure == false' > /dev/null; then
echo "Security issues found!"
echo "$RESULT" | jq '.structured_output.issues[]'
fi
jq でのパース例
jq で Claude の JSON 出力をパース・処理する。応答テキストは .result に入り、--json-schema を指定した場合は検証済みオブジェクトが .structured_output に入る(以下の $SCHEMA は各フィルタが読むフィールドを定義したスキーマを表す):
# 応答テキストの抽出
claude -p --output-format json "analyze this code" | jq -r '.result'
# 配列要素のフィルタ
claude -p --output-format json --json-schema "$SCHEMA" "list issues" | jq -r '.structured_output.issues[] | select(.severity=="high")'
# 複数フィールドの抽出
claude -p --output-format json --json-schema "$SCHEMA" "describe the project" | jq -r '.structured_output | {name, version, description}'
# CSV への変換
claude -p --output-format json --json-schema "$SCHEMA" "list functions" | jq -r '.structured_output.functions[] | [.name, .lineCount] | @csv'
# 条件付き処理
claude -p --output-format json --json-schema "$SCHEMA" "check security" | jq 'if (.structured_output.vulnerabilities | length) > 0 then "UNSAFE" else "SAFE" end'
# ネストされた値の取得
claude -p --output-format json --json-schema "$SCHEMA" "analyze performance" | jq '.structured_output.metrics.cpu.usage'
# 配列全体の処理
claude -p --output-format json --json-schema "$SCHEMA" "find todos" | jq '.structured_output.todos | length'
# 出力の変換
claude -p --output-format json --json-schema "$SCHEMA" "list improvements" | jq '.structured_output.improvements | map({title: .title, priority: .priority})'
モデル
Claude Code は能力の異なる複数のモデルをサポートする:
| モデル | ID | コンテキストウィンドウ | 備考 |
|---|---|---|---|
| Opus 4.7 | claude-opus-4-7 |
1M トークン(1M コンテキスト対応は v2.1.117 で実装) | 最も能力が高く、適応的な労力レベルを備える。Claude Code では Opus 4.7 ローンチ(2026-04-16)以降 xhigh がデフォルトの労力レベル |
| Sonnet 4.6 | claude-sonnet-4-6 |
1M トークン | 速度と能力のバランスが良い。Pro/Max 加入者のデフォルト労力は v2.1.117 で medium から high に引き上げられた |
| Haiku 4.5 | claude-haiku-4-5 |
200K トークン | 最速で、軽いタスクに最適 |
モデルの選択
# 短縮名で指定
claude --model opus "complex architectural review"
claude --model sonnet "implement this feature"
claude --model haiku -p "format this JSON"
# opusplan エイリアス(Opus が計画、Sonnet が実装)
claude --model opusplan "design and implement the API"
# セッション中にファストモードを切り替え
/fast
労力レベル(Opus 4.7)
Opus 4.7 は適応的推論をサポートし、軽い順から low(○)、medium(◐)、high(●)、xhigh(Claude Code では Opus 4.7 ローンチ以降のデフォルト、2026-04-16)、max の労力レベルを持つ。Opus 4.6 / Sonnet 4.6 では、Pro/Max 加入者のデフォルト労力が v2.1.117 で medium から high に引き上げられた。
# CLI フラグで労力レベルを設定
claude --effort xhigh "complex review"
# スラッシュコマンドで労力レベルを設定
/effort xhigh
# 環境変数で労力レベルを設定
export CLAUDE_CODE_EFFORT_LEVEL=xhigh # low, medium, high, xhigh (default on Opus 4.7), or max
プロンプト内のキーワード「ultrathink」は深い推論を有効化する。v2.1.311 以降、対話型ターミナルで入力すると、Anthropic の API 経由の Opus 5.5、Sonnet 5.5、Haiku 5.5、Fable 5.2(v2.1.321 以降)、Fable 5.1 ではそのターンを xhigh で実行する(可能な場合は虹色で表示される。VS Code は v2.1.316 以降)。CLAUDE_CODE_DISABLE_ULTRATHINK=1(v2.1.316)でこのキーワードを無効化できる。
主要な環境変数
| 変数 | 説明 |
|---|---|
ANTHROPIC_API_KEY |
認証用の API キー |
ANTHROPIC_MODEL |
デフォルトモデルを上書き |
ANTHROPIC_CUSTOM_MODEL_OPTION |
API 用のカスタムモデルオプション |
ANTHROPIC_DEFAULT_OPUS_MODEL |
デフォルトの Opus モデル ID を上書き |
ANTHROPIC_DEFAULT_SONNET_MODEL |
デフォルトの Sonnet モデル ID を上書き |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
デフォルトの Haiku モデル ID を上書き |
MAX_THINKING_TOKENS |
拡張思考のトークン予算を設定 |
CLAUDE_CODE_EFFORT_LEVEL |
労力レベルを設定(low/medium/high/xhigh/max) — デフォルトは Fable 5.2、Opus 5.5、Sonnet 5.5、Haiku 5.5 では medium、Fable 5.1、Fable 5、Opus 5、Sonnet 5、Opus 4.8 では high(Opus 4.7 では xhigh)。xhigh には Fable モデル、Opus 5.5、Sonnet 5.5、Haiku 5.5、Opus 5、Sonnet 5、Opus 4.8/4.7 が必要。max は Fable モデル、Opus 5.5、Sonnet 5.5、Haiku 5.5、Opus 5、Sonnet 5、Opus 4.8/4.7/4.6、Sonnet 4.6 で使える |
CLAUDE_CODE_SIMPLE |
最小モード(--bare フラグで設定される) |
CLAUDE_CODE_DISABLE_AUTO_MEMORY |
1 を設定すると自動メモリを無効化する(自動メモリファイルを作成も読み込みもしない) |
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS |
バックグラウンドタスク実行を無効化 |
CLAUDE_CODE_DISABLE_CRON |
セッションスコープのスケジュールタスク(/loop、cron ツール)を無効化。クラウドスケジュールタスクには影響しない |
CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS |
git 関連の指示を無効化 |
CLAUDE_CODE_DISABLE_TERMINAL_TITLE |
ターミナルタイトル更新を無効化 |
CLAUDE_CODE_DISABLE_1M_CONTEXT |
1M トークンコンテキストウィンドウを無効化 |
CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK |
非ストリーミングフォールバックを無効化 |
CLAUDE_CODE_ENABLE_TASKS |
Task ツールがデフォルト。0 を設定すると従来の TodoWrite ツールに戻る |
CLAUDE_CODE_TASK_LIST_ID |
セッション間で共有する名前付きタスクディレクトリ |
CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION |
プロンプトサジェストを切り替え(true/false) |
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS |
実験的なエージェントチームを有効化 |
CLAUDE_CODE_NEW_INIT |
新しい初期化フローを使用 |
CLAUDE_CODE_SUBAGENT_MODEL |
サブエージェント実行用モデル |
CLAUDE_CODE_PLUGIN_SEED_DIR |
プラグインシードファイル用ディレクトリ |
CLAUDE_CODE_SUBPROCESS_ENV_SCRUB |
サブプロセスから取り除く環境変数 |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE |
自動コンパクションのパーセンテージを上書き |
CLAUDE_STREAM_IDLE_TIMEOUT_MS |
ストリームのアイドルタイムアウト(ミリ秒) |
SLASH_COMMAND_TOOL_CHAR_BUDGET |
スラッシュコマンドツールの文字数予算 |
ENABLE_TOOL_SEARCH |
ツール検索機能を有効化 |
MAX_MCP_OUTPUT_TOKENS |
MCP ツール出力の最大トークン数 |
CLAUDE_CODE_PERFORCE_MODE |
1 を設定すると Perforce モードを有効化 — ファイルをデフォルトで読み取り専用として扱う(Perforce/P4 バージョン管理ワークフロー向け)(v2.1.98 追加) |
DISABLE_UPDATES |
手動の claude update を含むすべての更新経路をブロックする。バックグラウンドの自動更新のみブロックする DISABLE_AUTOUPDATER より厳密(v2.1.118+) |
CLAUDE_CODE_HIDE_CWD |
1 に設定すると、起動時ロゴでカレント作業ディレクトリを隠す(プライバシー/画面共有用途)(v2.1.119+) |
CLAUDE_CODE_FORK_SUBAGENT |
0 を設定するとフォークサブエージェントを無効化する。v2.1.302 以降、ターミナル、claude -p、Agent SDK、デスクトップアプリ、VS Code でデフォルト有効。v2.1.302 より前は、claude -p と Agent SDK で有効にするには 1 を設定する。 |
OTEL_LOG_TOOL_DETAILS |
1 を設定すると OpenTelemetry イベント中のカスタムおよび MCP コマンド名のリダクションを解除する(v2.1.117+)。デフォルトはリダクション有効。 |
Agent Platform(Vertex AI)とゲートウェイでの
ENABLE_TOOL_SEARCH: v2.1.221 より前は、ENABLE_TOOL_SEARCH=trueを設定しない限り Google Cloud の Agent Platform ではツール検索がオフだった。現在は同プラットフォームで Claude Opus 4.5、Sonnet 4.5、Haiku 4.5 以降のモデルに対して有効である(それ以前のモデルはすべての MCP ツールを事前に読み込み、trueを設定しても変わらない)。ツール検索はデフォルトで有効で、v2.1.304 以降はカスタムのANTHROPIC_BASE_URLゲートウェイ経由でも有効になる(v2.1.305 以降、ツール検索を 400 または 422 で拒否するゲートウェイに対してはツール検索なしで再試行される)。すべてのツールを事前に読み込むにはENABLE_TOOL_SEARCH=falseを設定する。
クイックリファレンス
最もよく使うコマンド
# 対話セッション
claude
# サッと質問
claude -p "how do I..."
# 会話を継続
claude -c
# ファイルを処理
cat file.py | claude -p "review this"
# スクリプト用の JSON 出力
claude -p --output-format json "query"
フラグの組み合わせ
| ユースケース | コマンド |
|---|---|
| 簡易コードレビュー | cat file | claude -p "review" |
| 構造化出力 | claude -p --output-format json "query" |
| 安全な探索 | claude --permission-mode plan |
| 安全装置付き自律実行 | claude --enable-auto-mode --permission-mode auto |
| CI/CD 連携 | claude -p --max-turns 3 --output-format json |
| 作業の再開 | claude -r "session-name" |
| カスタムモデル | claude --model opus "complex task" |
| 最小モード | claude --bare "quick query" |
| 予算上限付き実行 | claude -p --max-budget-usd 2.00 "analyze code" |
トラブルシューティング
コマンドが見つからない
問題: claude: command not found
対処法:
- Claude Code をインストール:
curl -fsSL https://claude.ai/install.sh | bash(ネイティブ、推奨)またはnpm install -g @anthropic-ai/claude-code - PATH に
~/.local/bin(ネイティブインストール)または npm のグローバル bin ディレクトリが含まれていることを確認 claude doctorを実行
API キーの問題
問題: 認証に失敗する
対処法:
- API キーを設定:
export ANTHROPIC_API_KEY=your-key - キーが有効でクレジットが十分か確認
- 要求モデルに対するキー権限を確認
セッションが見つからない
問題: セッションを再開できない
対処法:
- 利用可能なセッションを一覧表示し、正しい名前/ID を確認
- セッションは一定期間使用しないと失効する場合がある
-cで直近のセッションを継続する
出力フォーマットの問題
問題: JSON 出力が壊れている
対処法:
--json-schemaで構造を強制する- プロンプト内に明示的な JSON 指示を含める
- プロンプトで JSON を要求するだけでなく
--output-format jsonを使用する
権限拒否
問題: ツール実行がブロックされる
対処法:
--permission-mode設定を確認--allowedToolsと--disallowedToolsフラグを見直す- 自動化用途では(注意のうえ)
--dangerously-skip-permissionsを使用
追加リソース
- 公式 CLI リファレンス - 完全なコマンドリファレンス
- ヘッドレスモードのドキュメント - 自動実行
- スラッシュコマンド - Claude 内のカスタムショートカット
- メモリガイド - CLAUDE.md による永続コンテキスト
- MCP プロトコル - 外部ツール連携
- 高度な機能 - プランニングモード、拡張思考
- サブエージェントガイド - 委譲によるタスク実行
Claude How To ガイドシリーズの一部
最終更新: 2026 年 11 月 12 日 Claude Code バージョン: 2.1.322 出典:
- https://code.claude.com/docs/en/agent-sdk/agent-loop#turns-and-messages
- https://code.claude.com/docs/en/model-config#use-ultrathink-for-one-off-deep-reasoning
- https://code.claude.com/docs/en/changelog#2-1-316
- https://code.claude.com/docs/en/troubleshoot-install#fix-an-npm-12-install
- https://code.claude.com/docs/en/cli-reference
- https://code.claude.com/docs/en/model-config
- https://code.claude.com/docs/en/settings
- https://code.claude.com/docs/en/changelog
- https://www.anthropic.com/news/claude-opus-4-7
- https://github.com/anthropics/claude-code/releases/tag/v2.1.113
- https://github.com/anthropics/claude-code/releases/tag/v2.1.116
- https://github.com/anthropics/claude-code/releases/tag/v2.1.117
- https://github.com/anthropics/claude-code/releases/tag/v2.1.118
- https://github.com/anthropics/claude-code/releases/tag/v2.1.119
- https://code.claude.com/docs/en/remote-control
- https://code.claude.com/docs/en/setup
- https://code.claude.com/docs/en/troubleshoot-install#command-not-found-claude-after-installation
- https://code.claude.com/docs/en/headless
- https://code.claude.com/docs/en/env-vars
- https://code.claude.com/docs/en/sub-agents
- https://code.claude.com/docs/en/changelog#2-1-302
- https://github.com/anthropics/claude-code
- https://platform.claude.com/docs/en/about-claude/models/overview
- https://code.claude.com/docs/en/cli-reference#cli-flags
- https://code.claude.com/docs/en/changelog#2-1-304
- https://code.claude.com/docs/en/mcp#configure-tool-search
- https://code.claude.com/docs/en/mcp#tool-search-through-a-gateway
- https://code.claude.com/docs/en/env-vars#variables
- https://code.claude.com/docs/en/scheduled-tasks
- https://code.claude.com/docs/en/model-config#adjust-effort-level 対応モデル: Claude Fable 5、Claude Opus 5、Claude Sonnet 5、Claude Sonnet 4.6、Claude Opus 4.8、Claude Haiku 4.5