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:
- Pass 1 — extract only
uuid/parentUuidvia raw-byte regex (no full JSON parse). Builds the chain tree in ~10 MB of memory regardless of file size. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_rescue-0.2.1.tar.gz.
File metadata
- Download URL: claude_rescue-0.2.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b64b17c6ad09516794997c645cedfe2fded07a5e2bc95f6b2977f5ebcd5ffd3
|
|
| MD5 |
bc3112f74361710b317ba76504ed06b7
|
|
| BLAKE2b-256 |
5b52bce33e6d67d4e7a5a0f9332beccb6e82a63a10b3a25860e92a4e11f38b19
|
Provenance
The following attestation bundles were made for claude_rescue-0.2.1.tar.gz:
Publisher:
publish.yml on Jwrede/claude-rescue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_rescue-0.2.1.tar.gz -
Subject digest:
9b64b17c6ad09516794997c645cedfe2fded07a5e2bc95f6b2977f5ebcd5ffd3 - Sigstore transparency entry: 1426709516
- Sigstore integration time:
-
Permalink:
Jwrede/claude-rescue@4bf33f8c7eef95b4d6b209e856437c9adebab647 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Jwrede
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4bf33f8c7eef95b4d6b209e856437c9adebab647 -
Trigger Event:
push
-
Statement type:
File details
Details for the file claude_rescue-0.2.1-py3-none-any.whl.
File metadata
- Download URL: claude_rescue-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3917577871133e0e2e6d0b81c3dd3ae4e14fc52edcb3118ba361d3c57af99ff7
|
|
| MD5 |
f8a40f1f46ba0b915b05b2f751d5da0a
|
|
| BLAKE2b-256 |
64c165acbaa2ba3bc5fc9628551aee4dbaae26b6740fce09fb11419d511ff49d
|
Provenance
The following attestation bundles were made for claude_rescue-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on Jwrede/claude-rescue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_rescue-0.2.1-py3-none-any.whl -
Subject digest:
3917577871133e0e2e6d0b81c3dd3ae4e14fc52edcb3118ba361d3c57af99ff7 - Sigstore transparency entry: 1426709622
- Sigstore integration time:
-
Permalink:
Jwrede/claude-rescue@4bf33f8c7eef95b4d6b209e856437c9adebab647 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Jwrede
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4bf33f8c7eef95b4d6b209e856437c9adebab647 -
Trigger Event:
push
-
Statement type: