Skip to main content

Diagnose and recover corrupted Claude Code session JSONL files

Project description

claude-rescue

Diagnose and recover corrupted or fragmented Claude Code session files.

Claude Code stores conversations as JSONL files in ~/.claude/projects/. Over time these files can become fragmented (multiple disconnected conversation chains in one file, usually from interrupted sessions or reconnects) or corrupted (entries referencing parents that don't exist). claude-rescue finds these issues and recovers the best chain so you can resume with full context.

Installation

pipx install claude-rescue   # recommended
# or
pip install claude-rescue

Commands

diagnose

Scan a project directory and report the health of each session file.

claude-rescue diagnose          # current directory (auto-resolved to its Claude project)
claude-rescue diagnose .        # same
claude-rescue diagnose ~/work/my-project
claude-rescue diagnose --subagents   # also show subagent/compaction files

Example output:

(project root)
  Session ID                            Entries   Roots   Broken  Status        Last prompt
  ---------------------------------------------------------------------------------------------------------------
  69e982d2-71f2-447a-a4df-1f90ae590e2d    8682      57        0  ⚠ fragmented  please familiarise yourself with...
  fbf21b51-e264-4721-adf8-d176907d8404    1824       1        0  ✓ healthy     can you add error handling to...

Status meanings:

  • ✓ healthy — single chain, no issues
  • ⚠ fragmented — multiple disconnected chains; recoverable
  • ✗ corrupted — entries with missing parents; recoverable (dangling entries are dropped)

recover

Recover a single session by ID, keeping the most recently written chain.

claude-rescue recover 69e982d2-71f2-447a-a4df-1f90ae590e2d

Output:

Last prompt: please familiarise yourself with this project

Recovered 57 entries (1769 metadata lines) to:
  /home/you/.claude/projects/.../1892d453-aa34-4598-80c0-e214234e0c7d.jsonl

Resume with:
  claude --resume 1892d453-aa34-4598-80c0-e214234e0c7d

Options:

  • --pick — interactively choose which chain to recover instead of auto-selecting
  • --project PATH — specify the project directory if not auto-detected

Running recover twice on the same session without changes prints the existing ID instead of creating a duplicate.

recover-all

Recover every fragmented or corrupted session in a directory.

claude-rescue recover-all          # current directory
claude-rescue recover-all ~/work/my-project
claude-rescue recover-all --quiet  # suppress per-file resume hints
claude-rescue recover-all --in-place  # overwrite originals (backup as .bak)

Compaction files (agent-acompact-*) are always recovered in-place since they have no session ID to resume.

prune-acompact

Delete compaction sidechain files (agent-acompact-*). These are internal transcripts of Claude's context-summarisation runs and are not needed for resuming sessions — the summary itself is stored inline in the main session file.

claude-rescue prune-acompact            # current directory
claude-rescue prune-acompact --dry-run  # show what would be deleted

On a long-running project this can recover hundreds of MB.

How it works

Claude Code session files are JSONL where each entry has a uuid and optional parentUuid, forming a linked chain. Fragmentation occurs when multiple root entries (entries with no parent) exist in the same file — typically after a reconnect writes a new root instead of continuing from the last entry.

claude-rescue uses a two-pass approach:

  1. Pass 1 — extract only uuid/parentUuid via raw-byte regex (no full JSON parse). Builds the chain tree in ~10 MB of memory regardless of file size.
  2. Pass 2 — stream the file again, writing only entries belonging to the selected chain.

The best chain is selected by highest last-written line number (most recently active chain). Use --pick to override.

Contributing

Issues and pull requests welcome at github.com/Jwrede/claude-rescue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_rescue-0.2.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_rescue-0.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file claude_rescue-0.2.0.tar.gz.

File metadata

  • Download URL: claude_rescue-0.2.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for claude_rescue-0.2.0.tar.gz
Algorithm Hash digest
SHA256 56d46024033573d6736f98517687744da0dcbfa2fc1fd214bf167359f62172c1
MD5 b5b323c47b985af9177b3d713fb07d2b
BLAKE2b-256 601355f379a9fb9794a75c6c0b8c1878b456a5e87cfff4e21449ec976504487f

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_rescue-0.2.0.tar.gz:

Publisher: publish.yml on Jwrede/claude-rescue

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file claude_rescue-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: claude_rescue-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for claude_rescue-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1df4e12ba430012fd03b8c83f58b5d363ed6ee407656e7d7aab48f615c5e39b3
MD5 ca8e9a3e4349efe53ad8fce7e9e964d2
BLAKE2b-256 82b8ef5d646580c5c74cd69c5ed40195b483c71008c14ee0808dc678c684cd85

See more details on using hashes here.

Provenance

The following attestation bundles were made for claude_rescue-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Jwrede/claude-rescue

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page