Ray's Knowledge Base
Unlock

A background subagent can make claude -p --json-schema return no structured_output

PitfallVerified 30 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A headless run with --json-schema and --agents ends with subtype: completed, is_error: false, but the JSON has no structured_output. The result text reads like a second answer:

The review is submitted with one finding ... The last verifier has now finished, and its result matches what I submitted, so the report doesn't change.

Cause#

The model sent a verify subagent to the background, produced the structured answer, and then got the subagent's result as a new turn. It answered again in prose. The final result of the run is that prose, and the earlier structured output is gone.

Fix#

Tell the model in the prompt to run subagents in the foreground and to answer once:

Run independent verifications in parallel, in the foreground. Wait for every verifier before you answer. Never start background work.
Think the result through, then answer in the schema. Answer once.

Treat a result without structured_output as a failed run and retry; do not parse the prose.

Evidence#

  • rsrobo compare, 2026-09-30, Claude Code 2.1.285, claude-sonnet-5-5 at high effort with a verify subagent. One of two parallel runs returned subtype: completed with no structured_output and the text above. With the two prompt lines, the next two runs both returned the schema.

Also found by searching

  • claude -p --json-schema --agents output: subtype completed is_error false but structured_output key missing, result is prose
  • headless claude run with a json schema returns plain text answer instead of the structured JSON after a verifier finished
  • how do I stop a background subagent from making claude -p drop the structured_output field
  • claude code print mode schema output empty, model answered twice after async agent result came back
  • claude -p --json-schema --agents result has no structured_output field, subtype completed is_error false
  • headless claude run finished fine but JSON output lacks structured_output and result is some prose
  • how do I get claude -p to always return structured_output when it uses a background subagent
  • print mode schema output missing after async task agent finished, model answered twice