From c7aa9072a9b7f63d2221b1fbc4465e1c970b5604 Mon Sep 17 00:00:00 2001 From: quick-sort Date: Fri, 12 Jun 2026 09:46:42 +0000 Subject: [PATCH] fix: correct tool_result message format for AskUserQuestion When Claude Code calls AskUserQuestion, the agent pauses and waits for the user's reply, then sends it back as a tool_result. The message was using `parent_tool_use_id: tool_use_id`, but every other user message in the SDK (initial prompt, client.query()) uses `parent_tool_use_id: null`. This mismatch caused the CLI to misroute the tool_result, so the LLM never received the user's answer and re-asked the same question. Also fix session_id fallback: use "" (matching the SDK's initial-message format) instead of "default", and use `or ""` instead of `.get(key, "")` so that an explicit None value is also replaced by the empty string. Co-Authored-By: Claude Sonnet 4.6 --- src/agent_box/agents/claude_code.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/agent_box/agents/claude_code.py b/src/agent_box/agents/claude_code.py index 1ff056e..b9c66c9 100644 --- a/src/agent_box/agents/claude_code.py +++ b/src/agent_box/agents/claude_code.py @@ -407,8 +407,8 @@ async def _send_tool_result( } ], }, - "parent_tool_use_id": tool_use_id, - "session_id": session_id or "default", + "parent_tool_use_id": None, + "session_id": session_id or "", } # Use the transport directly — ``client.query()`` only sends plain # text user messages, but we need to attach a tool_result payload. @@ -439,7 +439,7 @@ async def run(self, prompt: str, user_id: str = "", channel: str = "") -> AsyncI client, tool_use_id=ask["tool_use_id"], answer=prompt, - session_id=ask.get("session_id", ""), + session_id=ask.get("session_id") or "", ) else: await client.query(prompt)