AskUserQuestion auto-resolves with empty answers in headless/no-TTY mode (Python Agent SDK)
Description
When using the Python Agent SDK (claude-agent-sdk) in a headless/no-TTY environment (e.g., Docker container, CI, server-side automation), AskUserQuestion auto-resolves immediately with empty answers:
User has answered your questions: . You can now continue with the user's answers in mind.
The tool completes in ~37ms without any opportunity for the integration to collect answers from the user, even when a can_use_tool callback or PreToolUse hook is registered.
Expected behavior
In headless/no-TTY environments, AskUserQuestion should either:
- Await the
can_use_toolcallback before resolving, allowing the integration to collect answers via its own UI and return them inupdated_input - Respect
PreToolUsehooks that returncontinue_: Falseby not executing the tool at all (currently the tool executes before the stop signal takes effect)
The Agent SDK docs describe option 1 as the intended flow, but it doesn't work in practice.
Actual behavior
- Claude calls
AskUserQuestion(questions=[...]) - The CLI detects no TTY is available
- The tool immediately resolves with empty answers — before any callback or hook can intervene
- Claude continues with the empty answers as if the user responded
Workaround
The only reliable workaround is returning permissionDecision: "deny" from a PreToolUse hook, which prevents the tool from executing entirely. The question event can be emitted separately (e.g., via PubSub), and the user's answer is delivered as a new prompt in a subsequent turn.
async def pre_tool_use_hook(self, input, tool_use_id, context):
if input and input.get("tool_name") == "AskUserQuestion":
return {
"continue_": False,
"stopReason": "Waiting for user to answer the question.",
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": "Questions sent to user. Waiting for response.",
},
}
return {"hookEventName": "PreToolUse"}
This works but loses the tool's conversational context — the answer arrives as a fresh prompt rather than a tool result, so Claude doesn't always associate it with the original question.
Environment
claude-agent-sdk==0.1.63(Python)- Bundled CLI:
@anthropic-ai/claude-code@2.1.114 - Running in Docker (no TTY attached)
- Python 3.12
Related issues
- #30983 —
canUseToolcallback never awaited (closed as not planned) - #29530 — Empty response without rendering UI
- #47114 — v2.1.104 regression, auto-resolves even in interactive CLI
- #29618 — Auto-resolves under
acceptEditspermission mode - #16712 — No way to provide answers via stdin when resuming a session
- #34592 — Unavailable in sub-agent contexts
- anthropics/claude-agent-sdk-python#327 — Can't trigger AskUserQuestion in Python SDK
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗