claude_code_session_fixer
Claude Code Session Fixer
Small Crystal CLI tool to repair broken Claude Code session files by removing thinking and redacted_thinking blocks from assistant messages in .jsonl sessions.
What It Does
- Scans Claude sessions under
~/.claude/projects/*/*.jsonl. - Finds assistant messages that contain
thinking/redacted_thinkingblocks. - Removes only those blocks from
message.content. - Drops a line if, after removal,
contentbecomes empty. - Creates a backup before writing changes.
Why
Some Claude session files can become hard to resume when internal thinking blocks are present or malformed for downstream tooling. This utility performs a targeted cleanup without changing unrelated JSON fields.
Requirements
- Crystal
>= 1.10.0
Build
crystal build src/session_fixer.cr -o session_fixer
Usage
# Show help
./session_fixer --help
# List sessions that contain thinking blocks
./session_fixer --list
# Fix by full or partial session ID
./session_fixer <session-id>
# Fix by direct file path
./session_fixer /absolute/path/to/session.jsonl
# Preview changes only (no write)
./session_fixer <session-id-or-path> --dry-run
You can also run without building:
crystal run src/session_fixer.cr -- --list
crystal run src/session_fixer.cr -- <session-id> --dry-run
Session Selection Rules
When you pass an ID (not a file path), matching is:
- Exact UUID match first.
- Partial UUID match second.
- If multiple matches are found, the tool stops with an ambiguity error and asks for a longer ID or full path.
Safety and Backups
- Normal mode writes to a temporary file, then replaces the original.
- A backup is created first:
- preferred:
<session>.bak.jsonl - if that already exists:
<session>.bak.<timestamp>.jsonl
- preferred:
--dry-runnever modifies the source file.
Output Stats
After processing, the tool reports:
- total lines
- modified lines
- removed lines (where content became empty)
- number of thinking blocks removed
- parse errors skipped (if any malformed JSON lines were encountered)
Limitations
- Only assistant messages are modified.
- Non-JSON lines are skipped (counted as parse errors).
- The tool assumes standard Claude session layout under
~/.claude/projects/.
Repository
claude_code_session_fixer
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- about 6 hours ago
- March 1, 2026
License
Links
Synced at
Sun, 01 Mar 2026 18:32:17 GMT
Languages