[BUG] --print mode hangs in v2.1.76: deferred tools (Agent, Skill, WebSearch) cause intermittent deadlock

Resolved 💬 2 comments Opened Mar 17, 2026 by mknitsche Closed Apr 14, 2026

Description

In Claude Code v2.1.76, --print (non-interactive/headless) mode hangs intermittently when the model attempts to use deferred tools (Agent, Skill, WebSearch, WebFetch, ToolSearch). Core tools (Bash, Read, Write, Edit, Grep, Glob) work reliably.

This is a regression from v2.1.74, where -p mode worked correctly with all tools including Agents and Skills.

Related: #30008 (closed, but the underlying issue persists in v2.1.76)

Steps to Reproduce

# This hangs intermittently (requires project with skills defined):
claude -p --dangerously-skip-permissions --model claude-sonnet-4-6 \
  "Run this command: echo hello and tell me the result. Then search the web for weather in Berlin."

# This always works (no deferred tools needed):
claude -p --dangerously-skip-permissions --model claude-sonnet-4-6 \
  "Run this command: echo hello and tell me the result."

The hang is intermittent — the same prompt may work on one attempt and hang on the next:

Run 1: OK
Run 2: HANGING (0 bytes output after 60s)
Run 3: OK

Systematic Test Results

| Prompt pattern | Result |
|---|---|
| Simple text response (no tools) | Always works |
| Core tool use (Bash, Read) | Always works |
| Prompt that triggers Agent tool | Intermittent hang |
| Prompt that triggers Skill tool | Intermittent hang |
| Prompt that triggers WebSearch | Intermittent hang |
| --disable-slash-commands flag | Does NOT fix the issue |

Root Cause Analysis

The hang produces 0 bytes of output — Claude starts but never generates any response. The process stays alive consuming no CPU. This suggests the event loop / do-while in the print mode controller gets stuck waiting for deferred tool initialization or in_process_teammate tasks (as described in #30008).

The intermittent nature points to a race condition in the deferred tool loading or task status management. When the model decides to use a deferred tool, the print controller sometimes enters a state where it waits indefinitely for a task that will never complete.

Impact

This breaks all headless/automated workflows that rely on -p mode:

  • Scheduled tasks via launchd/cron (e.g., automated morning briefings)
  • CI/CD pipelines using Claude Code
  • Any automation that uses Agents, Skills, or web search in print mode

Workaround

  1. Startup check + retry: Kill the process if no output after 60s, retry up to 3 times
  2. Restrict to core tools: Prompt instructs Claude to only use Bash/Read/Write (no Agent, Skill, WebSearch)
  3. Both combined provide ~95% reliability

Environment

  • Claude Code version: 2.1.76 (native binary, macOS ARM64)
  • OS: macOS Darwin 25.3.0 (Apple Silicon)
  • Regression from: v2.1.74 (where -p mode worked correctly with all tools)
  • Update timestamp: Binary symlink changed 2026-03-14 15:03 → first failure 2026-03-15 05:39

View original on GitHub ↗

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