[BUG] Background agent IDs lost on context compaction

Resolved 💬 2 comments Opened Feb 27, 2026 by RemyPhD34 Closed Feb 27, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When a conversation hits the context limit and compacts, any running background agent IDs are lost. The resumed session has no reference to agents that were launched before compaction. The assistant can't retrieve their results, and the agents keep running in the background. User must notice and manually stop agent.

What Should Happen?

Background agent IDs should survive context compaction. After
compaction, the session should still be able to reference,
check status of, and stop any agents that were running before
compaction occurred.

Error Messages/Logs

Leave blank (no error -- it just silently
  loses the IDs)

Steps to Reproduce

  1. Start a long Claude Code session that will approach the

context limit

  1. Launch a background agent using the Task tool (e.g., a

research task that takes a few minutes)

  1. Continue working until context compaction triggers
  2. After compaction, attempt to check on or stop the background

agent

  1. The agent ID is gone -- neither the user nor the assistant

can reference it

  1. /tasks may still show it, but the assistant has no way to

connect to it

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.62 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

iscovered during a working session where a verification agent
was launched, context compacted mid-session, and the resumed
conversation had no way to stop or retrieve the agent. The
agent's partial results had been observed before compaction, so
the work wasn't blocked -- but the orphaned agent kept running
with no kill switch.

View original on GitHub ↗

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