npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@epaynter/claude-prune

v2.0.1

Published

Intelligent context management for Claude Code sessions with interactive pruning strategies

Readme

claude-prune

Intelligent context management for Claude Code sessions. This CLI tool analyzes and prunes Claude Code session transcript files to reduce context usage while preserving the most important parts of your conversation.

Fork of DannyAziz/claude-prune with enhanced selection strategies and visual interface.

Features

Smart Interactive Pruning

  • Work Phase Detection: Automatically identifies distinct phases in your session (setup, debugging, implementation)
  • Multiple Pruning Strategies:
    • Keep recent work only
    • Keep bookends (beginning + end)
    • Keep all code/errors/file edits
    • Custom range selection
  • Visual Session Analysis: See exactly what's in your session before pruning
  • Context Usage Prediction: Know exactly how much context you'll free up

Safety Features

  • Safe by Default: Always preserves session summaries and metadata
  • Auto Backup: Creates timestamped backups before modifying files
  • Restore Command: Easy rollback to previous versions

Installation

Run directly (recommended)

# Using npx (Node.js)
npx claude-prune <sessionId> --keep 50

# Using bunx (Bun)
bunx claude-prune <sessionId> --keep 50

Install globally

# Using npm
npm install -g claude-prune

# Using bun
bun install -g claude-prune

Usage

Interactive Mode (Recommended)

Simply provide your session ID for an interactive experience:

claude-prune abc-123-def

This will:

  1. Analyze your session to detect work phases
  2. Present you with smart pruning options
  3. Show exactly how much context each option will free
  4. Let you preview or customize the selection

Quick Non-Interactive Mode

For automation or quick pruning without prompts:

claude-prune abc-123-def --non-interactive

Legacy Mode

For backward compatibility with the original simple pruning:

claude-prune abc-123-def -k 10  # Keep last 10 assistant messages

Restore from Backup

Every prune operation creates a backup. To restore:

claude-prune restore abc-123-def

Options

  • -k, --keep <number>: Use legacy mode - keep last N assistant messages
  • --non-interactive: Skip interactive mode, use auto strategy
  • --dry-run: Preview changes without modifying files
  • -h, --help: Show help information
  • -V, --version: Show version number

Example Session

$ claude-prune abc-123-def

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Session Analysis
  147 messages | ~42k tokens
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Work Phases Detected:

  ┌ Phase 1 (msg 1-23)     Initial setup and requirements
  ├ Phase 2 (msg 24-89)    Debugging and error resolution
     └─ 31 errors
  ├ Phase 3 (msg 90-147)   Implementation and coding
     └─ 12 file edits

Choose pruning strategy:
  [1] Keep recent work only (msg 90-147, frees 71% context)
  [2] Keep bookends (msg 1-10 + 120-147, frees 65% context)
  [3] Keep all code/errors (23 key messages, frees 58% context)
  [4] Custom range selection
  [5] View message details

Selection [1]: _

How It Works

  1. Session Analysis: Analyzes your conversation to identify work phases and important messages
  2. Smart Detection: Identifies code blocks, errors, file edits, and tool usage
  3. Pruning Strategies: Offers multiple strategies based on your session's structure
  4. Safe Backup: Creates timestamped backups in prune-backup/ before modifying
  5. Cache Optimization: Automatically optimizes cache tokens to reduce UI context display

Technical Details

File Locations

Claude Code stores sessions in:

~/.claude/projects/{project-path-with-hyphens}/{sessionId}.jsonl

For example, a project at /Users/alice/my-app becomes:

~/.claude/projects/-Users-alice-my-app/{sessionId}.jsonl

Backups are stored in:

~/.claude/projects/{project}/prune-backup/{sessionId}.jsonl.{timestamp}

Architecture

The tool is built with a modular architecture:

  • src/analyzer.ts - Session analysis and phase detection
  • src/interactive.ts - Interactive UI components
  • src/pruner.ts - Core pruning logic
  • src/index.ts - CLI interface

Development

# Install dependencies
bun install

# Run tests
bun test          # Run all tests
bun test --watch  # Run tests in watch mode

# Build for distribution
bun run build

# Test locally
bun run src/index.ts prune <sessionId>  # Test prune command
bun run src/index.ts restore <sessionId> # Test restore command
./dist/index.js --help                   # Test built CLI

Credits

Contributing

Contributions welcome! The codebase is well-tested and documented. Please ensure:

  • All tests pass (bun test)
  • New features include tests
  • Code follows existing patterns

License

MIT © Eliot Paynter