Skip to content

meridianix/clawdbot-session-pruner

Repository files navigation

Clawdbot Session Pruner

Optimize bloated JSONL session files by truncating large tool results while preserving conversation continuity.

Transform 2MB+ session files into lean, fast-loading versions without losing context. Built for Claude Code, Clawdbot sessions, and any JSONL-based chat logs.

Two Ways to Use

Command Line Interface

# Analyze your sessions
python analyze-sessions.py ~/.claude/projects/

# Preview changes (safe, no modifications)
python truncate-sessions.py ~/.claude/projects/ --dry-run

# Apply truncation with automatic backups
python truncate-sessions.py ~/.claude/projects/ --confirm

Web Interface

cd web-ui
npm install && npm run dev
# Open http://localhost:3000

Drag & drop your JSONL files, analyze bloat, download optimized versions. Perfect for one-off files or non-technical users.

The Problem

Claude Code session files balloon to 2MB+ because tool results contain massive outputs - file contents, logs, command output. This kills context loading speed and wastes tokens.

The Solution

Surgical truncation: Keep first 2.5KB + last 2.5KB of large tool results, insert a size marker. Preserves conversation flow, cuts 90% of bloat.

Example

Before (bloated tool result):

{"role":"tool","tool_result":"File contents:\nline 1\nline 2\n...50,000 lines of logs..."}

After (truncated):

{"role":"tool","tool_result":"File contents:\nline 1\nline 2\n\n[TRUNCATED: 197KB removed, keeping first + last 2.5KB each]\n\n...line 49,999\nline 50,000"}

Results

File Before After Saved
session_abc123 2.3MB 180KB 92%
session_def456 800KB 95KB 88%

How it Works

  • Parse each JSONL line and identify tool results over threshold (default 5KB)
  • Truncate large results: keep first 2.5KB + last 2.5KB, insert size marker
  • Preserve all user messages, assistant responses, and conversation metadata

What Gets Truncated

  • Large tool results over 5KB (configurable via --threshold)
  • Preserves first and last portions with size marker
  • Never touches user messages, assistant responses, or metadata

Safety

  • Atomic backups - Timestamped backups before any modification
  • Dry-run mode - Preview all changes before applying
  • JSON validation - Validates output before writing
  • Rollback ready - Restore from .backup_* files anytime

Requirements

CLI Tools:

  • Python 3.9+ (no external dependencies)

Web Interface:

  • Node.js 18+
  • npm or yarn

License

MIT

About

Optimize bloated JSONL session files by truncating large tool results while preserving conversation continuity. Built for Claude Code, Clawdbot sessions, and any JSONL-based chat logs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors