[BUG] Unexpected compaction on terminal close with background tasks - context lost at 11% usage

Resolved 💬 3 comments Opened Feb 3, 2026 by DiFuks Closed Mar 5, 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 closing the terminal with active background tasks (which get killed), Claude Code creates a summary record in the session JSONL file and compacts the conversation - even though context usage was only ~11% (far below the documented 95% auto-compaction threshold).

On --resume, only this brief summary is loaded instead of the full conversation history. The summary is extremely terse (just one sentence describing the general topic) and provides no useful context about what was being worked on.

Key observations:

  • Context was at ~11% (21k/200k tokens) - nowhere near 95% threshold
  • No compact_boundary marker in JSONL - only a summary record
  • The summary was created immediately after task-notification with status: killed
  • Full conversation history (153 messages, 5.7MB) exists in JSONL but is not loaded on resume

What Should Happen?

  1. Compaction should NOT trigger when closing terminal if context is below threshold (95% by default)
  2. On --resume, the full conversation history should be loaded from the JSONL file
  3. If compaction must happen on exit, the summary should be detailed enough to preserve important context

Per documentation:

"When you resume a session with claude --continue or claude --resume, you pick up where you left off. Your full conversation history is restored."

Error Messages/Logs

No errors - the session simply loses context silently.

Session file analysis:

$ wc -l session.jsonl
2213 lines (5.7MB)

$ jq -r '.type' session.jsonl | sort | uniq -c
1078 saved_hook_context
 933 progress
 114 assistant
  67 user
   1 summary    ← Created on terminal close

$ jq -c 'select(.type == "summary")' session.jsonl
{"type":"summary","summary":"<one-sentence description>","leafUuid":"dd5ff8de-..."}

Timeline before summary creation:

L2167: user message (task-notification, status: killed)
L2168: user message (task-notification, status: killed)  
L2169: user message (task-notification, status: killed)
L2170: summary record ← Created immediately after killed tasks

Steps to Reproduce

  1. Start a Claude Code session
  2. Run background tasks using run_in_background: true
  3. Work on the session until context is ~10-20% (well below 95%)
  4. Close the terminal (Ctrl+D, close window, or kill the process)
  5. Background tasks are killed with status: killed notifications
  6. Resume with claude --resume <session-id>
  7. Result: Only a brief summary is loaded, full conversation context is lost

Claude Model

Opus

Is this a regression?

I don't know

Claude Code Version

2.1.30 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

This is different from #22107 (broken parent chains). In this case:

  • Parent chain is intact - all parentUuid references are valid
  • The problem is unexpected compaction trigger when terminal closes with background tasks
  • And resume not loading full history from intact JSONL

Workaround: Before closing terminal, manually stop all background tasks with /stop or run /compact with a detailed description.

Session file available for debugging if needed.

View original on GitHub ↗

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