claude -p background tasks orphaned across invocations surface false "no completion record from previous session" events

Resolved 💬 1 comment Opened Jun 29, 2026 by jsedwick Closed Jun 29, 2026

Summary

When Claude Code is driven as a series of one-shot claude -p invocations — e.g. a wrapper that runs one claude -p per conversation turn and continues the conversation via --resume — background tasks started in one invocation (persistent Monitor tasks and background Bash / run_in_background) are bound to that invocation's process. When the process exits normally at the end of the turn, those tasks are orphaned. On the next claude -p invocation, the harness's task reconciliation emits, once per orphaned task, on every turn boundary:

No completion record was found for this background shell command from the previous session. It may have been stopped (via the UI, Monitor timeout, or agent teardown — these leave no transcript marker), or it may have been running when the previous Claude Code process exited. Check the output file for partial results before assuming it completed.

Environment

  • Claude Code 2.1.195
  • Usage pattern: claude -p --output-format stream-json --include-partial-messages --resume <session-id> with --permission-mode bypassPermissions — one process per turn (a local chat-bridge wrapper)
  • Tasks affected: persistent Monitor tasks, background Bash (run_in_background)

Repro

  1. In a claude -p invocation, arm a persistent Monitor (or start a background Bash task).
  2. Let that invocation produce its result and exit.
  3. Start a new claude -p for the same conversation with --resume <id>.
  4. Observe a "no completion record … from the previous session" event for each task armed in step 1.
  5. If the new invocation re-arms them, the cycle repeats on every turn.

Expected

A one-shot claude -p process that exits normally after producing its result should not surface its background tasks as anomalous "may have been running when the process exited" events in a subsequent process. Either:

  • background tasks tied to a -p process are reaped quietly when that process exits normally (no cross-invocation reconciliation event carried into --resume), or
  • the reconciliation distinguishes "parent -p exited normally" (expected → silent) from "process crashed / was killed" (anomalous → surface).

Actual

Every orphaned task produces a teardown event in the next invocation, indistinguishable from a genuine crash/hang, creating recurring noise surfaced to the user.

Impact

  • Recurring, alarming-looking noise on every turn for any wrapper using claude -p per turn.
  • Misleading — implies a possible crash/hang when the process simply exited normally.
  • Forces wrappers to disable background tasks (Monitor, background Bash) entirely as a workaround.

Possible directions

  • Treat normal exit of a -p process as a clean reap point for its background tasks (no carry-forward into --resume).
  • Tag reconciliation events with the prior process's exit status; surface only on abnormal exit.
  • Provide a flag to suppress cross-invocation background-task reconciliation for headless/-p use.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗