Skip to content

Subagent output files lost after context compaction #23821

@coreh

Description

@coreh

Description

When a conversation runs long enough to trigger context compaction, the output files for subagents (Task tool) that completed before compaction are lost. Only agents that were still running or recently completed at the time of compaction retain their output files.

Steps to Reproduce

  1. Start a conversation that spawns many subagents (e.g., 10+ research agents across multiple phases)
  2. Continue working until context compaction is triggered
  3. After compaction, try to access earlier subagent outputs via TaskOutput or by reading files in the tasks directory

Expected Behavior

All subagent output files should be preserved for the duration of the session, regardless of context compaction. The task output files are stored on disk (in /private/tmp/claude-501/.../tasks/), so they should survive compaction since it's a context window operation, not a filesystem operation.

Actual Behavior

Only 4 out of 14+ subagent output files were available after compaction. The earlier research agents' outputs were all gone. Only the 3 most recent agents (which were still running at compaction time) retained their files.

The system reminders after compaction still reference the old agent task IDs (e.g., a546039, abcc9c4, adfe895, etc.), but reading their output files fails with "file not found."

Impact

This is particularly painful for long research sessions where you intentionally spawn many parallel agents to gather information, then synthesize results in later phases. The whole point of saving to disk is durability — but the outputs are lost exactly when you need them most (in long sessions that hit context limits).

Workaround

Manually save subagent outputs to project files (using Write tool) immediately after each agent completes, before context compaction can occur. This is tedious and defeats the purpose of the automatic output file mechanism.

Environment

  • Claude Code v2.1.34
  • macOS Darwin 25.3.0
  • Model: claude-opus-4-6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions