メインコンテンツへスキップ

OPERATOR GUIDE / 2.1.220

Claude Code CLI 完全ガイド

実行モードを選び、コンテキストを保ち、権限を制御し、ツールを接続して、実際にロードされた機能を検証するための実践ルートです。

完全リファレンスを開く →
00

ルートマップ

01

実行モードを選ぶ

対話モードは共同作業、print mode は境界のある自動化、background mode は継続実行に適します。

02

セッションを継続する

最新セッションを continue、ID や名前で resume、transcript を失わず background 作業へ attach します。

03

権限境界を設定する

Permission mode、allowed tools、sandbox settings、safe mode が agent の権限を決めます。

04

MCP を意図的に接続する

設定 scope、approval、health を確認し、リモート server の認証を別に実行します。

05

Plugins、skills、hooks を構成する

Plugin は配布、skill は手順、hook はライフサイクルイベントの観測や制御を担います。

06

Agents を運用し差分を診断する

Background sessions を監視し、logs と doctor、出典台帳で実際の動作を確認します。

01

CHAPTER / 01

実行モード

同じ executable でも三つの運用スタイルがあります。出力、永続化、権限動作が異なるため明示的に選びます。
Manifest コマンド
claude runtime-confirmed

Start Claude Code interactively, run a headless prompt, or manage a session.

claude
関連フラグ
-p, --print

Print a non-interactive response and exit.

none
--background, --bg

Control Claude Code background behavior.

none
--output-format

Select print-mode output: text, json, or stream-json.

none
Manifest プレイブック

Run Claude Code headlessly

Use print mode with bounded turns, structured output, and explicit permissions for scripts and CI.

  1. STEP 01 Start with a bounded text run claude -p --max-turns 8 "Review the current diff"

    Print mode writes the final response and exits.

  2. STEP 02 Request machine-readable output claude -p --output-format json --json-schema '{"type":"object"}' "Summarize the diff"

    JSON output and a schema make downstream parsing explicit.

  3. STEP 03 Grant only required tools claude -p --allowed-tools "Read" "Grep" "Bash(git diff *)" "Review this change"

    Narrow permission rules keep automation bounded.

02

CHAPTER / 02

セッションの継続性

Session state は重要な資産です。名前を付けて resume し、attach、restart、削除の違いを理解します。
Manifest コマンド
claude runtime-confirmed

Start Claude Code interactively, run a headless prompt, or manage a session.

claude
claude attach runtime-confirmed

Attach this terminal to a background session.

claude logs runtime-confirmed

Print recent terminal output for a background session.

関連フラグ
-c, --continue

Continue the most recent conversation in the current directory.

none
-r, --resume

Resume a session by ID or name, or open the session picker.

none
-n, --name

Name the session.

none
Manifest プレイブック

Continue or resume a session

Continue the latest conversation, resume a named session, or attach to a background session.

  1. STEP 01 Continue the latest project session claude --continue

    Loads the most recent conversation associated with this directory.

  2. STEP 02 Resume a named session claude --resume auth-refactor

    Resumes by session ID or user-assigned name.

  3. STEP 03 Attach to a background session claude attach 7c5dcf5d

    Connects the current terminal while the session keeps running.

03

CHAPTER / 03

権限と安全な運用

作業を完了できる最小権限から始めます。権限 bypass は便利な既定値ではなく、高リスクの例外です。
Manifest コマンド
claude runtime-confirmed

Start Claude Code interactively, run a headless prompt, or manage a session.

claude
関連フラグ
--permission-mode

Start in a selected permission mode.

review
--allowed-tools, --allowedTools

Grant matching tools without a permission prompt.

review
--safe-mode

Control Claude Code safe mode behavior.

none
--dangerously-skip-permissions

Control Claude Code dangerously skip permissions behavior.

high
Manifest プレイブック

Design permission boundaries

Choose a permission mode, add narrow allow rules, and keep bypass mode visibly high risk.

  1. STEP 01 Start in plan mode claude --permission-mode plan

    Plan mode supports repository analysis before edits.

  2. STEP 02 Allow specific read-only commands claude --allowed-tools "Read" "Grep" "Bash(git diff *)"

    Tool-pattern rules are safer than broad shell access.

  3. STEP 03 Troubleshoot customizations safely claude --safe-mode

    Safe mode disables project customizations, hooks, plugins, skills, and MCP.

04

CHAPTER / 04

MCP:ターミナル外のツール

MCP server は tools、resources、prompts を追加します。設定 scope、project approval、OAuth 認証は別の境界です。
Manifest コマンド
claude mcp add runtime-confirmed

Add a stdio, SSE, or HTTP MCP server.

claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
claude mcp get runtime-confirmed

Inspect one configured MCP server and its approval state.

claude mcp get sentry
claude mcp login runtime-confirmed

Run the OAuth flow for a configured remote MCP server.

claude mcp login sentry --no-browser
claude mcp serve runtime-confirmed

Expose Claude Code tools as a local stdio MCP server.

claude mcp serve
Manifest プレイブック

Add and authenticate an MCP server

Register a server at the intended scope, inspect it, and run OAuth separately when required.

  1. STEP 01 Add a remote server claude mcp add --transport http sentry https://mcp.sentry.dev/mcp --scope user

    Choose local, user, or project scope deliberately.

  2. STEP 02 Inspect approval and health claude mcp get sentry

    Unapproved project servers remain pending and are not connected.

  3. STEP 03 Authenticate over SSH claude mcp login sentry --no-browser

    Prints an authorization URL rather than opening a browser.

05

CHAPTER / 05

Plugins、skills、hooks

Plugin は skills、commands、agents、hooks、MCP 設定を梱包できます。インストール後にロード済み部品を確認します。
Manifest コマンド
claude plugin marketplace add runtime-confirmed

Register a plugin marketplace source.

claude plugin marketplace add anthropics/claude-plugins-official
claude plugin install runtime-confirmed

Install a plugin from a configured marketplace.

claude plugin install code-review@claude-plugins-official
claude plugin details runtime-confirmed

Show a plugin component inventory and projected token cost.

claude plugin details code-review
claude plugin validate runtime-confirmed

Validate plugin structure and metadata.

claude plugin validate ./my-plugin --strict
関連フラグ
--plugin-dir

Load plugins from directories for this session.

review
Manifest プレイブック

Install plugins and inspect skills and hooks

Add a trusted marketplace, install at a scope, then inspect the loaded skills and hooks in-session.

  1. STEP 01 Add a marketplace claude plugin marketplace add anthropics/claude-plugins-official

    Marketplace sources determine which plugins are installable.

  2. STEP 02 Install at project scope claude plugin install code-review@claude-plugins-official --scope project

    Project scope shares plugin policy with the repository.

  3. STEP 03 Inspect runtime components

    Use /skills, /hooks, and /plugin inside Claude Code to verify what loaded.

06

CHAPTER / 06

Agents と background 作業

Background session は作業を継続し、agent view と logs が運用コントロール面になります。
Manifest コマンド
claude agents runtime-confirmed

Open agent view or query active background sessions.

claude agents --json
claude logs runtime-confirmed

Print recent terminal output for a background session.

claude stop runtime-confirmed

Stop a background session while retaining its conversation.

claude respawn runtime-confirmed

Restart a background session with its conversation intact.

関連フラグ
--agent

Use a named agent for this session.

review
--agents

Define session subagents with a JSON object.

review
--background, --bg

Control Claude Code background behavior.

none
Manifest プレイブック

Launch and monitor agents

Define a session agent, start work in the background, and inspect active sessions as JSON.

  1. STEP 01 Start a named agent in the background claude --background --agent reviewer "Review the current branch"

    The command returns a session ID for later management.

  2. STEP 02 List active agents claude agents --json

    JSON mode supports external monitoring and orchestration.

  3. STEP 03 Read recent output claude logs 7c5dcf5d

    Inspect progress without attaching to the session.

07

CHAPTER / 07

Headless 自動化

Print mode は scripts 向けです。turns とコスト、出力形式、必要な tools を明示します。
Manifest コマンド
claude runtime-confirmed

Start Claude Code interactively, run a headless prompt, or manage a session.

claude
関連フラグ
-p, --print

Print a non-interactive response and exit.

none
--max-turns

Limit agentic turns in print mode.

none
--max-budget-usd

Stop print-mode execution at an approximate dollar budget.

none
--json-schema

Validate print-mode structured output against a JSON Schema.

none
--input-format

Select print-mode input: text or stream-json.

none
--output-format

Select print-mode output: text, json, or stream-json.

none
Manifest プレイブック

Run Claude Code headlessly

Use print mode with bounded turns, structured output, and explicit permissions for scripts and CI.

  1. STEP 01 Start with a bounded text run claude -p --max-turns 8 "Review the current diff"

    Print mode writes the final response and exits.

  2. STEP 02 Request machine-readable output claude -p --output-format json --json-schema '{"type":"object"}' "Summarize the diff"

    JSON output and a schema make downstream parsing explicit.

  3. STEP 03 Grant only required tools claude -p --allowed-tools "Read" "Grep" "Bash(git diff *)" "Review this change"

    Narrow permission rules keep automation bounded.

08

CHAPTER / 08

証拠ラベルを読む

Root help にないフラグが使用不能とは限らず、docs にある機能も全 platform・plan で利用できるとは限りません。
runtime-confirmed インストール済み
docs-confirmed 公式 docs
conditional 条件付き
source-preview 公開 asset preview
historical 履歴のみ
運用原則
  1. 暗黙の設定より、明示的な scope を優先する。
  2. Transcripts、settings、credentials を別の状態領域として扱う。
  3. 無人実行前に、ロード済み tools と permissions を検証する。
  4. Runtime help と docs がずれる場合は source と availability を確認する。