til/applied-sciences/engineering/claude-agents-spec
claude-agents-spec.mdupdated 2026-07-163479 words
ダブルクリックで英日反転
Applied Sciences · Engineering

Claude Code Agent Layers: A Clear Breakdown

EN

Claude Code ships five distinct "agent-ish" primitives. Conflating them makes orchestration impossible; each has a precise role and the right one depends on what you actually need.

The Five Layers

  • Slash command — text expansion + permissions, triggered by typing `/foo`
  • Skill — a how-to document auto-injected when its description matches a condition
  • Sub-agent — an independent LLM call in a separate context window, spawned via the Task tool
  • Hook — a shell script bound to tool events (PreToolUse / PostToolUse / Stop / SessionStart)
  • MCP server — exposes an external API as a tool, connected at session start

What Makes a Sub-Agent Special

  • Runs in a completely separate context window — cannot see the parent's history
  • Returns a single message; the parent only sees that result
  • Multiple sub-agents can be launched in parallel within one message
  • "worktree" flag also creates a git worktree for physical file isolation

Skill vs Sub-Agent vs Hook

  • Skill: injects a procedure into context — no code runs, no separate LLM call
  • Sub-agent: actually does work in its own LLM call, for heavy or parallel tasks
  • Hook: pure shell, not an LLM — rules that need certainty belong here

Open Questions

  • Cost of deep sub-agent nesting grows exponentially — budget carefully
  • Skill auto-triggering accuracy depends entirely on description quality
  • Boundary between Hook and Skill (auto-commit = Hook; auto-review = Skill for now)
  • Background job ≠ sub-agent: a bg job shares the parent's context; a sub-agent does not
Map each need to the right primitive: sub-agent for parallel/isolated work, Skill for reusable procedures, Slash command for fixed wording, Hook for tool-call automation, MCP for external APIs.
応用科学 · エンジニアリング

Claude Code エージェント層の​整理

JP

Claude Code には​5種類の​「エージェント的」​プリミティブ​(=基本構成要素)が​ある。​混同すると​ orchestration​(=複数エージェントの​協調制御)の​設計が​破綻する​ため、​それぞれの​役割を​明確に​区別する。

5つの​層

  • Slash command — `/foo` と​入力して​起動する​テキスト展開+権限付与
  • Skill — 説明文が​条件に​一致した​とき、​手順書を​コンテキストへ​自動注入
  • Sub-agent — Task ツールで​起動する​独立 LLM 呼び出し。​別コンテキストウィンドウで​動く
  • Hook — ツールイベント​(PreToolUse / PostToolUse / Stop 等)に​紐づく​シェルスクリプト
  • MCP サーバー — 外部​ API を​ツールと​して​公開し、​セッション開始時に​接続

Sub-agent の​特徴

  • 完全に​独立した​コンテキストウィンドウで​動作し、​親の​会話履歴を​参照できない
  • 返り値は​単一メッセージのみ。​親が​見るのは​その​結果だけ
  • 1つの​メッセージ内で​複数の​ sub-agent を​並列起動できる
  • "worktree" 指定で​git worktreeも​自動作成し、​ファイル編集を​物理的に​分離可能

Skill / Sub-agent / Hook の​違い

  • Skill: 手順を​コンテキストへ注入するだけ。​コードを​実行せず、​LLM 呼び出しも​起きない
  • Sub-agent: 独自の​ LLM 呼び出しで​実際の​作業を​行う。​重処理・並列処理向き
  • Hook: LLM でなく​純粋な​シェル。​確実性が​必要な​ルールは​ここに​置く

未解決の​課題

  • Sub-agent を​多段ネストすると​コストが​指数的に​膨らむ——予算管理が​重要
  • Skill の​自動起動精度は​説明文の​品質に​完全依​存
  • Hook と​ Skill の​責任境界​(現時点: 自動コミット=Hook、​自動レビュー=Skill)
  • バック​グラウンドジョブ ≠ sub-agent: bg job は​親の​コンテキストを​共有する
用途に​合った​プリミティブを​選ぶ: 並列・分離作業は​ sub-agent、​手順の​再利用は​ Skill、​定型文は​ Slash command、​ツール連動の​自動処理は​ Hook、​外部​ API は​ MCP。
148 notestil