claude-code-session-cleaner lists and deletes Claude Code CLI session files
from ~/.claude/projects/. It is a local cleanup helper for saved sessions and
can run as either:
- a standalone interactive shell script
- a Claude Code slash command:
/delete-session
The tool uses the same practical labels you see in /resume, so you can delete
old sessions by title, recent prompt, project, or UUID prefix without manually
digging through encoded project directories.
- Lists sessions newest first for the current project by default.
- Supports
--allto scan every Claude Code project. - Shows index, modified time, project name, file size, UUID prefix, and label.
- Uses label priority compatible with
/resume: custom title, last prompt, then fallback user message. - Deletes the selected
.jsonlfile and its sibling<uuid>/artifact directory. - Refuses to delete sessions modified in the last 10 minutes to avoid removing an active session.
- Resolves UUID prefixes safely and refuses ambiguous matches.
- Installs both the shell script and Claude Code slash command with one command.
.
├── commands/
│ └── delete-session.md # Claude Code slash command
├── scripts/
│ └── delete-session.sh # Session listing and deletion script
├── install.sh # Installer for ~/.claude/scripts and ~/.claude/commands
├── LICENSE
├── README.md
└── README_CN.md
- macOS shell environment
- Bash 3.2 or newer
jq- Claude Code session data under
~/.claude/projects/
Install jq on macOS:
brew install jqClone the repository and install the script plus slash command:
git clone https://github.com/ihoooohi/claude-code-session-cleaner.git
cd claude-code-session-cleaner
./install.shThe installer copies:
scripts/delete-session.shto~/.claude/scripts/delete-session.shcommands/delete-session.mdto~/.claude/commands/delete-session.md
It will not overwrite existing files unless you pass --force.
Run interactively from a terminal:
~/.claude/scripts/delete-session.shList sessions without deleting anything:
~/.claude/scripts/delete-session.sh list
~/.claude/scripts/delete-session.sh list fix-v2
~/.claude/scripts/delete-session.sh --all list
~/.claude/scripts/delete-session.sh --project /path/to/project listDelete by UUID or UUID prefix:
~/.claude/scripts/delete-session.sh delete 9c8dbd97Use it inside Claude Code:
/delete-session
/delete-session fix-v2
/delete-session --all
/delete-session 9c8dbd97
- The script derives the current project from
$PWD, unless you pass--allor--project. - It maps the project path to Claude Code's encoded directory format under
~/.claude/projects/. - It reads only top-level
*.jsonlsession files, not nested artifact files. - It builds labels from session records in this order:
custom-title,last-prompt, then the last non-wrapper user message. - It renders a numbered list for review.
- On deletion, it confirms the target, refuses active sessions, removes the
main
.jsonl, and removes the sibling<uuid>/artifact directory if it exists.
Example list output:
[ 1] 2026-04-24 18:17 EchoCenter 728K bcf9c007... Update map labels
[ 2] 2026-04-24 08:02 EchoCenter 24K 34738f62... Pull the latest repo
[ 3] 2026-04-22 10:07 HERTCERT 31M 9f362cce... ★ fix-v2-production-stability
Interactive deletion accepts individual indexes and ranges:
Enter indexes to delete (e.g. '1 3 5' or '1-4'; empty to quit): 2 5-7
- The active-session guard refuses sessions modified less than 10 minutes ago.
delete <uuid-prefix>refuses if the prefix matches zero or multiple files.- The slash command asks for confirmation before calling the deletion script.
- Linux is not verified because the script currently uses BSD/macOS
statanddateflags. - There is no undo. Deleted files are removed with
rm.
rm ~/.claude/scripts/delete-session.sh
rm ~/.claude/commands/delete-session.mdThis project is released under the MIT License.