claude-code - 💡(How to fix) Fix AskUserQuestion auto-resolves with empty answers in headless/no-TTY mode (Python Agent SDK) [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#50728Fetched 2026-04-20 12:14:42
View on GitHub
Comments
2
Participants
3
Timeline
6
Reactions
0
Timeline (top)
labeled ×4commented ×2

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.

Root Cause

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.

Fix Action

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.

Code Example

User has answered your questions: . You can now continue with the user's answers in mind.

---

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"}
RAW_BUFFERClick to expand / collapse

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:

  1. Await the can_use_tool callback before resolving, allowing the integration to collect answers via its own UI and return them in updated_input
  2. Respect PreToolUse hooks that return continue_: False by 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

  1. Claude calls AskUserQuestion(questions=[...])
  2. The CLI detects no TTY is available
  3. The tool immediately resolves with empty answers — before any callback or hook can intervene
  4. 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/[email protected]
  • Running in Docker (no TTY attached)
  • Python 3.12

Related issues

  • #30983 — canUseTool callback 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 acceptEdits permission 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

extent analysis

TL;DR

To fix the issue of AskUserQuestion auto-resolving immediately with empty answers in headless environments, implement a PreToolUse hook that returns permissionDecision: "deny" and handle user input separately.

Guidance

  • Implement the provided pre_tool_use_hook function to prevent the tool from executing and allow for separate handling of user input.
  • Use a messaging system like PubSub to emit the question event and deliver the user's answer as a new prompt in a subsequent turn.
  • Be aware that this workaround loses the tool's conversational context, and the answer arrives as a fresh prompt rather than a tool result.
  • Review related issues (#30983, #29530, #47114, #29618, #16712, #34592, anthropics/claude-agent-sdk-python#327) for potential insights into the underlying problem.

Example

The provided pre_tool_use_hook function demonstrates how to return permissionDecision: "deny" and prevent the tool from executing:

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"}

Notes

The provided workaround is the only reliable solution mentioned in the issue, but it has limitations, such as losing conversational context. Further investigation into the related issues may be necessary to find a more comprehensive solution.

Recommendation

Apply the provided workaround by implementing the pre_tool_use_hook function, as it is the only known solution to prevent AskUserQuestion from auto-resolving with empty answers in headless environments.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

In headless/no-TTY environments, AskUserQuestion should either:

  1. Await the can_use_tool callback before resolving, allowing the integration to collect answers via its own UI and return them in updated_input
  2. Respect PreToolUse hooks that return continue_: False by 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.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING