Agent hangs indefinitely mid-task — no recovery path without Esc (blocks remote/headless use)

Resolved 💬 4 comments Opened Feb 25, 2026 by james-b-kelly Closed Mar 25, 2026

Description

Claude Code frequently hangs indefinitely mid-task — it stops producing output and makes no further tool calls, but doesn't return control to the user. The session appears stuck with no timeout or automatic recovery.

In an interactive terminal, the workaround is to press Esc to interrupt the agent and re-prompt. But this makes remote control / headless use non-viable, since there is no equivalent of pressing Esc programmatically or via the SDK.

Steps to Reproduce

No single reliable repro — the hang occurs intermittently across a variety of tasks (file edits, multi-step agentic workflows, tool calls). It seems more common during:

  • Multi-turn agentic loops (Task tool / subagents)
  • After a tool call returns a large result
  • During complex reasoning before a tool call

Expected Behavior

  • The agent should always either produce output, make a tool call, or return control within a reasonable timeout.
  • If the agent detects it is stuck or an API call has stalled, it should automatically recover (retry, surface an error, or yield control).
  • For headless/remote use, there should be a programmatic equivalent of Esc (e.g., a signal, API call, or SDK method to interrupt a hung turn).

Actual Behavior

  • The agent silently hangs. No output, no tool calls, no error.
  • The only recovery is pressing Esc in an interactive terminal.
  • In remote control / SDK-driven sessions, the hang is unrecoverable — the session is effectively dead until manually killed.

Impact

This is a blocking issue for remote control and automation use cases:

  • Unattended CI/CD workflows using Claude Code
  • Remote control via the SDK (no physical keyboard to press Esc)
  • Long-running agentic tasks left to run overnight
  • Any scenario where a human isn't actively watching the terminal

Suggested Fixes

  1. Inactivity timeout: If no output or tool call is produced within N seconds, automatically retry or yield control with an error message.
  2. Programmatic interrupt: Expose an API/SDK method (or Unix signal handler, e.g., SIGUSR1) that acts as the equivalent of Esc for non-interactive sessions.
  3. Heartbeat / watchdog: Log periodic heartbeat messages during long thinking pauses so the user (or automation) can distinguish "thinking" from "hung."

View original on GitHub ↗

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