[FEATURE] Allow providing tool_result via stdin when resuming session with pending tool_use

Open 💬 4 comments Opened Jan 7, 2026 by cheruvian

Description

When building wrappers around Claude Code CLI (mobile apps, custom UIs, etc.) that need to handle interactive tools like AskUserQuestion in non-interactive mode, there's no way to provide a tool_result via stdin without the CLI first injecting a synthetic response.

Current Behavior

When resuming a session that ends with a tool_use (e.g., AskUserQuestion) using --input-format stream-json:

  1. Session ends with: [user] prompt[assistant] tool_use
  2. Resume with: claude --resume <id> --input-format stream-json --output-format stream-json
  3. CLI immediately injects: [assistant] "No response requested."
  4. Then reads stdin: [user] tool_result
  5. API rejects: unexpected tool_use_id found in tool_result blocks

The chain is broken because the synthetic message is inserted between tool_use and tool_result.

Expected Behavior

When resuming with --input-format stream-json, the CLI should:

  • Wait for stdin input before injecting any synthetic messages
  • OR provide a flag like --no-synthetic-response to disable the injection
  • OR recognize that a tool_result message on stdin corresponds to the pending tool_use

Use Case

Building a mobile/web wrapper for Claude Code that:

  1. Runs CLI in non-interactive mode (-p, --output-format stream-json)
  2. Detects AskUserQuestion tool calls
  3. Renders custom UI to collect user's answer
  4. Needs to provide the tool_result back to continue the session

Current Workaround

The only working approach is to:

  1. Write the tool_result directly to the session JSONL file (~/.claude/projects/.../<session>.jsonl)
  2. Resume with a text prompt

This works but:

  • Requires manipulating internal session files (fragile)
  • Still results in an extra user turn and "No response requested" message

Reproduction

# 1. Start session, get AskUserQuestion, kill process
claude -p "Use AskUserQuestion to ask about my favorite color" \
  --output-format stream-json --verbose \
  --session-id test-123
# Kill when tool_use appears

# 2. Try to resume with tool_result via stdin
echo '{"type":"user","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_xxx","content":"Blue","is_error":false}]}}' | \
claude --resume test-123 \
  --input-format stream-json \
  --output-format stream-json --verbose

# Result: API error due to "No response requested" being injected first

Environment

  • Platform: macOS
  • Version: 2.0.76

View original on GitHub ↗

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