[Bug] StructuredOutput tool doesn't stop agent execution - agent continues after calling it

Resolved 💬 3 comments Opened Jan 9, 2026 by guyskk Closed Feb 23, 2026

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:

  1. Call the StructuredOutput tool with the validated JSON
  2. Immediately stop execution - no more tool calls or text messages
  3. Return the result in the ResultMessage.StructuredOutput field

Actual Behavior

The agent:

  1. Calls the StructuredOutput tool successfully
  2. Receives "Structured output provided successfully" response
  3. Continues execution by:
  • Sending text messages like "好的,我明白了。让我立即开始实现这个 2048 游戏"
  • Calling TodoWrite tool
  • Calling Bash tool
  • 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:

  1. Enable structured outputs with --json-schema parameter
  2. Send a prompt requesting a structured decision (completed/feedback)
  3. Agent calls StructuredOutput tool with the result
  4. 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:

  1. A text message
  2. TodoWrite tool call
  3. Bash tool 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:

  1. Current behavior: --json-schema creates a StructuredOutput tool that the agent can call, but doesn't enforce termination
  2. Expected behavior: --json-schema should 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗