Learn Claude Code
0 から 1 へ nano Claude Code-like agent を構築し、毎回 1 つの仕組みを追加
コアパターン
すべての AI コーディングエージェントは同じループを共有する:モデルを呼び出し、ツールを実行し、結果を返す。実運用ではこの上にポリシー、権限、ライフサイクル層が重なる。
while True:
response = client.messages.create(messages=messages, tools=tools)
if response.stop_reason != "tool_use":
break
for tool_call in response.content:
result = execute_tool(tool_call.name, tool_call.input)
messages.append(result)メッセージの増加
エージェントループ実行時のメッセージ配列の成長を観察
学習パス
12の段階的セッション、シンプルなループから分離された自律実行まで
The Agent Loop
The minimal agent kernel is a while loop + one tool
Tools
The loop stays the same; new tools register into the dispatch map
TodoWrite
An agent without a plan drifts; list the steps first, then execute
Subagents
Subagents use independent messages[], keeping the main conversation clean
Skills
Inject knowledge via tool_result when needed, not upfront in the system prompt
Compact
Context will fill up; three-layer compression strategy enables infinite sessions
Tasks
A file-based task graph with ordering, parallelism, and dependencies -- the coordination backbone for multi-agent work
Background Tasks
Run slow operations in the background; the agent keeps thinking ahead
Agent Teams
When one agent can't finish, delegate to persistent teammates via async mailboxes
Team Protocols
One request-response pattern drives all team negotiation
Autonomous Agents
Teammates scan the board and claim tasks themselves; no need for the lead to assign each one
Worktree + Task Isolation
Each works in its own directory; tasks manage goals, worktrees manage directories, bound by ID
アーキテクチャ層
5つの直交する関心事が完全なエージェントを構成