Foundations domain 1 · Agentic architecture and orchestration
The agentic loop and stop reasons
A loop sends a request, reads why the model stopped, and acts on that. The stop_reason is the signal. Don't parse the text to guess.
| stop_reason | Meaning | What to do |
|---|---|---|
end_turn | The model finished | Exit the loop |
tool_use | It wants a tool run | Run it, send the result back, loop again |
max_tokens | Output hit your limit and was cut off | Treat as unfinished. If it was cut off inside a tool call, the input is incomplete: don't execute it; retry with more room |
stop_sequence | One of your stop strings was produced | Check which one, then usually exit |
pause_turn | A long-running turn (such as server tools) was paused | Send the response back as it is to let it continue |
refusal | The model declined | Don't resend the same prompt unchanged |
model_context_window_exceeded | The context window filled up | Reduce or restructure what you send |
Exam guide vs todayStudy notes often list six stop reasons. Current docs have a seventh,
model_context_window_exceeded. On the newest models, a refused request can sometimes be served by retrying on a different Claude model. The exam guide itself names only tool_use and end_turn.Always pair the loop with a safety bound, such as a maximum number of iterations or a budget, and make hitting it a visible outcome, not a silent stop.
Tool results and parallel calls
- Tool results go back in a user-role message. "User" is the side of the conversation that isn't the model; no human has to be involved.
- When the model requests several tools in one response, return all results in one user message, one
tool_resultblock per call, matched bytool_use_id. Thetool_resultblocks come before any text. - A failed call still gets a result: a
tool_resultwithis_error: trueand a useful message. An unanswered call is a malformed conversation.
Hooks: deterministic enforcement
- PreToolUse runs before a tool and can block it. PostToolUse runs after, so it can't prevent anything. It can inspect, normalise or replace the output, or add context.
- Exit codes: 0 success; 2 blocking error (for PreToolUse, the call is blocked and stderr goes back to Claude); any other non-zero code is a non-blocking error and the call proceeds. If a hook prints valid JSON, the JSON decision is used.
- The principle behind the facts: prompts are probabilistic, hooks and permissions are not. "Must never", "zero tolerance", "regulatory", or "a prompt rule already failed" point to a hook or permission.
Exam guide vs todayOlder notes list nine hook events: SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Notification, Stop, SubagentStop, PreCompact, SessionEnd. Those are still the core, but Claude Code now has more than thirty. Examples include PermissionRequest, PostToolUseFailure, SubagentStart, PostCompact and InstructionsLoaded.
Subagents and coordination
- A subagent starts without the coordinator's conversation. Everything it needs has to be in its prompt: the goal, the inputs, what a good answer looks like and the output format. (A fork is the exception: it inherits the whole conversation.)
- Give each subagent only the tools its role needs. A subagent defined without a tools list inherits all of them.
- Claude decides when to delegate to a subagent from its description, so a vague description means it isn't used.
- Hub-and-spoke: subagents report to the coordinator, which owns delegation, keeps it bounded, and synthesises. Independent subtasks can run in parallel.
- Open-ended investigation needs adaptive decomposition: plan, then revise as findings come in. Fixed, repeated processes suit a fixed workflow.
See also: Professional domain 1 · Multi-agent systems and decomposition.
Sessions
claude --continueresumes the most recent conversation in this directory.claude --resumelets you pick one.- Forking a session copies its history into a new session to try an alternative. Forks don't merge back.
- If much of a session's earlier tool output is stale, start a fresh session with a structured summary instead of resuming.
See also: Exam guide vs today · Foundations (CCAR-F).
Docs: Stop reasonsHandling tool callsParallel tool useHooksSubagentsSessions
Practise Domain 1