Claude Code session

Claude Prune

(85 ⭐ A fast CLI tool for pruning Claude Code sessions.

83 stars 11 forksSessions & history Source

Install

Install
npm install -g claude-prune

Found in the project README. Check it for setup steps after installing.

From source
git clone https://github.com/DannyAziz/claude-prune.git

From the README

claude-prune

A fast CLI tool for pruning Claude Code sessions.

Features

- 🎯 Smart Pruning: Keep messages since the last N assistant responses
- 🛡️ Safe by Default: Always preserves session summaries and metadata
- 💾 Auto Backup: Creates timestamped backups before modifying files

Installation

Run directly (recommended)

Install globally

Usage

Arguments

- sessionId: UUID of the Claude Code session (without .jsonl extension)

Options

- -k, --keep : Number of assistant messages to keep (required)
- --dry-run: Preview changes without modifying files
- -h, --help: Show help information
- -V, --version: Show version number

Examples

How It Works

1. Locates Session File: Finds ~/.claude/projects/{project-path}/{sessionId}.jsonl
2. Preserves Critical Data: Always keeps the first line (session summary/metadata)
3. Smart Pruning: Finds the Nth-to-last assistant message and keeps everything from that point forward
4. Preserves Context: Keeps all non-message lines (tool results, system messages)
5. Safe Backup: Creates {sessionId}.bak.{timestamp} before modifying
6. Interactive Confirmation: Asks for confirmation unless using --dry-run

File Structure

Claude Code stores sessions in:

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

Environment Variables

CLAUDE_CONFIG_DIR

By default, claude-prune looks for session files in ~/.claude. If Claude Code is configured to use a different directory, you can specify it with the CLAUDE_CONFIG_DIR environment variable:

Development

License

MIT © Danny Aziz
Read the full README on GitHub

Details

Language
TypeScript
License
MIT
Last updated
16 September 2025

FAQ

What is Claude Prune?

(85 ⭐ A fast CLI tool for pruning Claude Code sessions. It is a session for Claude Code, from DannyAziz/claude-prune on GitHub.

How do I install Claude Prune?

Run npm install -g claude-prune, then follow the setup in the README.

Is Claude Prune popular?

DannyAziz/claude-prune has 83 GitHub stars and 11 forks, and is included in 1 curated Claude Code list. It was last updated on 16 September 2025.

More sessions & history

Browse the most popular Claude Code mods, all sessions & history, or the skills and MCP server directories.