Claude Code stuck on compacting

Guide · August 2026 · ~4 min read

Long sessions periodically compact: Claude Code summarizes the conversation so far into a compact record and continues from it. When compaction hangs — spinner forever, or the session afterwards refuses to resume — the cause is almost always in the transcript file, not the model.

What a healthy compaction looks like

In the session JSONL you'll see a summary record near the end: a record whose content summarizes prior context, with the next user message parented onto it. If that structure is intact, resume works.

Failure mode 1: interrupted mid-write

Compaction writes new records. Kill the process (or lose power) during the write and the last line is truncated or a summary lands without its child. The session then either loops trying to compact again or fails to load. Find the bad line:

python -c "
import json
p = r'C:\Users\Lenovo\.claude\projects\YOUR-PROJECT\SESSION.jsonl'
for i, line in enumerate(open(p, encoding='utf-8')):
    if line.strip():
        try: json.loads(line)
        except Exception as e: print(f'line {i+1}: {e}')"

Failure mode 2: the summary is there but nothing points at it

The compact record exists but the following message still parents to the pre-compaction chain. The loader walks uuidparentUuid from the newest leaf; if the walk never reaches the summary, the session loads with full old context (compaction silently didn't take effect) or fails outright. The fix: reparent the orphaned message onto the summary record, or delete the dangling branch.

Failure mode 3: orphaned tool results around the cut

If a tool call sat in flight when compaction started, its result can end up referencing a call that was summarized away. Same repair as any orphan: remove the result or pair it out entirely.

Recovery path

Back up the file first. Then either hand-edit (workable under a few MB) or open the session in SessionPatch: Doctor lists every broken reference with its line number and jump-to links; delete or reparent the offending records in Edit mode; export .patched.jsonl; replace the original; claude --resume.

Related: --resume not working · transcripts deleted after 30 days