A developer adds a Claude Code PreToolUse command hook that inspects Bash commands and must stop any that drop a database table. When the script detects one, it prints a warning and exits with code 1, yet the command still runs. What should the script do instead?
AExit with code 0 and print the warning to stdout instead of stderr.
BWrite the reason to stderr and exit with code 2 instead of code 1.
CKeep exit code 1 but register the script under PostToolUse instead.
DKeep exit code 1 and add a CLAUDE.md rule against dropping tables.
Show answer
Answer: B
Exit code 2 is the code that blocks the action. Claude Code treats exit 1 without valid JSON as a non-blocking error and lets the action proceed, unless the hook is set to block on its own failure, even though 1 is the usual Unix failure code. With exit 2 on PreToolUse, the tool call is blocked and the stderr text becomes the reason Claude sees, so it can adjust its approach. That makes the policy one of the deterministic actions hooks exist for, not a request the model may ignore. Moving the check until after the tool runs arrives too late to stop the drop.
A. Exit 0 reports no objection. For a PreToolUse hook it does not block or approve the call, so the normal permission flow applies and the command runs.
C. PostToolUse fires after a tool call succeeds, so the table is already gone, and exit 1 would remain a non-blocking error there too.
D. Exit 1 stays non-blocking, and a CLAUDE.md rule relies on the model choosing to comply, which is the gap hooks exist to close with deterministic control.
A hand-written client for the Messages API stream saves a reply whenever the connection closes without an exception. After a network proxy reset, truncated answers were stored as complete ones. Which check best fits to detect an incomplete stream?
AConfirm that a ping event arrived during the last minute of the stream.
BConfirm that a message_stop event arrived before the reply counts as complete.
CConfirm that the HTTP status of the response was 200 when it started.
DConfirm that the last event received was a content_block_stop event for the final block.
Show answer
Answer: B
A connection that drops in mid-stream gives no error event, and in some clients the stream simply ends. A normal stream always finishes with a message_stop event after the content blocks and message_delta events, so its absence marks the reply as incomplete. The client should treat a missing message_stop as a failure and not store the text. A ping, a 200 status or a block-level event does not show that the stream reached its end.
A. Ping events may be dispersed through a stream at any point, and they say only that the connection was alive at that moment. A ping arriving a few seconds before a proxy reset proves nothing about whether the reply finished.
C. A stream starts with a 200 status before the first event, even when it later fails or is cut. The status says the request was accepted, not that the reply completed, so a truncated answer still shows 200.
D. A content_block_stop closes one content block only. The stream still sends message_delta events and then message_stop, so a last event of content_block_stop can just as well mean a cut in the middle of a longer reply.
A developer resumes yesterday's Claude Code session, which holds about 300,000 tokens. She has an afternoon of small follow-up tasks that build on that session and wants the lowest cost per request, accepting that some older detail may drop. Which approach fits?
AResume it, then run /compact so later requests carry a summary of the history
BResume it and carry on, so every request re-sends the full 300,000-token history
CResume it, then run /clear so later requests start again from an empty context
DQuit and run claude --continue --fork-session to start a smaller copy instead
Show answer
Answer: A
This is a session management choice. Every Claude Code request sends the whole conversation, so a 300,000-token history is re-read on each of the afternoon's small requests. Running /compact replaces that history with a summary, optionally focused on what she specifies. From then on Claude continues with the summary, the messages compaction left unsummarized and every message since; the summarized messages aren't loaded again, so each request is cheaper, at the cost of any detail the summary drops, which she has accepted. Carrying on with the full session keeps every detail but pays for the whole history on every turn.
B. Carrying on with the full session keeps every detail, but every request sends the whole conversation, the opposite of the lowest cost per request she wants.
C. /clear starts fresh with an empty context, so it is cheap, but it drops the whole session her follow-up tasks build on. The guidance aims it at moving between unrelated tasks.
D. --fork-session only gives the resumed conversation a new session ID instead of reusing the original; the copy carries the same history, so each request costs the same.
A support-agent evaluation gives the same zero score to two attempts: one never identifies the customer, while another authenticates correctly and diagnoses the issue but fails to issue the refund. Product wants the evaluation to show progress without labeling either task fully completed. Which grading design best fits?
AMark both attempts successful because each produced a response.
BReport component-level partial credit while retaining the full-task completion requirement.
CDiscard the incomplete attempts from the evaluation dataset.
DGrade only the final apology’s tone and omit operational steps.
Show answer
Answer: B
Component scores can reveal meaningful improvement while preserving the distinction between progress and task completion. Give credit for correctly achieved stages, but keep the overall completion criterion tied to the required refund outcome. Anthropic recommends partial credit for tasks with multiple components so useful intermediate behavior is not conflated with immediate failure. Discarding incomplete attempts is the strongest distractor because it makes the measured cohort cleaner, but it removes precisely the evidence needed to understand remaining weaknesses. A partial score must not silently become a completed-task label.
A. Producing a response does not establish the requested operational outcome.
C. Removing failures biases the evidence and hides differences in incomplete performance.
D. Tone alone does not measure authentication, diagnosis or the required refund.
A platform lead sets Claude Code defaults for 120 engineers under a fixed monthly spend cap. Most work is everyday coding, a few tasks need deep architectural reasoning, and many subagent calls are simple file lookups. The lead is justifying the tiers chosen against the cap. Which tier policy fits best?
ARun every session and every subagent on Opus, so that no task is under-served by a smaller tier.
BRun everything on Haiku, since the spend cap is the binding constraint and quality can be fixed later.
CDefault to Sonnet, reserve Opus for architectural or multi-step reasoning, and set simple subagents to Haiku.
DLet each engineer pick Opus for all tasks and rely on the cap to stop spending at the limit.
Show answer
Answer: C
Matching tier to task is the defensible policy under a fixed cap. Sonnet handles most coding tasks and costs less than Opus, Opus is kept for the few architectural or multi-step jobs that need it, and simple subagents run on Haiku. The strongest distractor, Haiku for everything, saves the most per token but pushes the deep-reasoning tasks onto a tier the guidance reserves for simpler work. Opus everywhere or unlimited Opus choice spends the cap on tasks that do not need it.
A. Opus for every session and subagent spends the cap on lookups and routine edits that Sonnet and Haiku handle. The guidance says to reserve Opus for complex architectural or multi-step work, not to apply it everywhere.
B. Haiku everywhere cuts price but removes the capability the architectural tasks need. The guidance names Haiku for simple subagent tasks, not as a blanket default, and deferring the quality problem is not a justification.
D. Letting each engineer pick Opus for all tasks hands the budget decision to habit, and a cap only stops spending after the money is gone. A default tier policy controls cost before the limit is reached.
Domain 6: Prompt and Context Engineering · Select 2
A ticket-triage prompt passes 188 of 200 regression cases. The 12 misses are all sarcastic or mixed-sentiment tickets mislabelled neutral, and no case of that kind appears in the prompt. The team wants to close the gap and be sure nothing else regresses. Select the TWO steps that best fit.
AAdd three to five diverse examples covering sarcasm and mixed sentiment.
BDelete the 12 failing cases from the suite as outliers.
CReplace the prompt with a much longer one that lists every sentiment rule.
DLower the temperature to zero so that the borderline tickets stop varying.
ERe-run the full regression suite on the revised prompt before it ships.
Show answer
Answer: A, E
The misses share one cause: the prompt shows no sarcastic or mixed-sentiment tickets. A few diverse examples that cover those cases, tagged so Claude can tell them from instructions, address that gap directly, and re-running the full regression suite shows whether the revision fixed the 12 without breaking the 188. Deleting the failing cases hides the problem, a longer rule list leaves the same cases unshown, and temperature does not teach a label.
A. Diverse examples that cover the failing edge cases show Claude what sarcasm and mixed sentiment look like and how to label them, which is the missing information. Three to five is the recommended range.
B. Removing the failing cases makes the score rise while the behaviour stays wrong. The suite exists to expose these gaps, so deleting them loses the evidence instead of closing the gap.
C. A long rule list still gives Claude no sample of a sarcastic or mixed ticket. Examples are the reliable way to steer labelling, and more rules add length without covering the edge cases.
D. Temperature sets how random sampling is. It does not teach the model that sarcasm is negative, so a consistent mislabel would simply be repeated each time.
E. Each prompt change can fix some cases and break others. Re-running the full suite on the revised prompt is the first line of defence that shows whether the gap closed and nothing else regressed.
A research agent fetches web pages with a tool and can also send email on the user's behalf. The team wants pages carrying embedded instructions caught automatically and cheaply, before they can influence an agent that holds the email tool. Which design best fits?
APass raw pages through, and add a system prompt line saying web content may hold attacks.
BLet the main agent read each page and decide for itself whether it holds an injection.
CQueue every fetched page for a human reviewer before it is returned to the agent.
DClassify each page with Claude Haiku 5.5 under a JSON schema; return it only if clean.
Show answer
Answer: D
The design must screen before Claude acts, run cheaply and give code a verdict. Anthropic's guide applies the lightweight-model pattern to tool output: pass each raw result to a small classifier call with Claude Haiku 5.5 and return it as a tool_result only if the screen finds no injection attempt. Structured outputs make the verdict a parseable value to branch on, and a flagged page becomes an error or a stripped summary. The system prompt warning is the strongest distractor; stating the policy helps, but the page still reaches Claude unscreened.
A. Stating the policy in the system prompt is a sound extra layer, but the raw page still reaches Claude unscreened, which fails the requirement.
B. This screens nothing before Claude acts. The guide's pattern runs a separate small classifier on tool output first, so the main agent, which holds the email tool, never sees a flagged page.
C. A human queue is neither automatic nor cheap, and it returns no verdict the code can branch on, whereas the guide's screen is a small model call with a structured verdict.
A client-side harness dispatches tool calls for an app that also enables the web_fetch server tool. One response ends with stop_reason tool_use and holds a client tool_use block plus a server_tool_use block that has no result block yet. What should the harness send next?
AA tool_result for each block, including one the app writes for the server tool call.
BThe same request again, unchanged, treating the response as a pause_turn continuation.
CA user message with only the client tool_result blocks, keeping the same tools array.
DThe client tool_result followed by a text note asking Claude to finish the web fetch.
Show answer
Answer: C
When Claude calls a server-side tool and a client tool in the same parallel group, the API does not run the server tool; it returns so the harness can run the client tool first. The documented pattern is to reply with only the client tool_result blocks and the same tools array, after which the API runs the pending server call and the next response starts with its result. Adding a text note is the strongest distractor, but text after the results ends the turn early, and for a server tool Claude called directly the request fails with a 400 error.
A. Server tool calls do not take a tool_result from the application. The API runs the pending server call once the client results arrive.
B. The stop reason here is tool_use, not pause_turn, and the client tool still needs its result before the turn can continue.
D. In this state the user message must contain only tool_result blocks. Text after the results ends the turn early or causes a 400 error.
A team is building a multi-step approval workflow: some steps must run in a fixed, auditable order regardless of what the model decides, while other steps need the model to choose the next action dynamically. Which design best fits?
AA LangGraph graph whose nodes mix hand-coded steps with LLM-driven steps.
BA prompt chain with a router step that sends each request down one fixed branch.
CAn autonomous agent loop whose system prompt lists the steps that must stay in order.
DA LangChain prebuilt tool-calling agent with each fixed step exposed as a tool.
Show answer
Answer: A
The workflow needs two kinds of step in one design: fixed, auditable steps and model-chosen ones. LangGraph is a low-level orchestration framework that can mix deterministic, hand-coded steps with LLM-driven steps in the same graph, so the fixed parts run in code, predictably and auditably, while the flexible parts stay model-driven. An agent loop with the required order written into its prompt is the strongest distractor: it allows dynamic choices, but the model still directs its own process, so the fixed steps are not enforced.
B. Routing classifies an input once and directs it to a specialised follow-up; each branch is then fixed, so no later step lets the model choose its next action.
C. In an agent loop the model directs its own process and tool use. Steps listed in a prompt are still followed at the model's discretion, so their order is not hand-coded and predictable in the way the auditable steps require.
D. The LangGraph docs point to LangChain agents when you want a higher-level agent loop; in such a loop the model directs its own tool use, so exposing the fixed steps as tools does not enforce their order.
A documentation team uses Claude Code as a writing assistant. It wants every reply short and plain, with a note on why each edit was made. Engineers sharing the repository must be able to switch that behaviour off. Which setup best fits?
AAdd the reply-format rules to the repository's CLAUDE.md so every session loads them.
BSet an output style for the format, and let engineers pick another style.
CSave the format as a skill that Claude loads only when a task seems relevant.
DWrite a hook that rewrites each reply into the required format after Claude answers.
Show answer
Answer: B
The need is about the response itself: its length, its format and how much Claude explains, with an option to turn it off. That is the job of an output style, which is one active style at a time and can be switched whenever a user wants. The strongest distractor, CLAUDE.md, holds project facts and rules and is always loaded, so engineers could not switch the format off. A hook or a skill neither sets nor holds a response style.
A. CLAUDE.md carries what Claude should know about the project and is always loaded. Reply format kept there applies to every session, so engineers have no switch to turn it off, which the scenario requires.
C. A skill loads on demand, when invoked or when Claude judges it relevant, so the format would appear only on some tasks. The team wants it on every reply and switchable, not loaded by chance.
D. Hooks run scripts on lifecycle events and suit automation that must happen every time. They do not set how Claude writes its answer, and a post-hoc rewrite is a heavy way to get a style that a built-in setting supplies.