CCA-F start here · Trap gym · Prompt or hook?

Prompt or hook?

This is the exam's most common trap. A rule that must hold every time comes with answers that make the prompt clearer. A nice-to-have comes with answers that build code. Learn to tell the two apart, and a whole family of questions becomes easy.

D1 Agentic ArchitectureExam guide 1.4 and 1.5About 15 minutes

At a glance: A rule that must hold every time, like verifying identity before a refund, goes in a hook or gate; a preference can stay in the prompt.

Start here: the cashier and the till

A shop has two ways to make its cashiers behave.

Tell them. A note by the till says “offer the loyalty card”, and the manager shows them how once. Most cashiers do it most of the time. If one forgets now and then, nothing bad happens.
Build it into the till. The till won't open for a refund over $150 without a manager's key. It works every time, but someone had to build it, test it and maintain it.

Claude works the same way. A prompt (instructions, plus a few example chats) is the note by the till: followed most of the time, cheap to change. A hook is code that runs every time Claude calls a tool. It is the till that won't open.

System prompt + examples followed most of the time Claude decides what to say and call PreToolUse hook checks the call first Tool e.g. process_refund PostToolUse hook edits the result first call result
The one question to ask: if this goes wrong once, is that acceptable?

Words in the question that tell you which side you're on

Prompt side

  • suggest, encourage, prefer
  • tone, style, wording
  • “a retention idea, not a business rule”
  • “most appropriate”, “simplest”: they ask for the right size, not the strongest

Code side

  • must, never, every time, stop completely
  • money, refunds, identity, security, compliance
  • “a prompt already says so, yet…”
  • “guarantee”, “deterministic”

Try it: run 1,000 chats

Pick a behaviour, then pick how you'd make Claude follow it. The simulator replays 1,000 chats where the behaviour matters, and the diagram above shows where your choice acts.

1. The behaviour
2. How you make it happen
followedmissedwrongly blockednot possible

The rates are illustrative, chosen to show the shape. They are not measurements. The exam guide's point is that prompt instructions have a non-zero failure rate, while hooks are deterministic for what they can see: tool calls and tool results.

Things to try: refund + prompt, then refund + PreToolUse. Then pause + PreToolUse to see the trap in reverse. Last, card number + PreToolUse, the right family but the wrong hook.

The three traps

TrapWhat the wrong option looks likeWhy it's wrong
Prompt where code was needed“Move the rule to the top of the prompt”, “add examples”, “state it in capitals”, for a money, security or must-never rulePrompts are followed most of the time. A rule that must hold every time needs code.
Code where a prompt was enoughA hook, classifier or new subagent for a suggestion or a toneOverbuilt. More to build and maintain, and it can block real users when it misreads.
Right family, wrong hookPostToolUse to stop an action; PreToolUse to hide data; a hook that only logsPreToolUse acts on the call, before it runs. PostToolUse acts on the result, before Claude reads it. Logging prevents nothing.

“But as an architect, it depends”

Take the retention feature from practice question 1: before a cancelling customer is handed to a person, the agent suggests pausing the subscription. In real life the right design does depend on the requirement. The exam removes the “it depends” by stating the requirement in the question. Your job is to find that sentence and build exactly what it asks for, not the system you would design if you owned the product.

If the question says…Best answerA retention subagent?
It's a nice-to-have; the agent doesn't have to do it in every chatA system-prompt instruction plus two example chatsNo. Overbuilt: a handoff and a second prompt for one sentence of behaviour.
Only some customers may be offered a pause, under rules finance setsA tool such as get_retention_offer(customer_id) that checks the policy in code, plus a prompt line saying when to call it and how to word the offerNo. A subagent is still a model deciding who is eligible. A policy belongs in code or data.
A pause must be offered before every cancellation (a compliance rule)A PreToolUse hook that blocks escalate_to_human until the offer is recordedNo. A subagent can't guarantee it either.
Retention is a long negotiation with its own tools, offers and historyA retention subagentYes. Now the separate context and focused prompt earn their cost.
Policy-driven doesn't mean subagent. If “who gets the offer” must follow a policy, put the policy where it can't be guessed: in code, behind a tool. Code decides who; the model decides how to say it. A subagent adds a second model, not certainty.

On the exam, the most appropriate answer is the smallest mechanism that fully meets the stated requirement. An option that meets a requirement the question never gave is the “overbuilt” trap, however good the design.

Tool A must run before tool B: every way, and which one wins

Many questions come down to one shape: the agent must call A (verify the customer, preview a removal, search for a connector) before B (refund, remove, call the connector), and it sometimes skips A. There are eight ways to enforce it. Questions with the same shape can have different answers because they give different options and stress different words.

#WayHow it worksWhat it guarantees
1System prompt instruction“Always call A before B”Nothing. Followed most of the time, not every time.
2Tool description and few-shot examplesThe same request, written into each tool's descriptionNothing. It raises the rate but never makes it certain.
3Merge A and B into one toolA single tool does A and then BThe order, but the model can no longer check between the steps (the find_and_execute trap).
4Hide B until A has runA dynamic tool list: B appears only after AThe order. The answer when there are too many tools and the agent calls tools it never searched for.
5PreToolUse hook in the host or Agent SDKCode checks that A has run in this session before allowing B, and blocks B otherwiseThe order, but only inside that host.
6Server remembers recent callsFor example, “allow B only if a matching A ran in the last 60 seconds”The order, but fragile: a slow user misses the window, and one A can be reused within it.
7A returns a token that B requiresB's own input needs something only A can produce, valid once and only for that actionThe order and the exact data, whoever calls the tool.
8Fixed workflow codeYour code calls A and then B, and the model doesn't chooseEverything, but the model has no flexibility. Right when the steps never change.
+Human approval gateThe host asks the user before B runsA person's sign-off. Combine it with 5 or 7, because on its own the user may approve without ever seeing A's result.

How to pick: read the question for these clues

If the question…Best answer
Says the agent sometimes skips A, and the options are prompts, examples and one hook or programmatic checkThe hook (5). It's the only option enforced in code.
Is about the Claude Agent SDK or Claude Code, or about a policy such as “verify identity before any refund”The hook (5).
Is about designing the tool itself (your MCP server, its parameters), or says B must be tied to that specific AThe token (7).
Says the user must explicitly confirmA host approval gate on top of 5 or 7.
Has too many tools, and the agent calls tools it never searched forHide B until A has run (4).
Describes steps that are always the same and need no judgmentFixed workflow code (8).

Worked example: why it's the token here and not the hook

“Your remove_team_member tool has a dry_run parameter. The agent skips the preview in 15% of calls. You need every removal to be preceded by a preview the user explicitly confirms.” The options were: (A) allow dry_run=false only if a matching preview ran in the last 60 seconds; (B) two tools, where the preview returns a single-use token that execute requires; (C) mark the tool as needing confirmation and have the host ask the user; (D) better instructions and examples.

OptionEnforced in code?Tied to the exact preview?Robust?Verdict
B. Single-use tokenYesYesYesPick. The only way to get a token is to run the preview.
A. 60-second windowYesPartlyNoWorks, but fragile: it depends on timing, and one preview can be reused.
C. Host asks for approvalYesNoPartlyWorks, but the user approves a call without ever seeing a preview. MCP tool annotations are only hints.
D. Better instructionsNoNoNoOnly usually works. The agent already skips the preview 15% of the time.

Why not a PreToolUse hook? It wasn't one of the options, and it would be weaker here for three reasons. A hook sees one call at a time, so to know a preview happened it would have to rebuild option A or B inside itself. It only runs in one host, while the tool may be called from any client. And “never remove without a preview” is a business rule that belongs inside the tool. The hook is still useful alongside the token, as the place where the user approves: the token proves a preview happened, and the approval proves a person said yes.

Same principle, different winner. Both questions test one idea: a rule that must always hold goes in code, never only in the prompt. When the options offer one code-enforced mechanism, pick it. When they offer several, pick the one whose scope matches the question's wording: the hook for the agent's host or a policy, the token for the tool's own design or one exact action.

To choose, work through three steps. First, drop anything that is only a prompt when the question says “every” or “always”. Second, drop fragile fixes such as timers, time windows and hints that the host may ignore. Third, choose among what's left using the clue table above.

Practice: three exam-style questions

Answer first, then open “Think it through”.

Rule to remember

Must hold every time → code. Nice to have → prompt and examples. Stop an action with PreToolUse; hide data with PostToolUse.

Exam guide 1.4: “When deterministic compliance is required (e.g., identity verification before financial ops), prompt instructions have a non-zero failure rate.” Exam guide 1.5: “Hooks give deterministic guarantees vs prompt-based probabilistic compliance.”

← All traps