[Bug] StructuredOutput tool doesn't stop agent execution - agent continues after calling it
Bug Report
Summary
When using --json-schema parameter for structured outputs, the agent calls the StructuredOutput tool but continues execution instead of stopping. The agent should terminate immediately after calling the StructuredOutput tool, but instead it proceeds to call other tools (TodoWrite, Bash, etc.) and send additional text messages.
Expected Behavior
When structured outputs are enabled via --json-schema, the agent should:
- Call the
StructuredOutputtool with the validated JSON - Immediately stop execution - no more tool calls or text messages
- Return the result in the
ResultMessage.StructuredOutputfield
Actual Behavior
The agent:
- Calls the
StructuredOutputtool successfully - Receives "Structured output provided successfully" response
- Continues execution by:
- Sending text messages like "好的,我明白了。让我立即开始实现这个 2048 游戏"
- Calling
TodoWritetool - Calling
Bashtool - Calling other tools
Reproduction Steps
This issue was discovered when using a supervisor hook with the Claude Agent SDK for Go. The supervisor uses structured outputs to get a decision from the AI:
- Enable structured outputs with
--json-schemaparameter - Send a prompt requesting a structured decision (completed/feedback)
- Agent calls
StructuredOutputtool with the result - Agent continues executing instead of stopping
Debug Log
[2026-01-09T23:27:17.535Z] [DEBUG] raw message supervisor_id=6c3fcab1-782a-42e8-9d5d-ec3febe4a57b json={"type":"assistant","content":[{"type":"tool_use","id":"call_e253783f1b2b40ac8beeb8f1","name":"StructuredOutput","input":{"completed":false,"feedback":"当前还未开始任何实际工作,仅停留在规划阶段..."}}]}
[2026-01-09T23:27:17.554Z] [DEBUG] raw message ... json={"type":"user","content":[{"type":"tool_result","tool_use_id":"call_e253783f1b2b40ac8beeb8f1","content":"Structured output provided successfully"}]}
[2026-01-09T23:27:33.974Z] [DEBUG] raw message ... json={"type":"assistant","content":[{"type":"text","text":"好的,我明白了。让我立即开始实现这个 2048 游戏,不做无谓的等待和确认。"}]}
[2026-01-09T23:27:33.977Z] [DEBUG] raw message ... json={"type":"assistant","content":[{"type":"tool_use","id":"call_13f3f39584684e5ba60292b9","name":"TodoWrite","input":{...}}]}
[2026-01-09T23:27:35.605Z] [DEBUG] raw message ... json={"type":"assistant","content":[{"type":"tool_use","id":"call_01bf48776744400e9378668c","name":"Bash","input":{"command":"go mod init..."}}]}
Note how after the StructuredOutput tool call returns successfully, the agent continues with:
- A text message
TodoWritetool callBashtool call
Environment
- CLI: claude-code (latest)
- Model: glm-4.7 (custom API endpoint)
- SDK: claude-agent-sdk-go v0.5.1
- Context: Supervisor hook using structured outputs
Analysis
This appears to be a fundamental issue with how the --json-schema parameter is implemented:
- Current behavior:
--json-schemacreates aStructuredOutputtool that the agent can call, but doesn't enforce termination - Expected behavior:
--json-schemashould constrain the final response format and terminate immediately after the structured output is provided
The difference is subtle but critical:
- Tool approach (current): Agent calls StructuredOutput tool → gets result → continues working
- Response constraint approach (expected): Agent's final response must match schema → terminates
Related
- Documentation: https://platform.claude.com/docs/en/agent-sdk/structured-outputs
- Python SDK reference implementation shows expected behavior where StructuredOutput terminates the session
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗