2.1.198: headless -p run exits ~50s after model launches Agent subagent with run_in_background=true; bg wait ceiling not applied (regression from 2.1.197)

Open 💬 2 comments Opened Jul 2, 2026 by Jarvvski

Summary

In Claude Code 2.1.198, a headless run (claude -p style, driven by anthropics/claude-code-action@v1 via the Agent SDK) exits roughly 50 seconds after the model launches an Agent-tool subagent with run_in_background: true. The backgrounded subagent is abandoned mid-work, no result message is emitted on the stream, and the run produces no output. The documented background-subagent wait ceiling for print mode (CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS, default 10 minutes) does not kick in.

The same workflow on 2.1.197 (previous day, same prompt) completed normally. The failure is intermittent because it depends on a model choice: on 2.1.198, runs where the model launches subagents as blocking calls still succeed; runs where it picks run_in_background: true die.

Environment

  • Claude Code 2.1.198 (installed by anthropics/claude-code-action@v1, commit 6c0083bb7289c31716797a039b6367b3079cc46e, which bumps CLI 2.1.197 -> 2.1.198 and Agent SDK 0.3.197 -> 0.3.198)
  • Vertex AI provider (CLAUDE_CODE_USE_VERTEX=1), model claude-opus-4-7
  • Linux CI runner (Ubuntu 24.04), non-interactive
  • Prompt: a multi-agent PR review orchestrator that instructs the model to "launch 5 Task sub-agents in parallel", collect their JSON findings, then post a review

What happened (from the stream JSON in the CI log)

  1. 13:37:58 - orchestrator calls the Agent tool with "run_in_background": true for the first review subagent. Tool result comes back immediately:
"tool_use_result": {
  "isAsync": true,
  "status": "async_launched",
  "agentId": "a2d3cf5fb9e237fa1",
  "resolvedModel": "claude-opus-4-7",
  "outputFile": "/tmp/claude-1001/.../tasks/a2d3cf5fb9e237fa1.output",
  "canReadOutputFile": true
}
  1. 13:38:00-13:38:01 - the backgrounded subagent starts working (task_started, task_progress, first Read tool call and its tool_result appear on the stream).
  2. The stream then truncates mid tool_result message. No further assistant turns, no "type": "result" message at all.
  3. 13:38:51 - the action step completes with exit code 0 and the job moves on. Total elapsed since the async launch: ~53 seconds. None of the orchestrator's later phases ran and nothing was written or posted.

For comparison, a run minutes later on the same 2.1.198 install, where the model happened to launch its subagents as blocking calls (no async_launched anywhere in the stream), completed all phases and ended with a normal "subtype": "success" result message. The last 2.1.197 run the previous day also completed normally.

Expected

Per the headless docs, print mode should wait for background subagents up to CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS (default 10 minutes), and the orchestrator should be able to collect the subagent's result and continue. Instead the process exits within about a minute, silently, with exit code 0.

Impact

Any headless orchestration prompt that fans out subagents now fails nondeterministically, depending on whether the model elects to background them. Exit code 0 makes the failure silent in CI.

Workarounds we applied

  • CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 in the action env, which removes run_in_background from the Agent tool.
  • A prompt instruction to never pass run_in_background.
  • Known-good fallback: pinning the action to the last commit shipping 2.1.197 (fad22eb3fa582b7357fc0ea48af6645851b884fd).

Happy to provide fuller (lightly redacted) stream logs from the failing run if useful.

View original on GitHub ↗

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