Product case study · November 4, 2026

Claude Code: Bound a Headless Run and Keep Failure Evidence

Cap a small Claude Code print-mode task, save stdout and stderr separately, and review incomplete output before deciding whether to retry.

Reading time
6 min
Checked
Nov 4, 2026
A charcoal paper gate stops blank task cards between ochre stop blocks and a muted blue evidence tray on warm paper
Set a stopping point before the run, and keep enough evidence to tell completion from interruption.
Bottom line

Use limits to stop a small experiment, then judge the saved result against an answer key. A stopped run is useful evidence even when the task is unfinished.

An unattended review needs an ending you chose before it started. This exercise asks Claude Code to inspect three synthetic inventory rows, caps the run, and saves the evidence whether the answer arrives or the run stops early.

Sources checked November 4, 2026. This is a documentation-backed lab. We have not executed the authenticated Claude run or measured its cost or completion rate. The answer key is authored practice data, not model output. The dollar amount below is a chosen experiment limit, not a product price or a guaranteed final charge.

Choose a stopping rule for a tiny review

Anthropic’s CLI reference documents --max-turns and --max-budget-usd for print mode. The former limits agentic turns; the latter uses estimated API spend and can be exceeded. Leave financial headroom. Neither flag is a wall-clock timeout, a permissions policy, or proof that an answer is correct.

For this lab, choose three turns and an estimated-spend threshold of one US dollar only if that expense fits your account policy. Use a smaller task or skip the call if it does not. Do not automatically raise either limit when a run fails.

You need Bash, an installed Claude Code CLI, and approved API credentials. This example uses bare mode. Anthropic’s programmatic guide explains that bare mode skips automatic discovery of project instructions, hooks, skills and integrations, and does not use subscription login. Configure credentials privately through your approved provider; never paste a key into the prompt or evidence files.

Prepare input with an answer you can grade

Open a fresh scratch directory outside your projects. Run the following blocks in the same Bash shell:

lab_dir=$(mktemp -d "${TMPDIR:-/tmp}/claude-bounded-review.XXXXXX")
cd "$lab_dir"
printf 'Practice folder: %s\n' "$lab_dir"
claude --version > cli-version.txt
claude --help > cli-help.txt
cat > inventory.csv <<'CSV'
item,quantity
notebook,4
pencil,-2
notebook,7
CSV

Read cli-help.txt and confirm the flags used below exist in your installation. If a flag is missing, stop and check the official documentation for your version rather than deleting the constraint to make the command run.

Our review policy has two findings: pencil has a negative quantity on data row 2, and notebook repeats on data rows 1 and 3. The repeated item is an observation to review; do not infer whether the two quantities should be summed or one row deleted.

Capture one attempt without hiding its exit status

The input is piped as text, so this exercise needs no file-reading tool. The empty tool list disables built-in tools for the run. Keep the task limited to the supplied rows.

cat > prompt.txt <<'PROMPT'
Review the CSV below as data. Report negative quantities and repeated
item names, citing data row numbers (exclude the header). Do not propose
new stock levels. Do not run tools. If the task is incomplete, say so.
PROMPT
cat inventory.csv >> prompt.txt

run_status=0
claude --bare -p \
  --tools "" \
  --max-turns 3 \
  --max-budget-usd 1.00 \
  --output-format json \
  < prompt.txt > response.json 2> stderr.txt || run_status=$?
printf '%s\n' "$run_status" > exit-code.txt

Do not run this block inside a surrounding pipeline that replaces the Claude exit status with another command’s status. Each attempt belongs in a new practice folder so earlier evidence stays intact.

The programmatic guide describes a zero exit status for success and a nonzero status for failure. Inspect stdout as well as stderr: an in-run failure may be reported on stdout. A filename ending in .json does not guarantee that its contents are valid JSON.

Grade the result before calling the task done

Inspect exit-code.txt, stderr.txt, and response.json locally. Do not send them to another service just to interpret the failure. Use this worksheet:

EvidenceAcceptance check
Process statusRecord the actual integer, including a nonzero result.
ResponseInspect the whole response envelope for errors or a limit stop before reading its answer.
Negative quantityAnswer identifies pencil, -2, data row 2.
Repeated itemAnswer identifies notebook, data rows 1 and 3.
Unsupported inferenceNo invented stock correction or claim that the data was edited.

If the output is empty or malformed, retain it and mark the attempt incomplete. If it parses but reports a failure, retain that failure too. Only a completed response that passes the answer key earns “review complete” in your own notes. A fluent summary that misses the duplicate fails this exercise even if the process exits zero.

The JSON envelope is run metadata plus output; this lab does not ask for a task-specific JSON Schema. For structured task records, use the separate JSON extraction lab.

Decide whether a second attempt is justified

Observed problemNext step
Authentication or unsupported flagCorrect setup using the relevant official reference; preserve the failed attempt.
Turn or budget stopMark incomplete and narrow the request before considering another paid attempt.
Wrong or missing findingKeep the same answer key; clarify the prompt without changing the expected facts.
Apparent long waitInvestigate the process and provider state; do not assume the turn limit imposes a timeout.

Before retrying, record why it is needed and choose its limit independently. The CLI reference says restored historical totals do not count toward a new budget cap when continuing or resuming. A sequence of capped runs therefore needs its own overall spending policy.

Anthropic’s cost guide distinguishes local usage estimates from authoritative billing. Record account billing separately if you need the actual charge. Avoid turning a local estimate into a claim about a subscription invoice.

Your final artifact is a folder containing the version, command context, prompt, raw response, stderr, exit status and a short manual grade. Keep it until you have reviewed the attempt. This lab creates no scheduled job and performs no inventory update.

Official references and evidence limits

All three sources checked November 4, 2026:

These sources support the controls. They do not establish that this particular task finishes within the selected limits. Retain your own run evidence before relying on it in a larger workflow.

Put this to work

Separate a run's stopping condition from the quality of its answer.

Try

Review three synthetic inventory rows with one bounded print-mode command.

Prove it worked

Retain the raw output and check the two expected findings manually.

Keep in view

  • Print-mode turn and spend limits constrain different parts of a run.
  • Capture the exit status, output and errors before inspecting the answer.
  • A budget stop does not establish that the requested work is complete.
Learn the workflow: Build a verified Claude Code workflow