Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

session-stripper

БесплатноЗапускает вложенные скриптыНе проверен

Manually trim, compact, persist, and repair Claude Code conversation sessions stored as JSONL files. Use when the user wants to: (1) fix a session hitting…

vicnaumот vicnaum★ 53 звезды на GitHub

Об этом скилле

Session Surgery

CLI tool for trimming Claude Code JSONL sessions. Sessions live at ~/.claude/projects/<project-path>/<uuid>.jsonl.

Identify the session FIRST — never guess by mtime

Every mutating command operates on the exact <session.jsonl> path you pass. Getting that path right is the single most important step: strip the wrong file and you silently corrupt a different, possibly active, session.

To strip the CURRENT session, resolve it from $CLAUDE_CODE_SESSION_ID — the env var Claude Code exports into every Bash tool call, which matches the real transcript filename:

SKILL=<skill-dir>/scripts/stripper.py
SESS=$(python3 "$SKILL" current --quiet)   # resolves $CLAUDE_CODE_SESSION_ID → its .jsonl (any cwd)
python3 "$SKILL" strip-all "$SESS"

current (without --quiet) prints the id, path, and whether it exists.

NEVER select the session with ls -t ... | head -1 (most-recently-modified). In a project folder with more than one session running — increasingly common with parallel/multi-agent work — the newest file is frequently a different live session, and you will strip someone else's work. $CLAUDE_CODE_SESSION_ID is the only reliable source; if it is unset you are not inside a CC session, so ask the user which file to strip rather than guessing.

When the user names a specific session id or file (e.g. "strip session abc123"), use that instead; current is only for "strip this/my session".

Fork-first: mutations never touch the session you pass

Mutating commands write a fork by default. The result is a new session, <newSessionId>.jsonl next to the original, with forkedFrom stamped on every record. The original is only read. Every command ends with the resume line:

python3 stripper.py strip-all <session.jsonl>
# ...
# Stripped session: ~/.claude/projects/<dir>/<newSessionId>.jsonl
# Resume it:        claude -r <newSessionId>

Nothing has to be swapped in, and nothing the original records later is ever discarded. The original can keep running while you strip; quit it whenever you like and claude -r <newSessionId>. If you kept working in the original after stripping, its newer turns are not in the fork: strip again (--new-fork) to include them.

Why (incident 2026-11-11): the old default wrote <session>.jsonl.pending and needed the CLI to quit so apply could swap it in. The user kept working in the session meanwhile, so the copy went stale: swapping it in would have discarded those turns, and the session never got smaller. Before that (incident 2026-08-05), in-place rewrites raced the live CLI's appends; one collapsed a 763-message chain to 14. A fork has neither problem.

Mechanics:

  • Back-to-back passes build ONE fork. A second mutating command on the same session reuses its fork while nobody has resumed it (analyze → persist-range → strip-all → …). It says so, and notes if the original has grown since. A command aimed at the fork itself edits it in place, too.
  • A resumed fork is never edited. The stripper records each fork's size and mtime after its last write, in <fork>.jsonl.stripper.json (outside CC's *.jsonl glob). Once a CLI has appended to the fork, the next command forks the original afresh. --new-fork always takes a fresh one.
  • Dry runs never create a fork.
  • No .baks are written while mutating a fork: the untouched original is the backup.
  • compact always writes a new session file anyway. migrate-persisted moves shared sidecar files on disk, so it keeps the in-place flow below.
  • After a fork, anything keyed to the old session id is stale; for example, re-register on agent-chat in the resumed session.

--in-place: keep the session id

For a session that must keep its id, --in-place keeps the older copy-first flow. It mutates <session>.jsonl.pending and swaps it over the original with one atomic rename:

python3 stripper.py strip-all <session.jsonl> --in-place   # writes <session.jsonl>.pending
python3 stripper.py apply     <session.jsonl>              # the one write to the real file
  • Multi-pass --in-place strips reuse the same pending copy. snapshot --refresh re-snapshots.
  • apply accepts either path (original or .pending). It refuses to swap when the original is being written right now (it grew during a 400ms settle check), when the original was rewritten since the snapshot (prefix-hash mismatch), or when the pending copy fails verify. Refusals leave everything in place.
  • Anything appended to the original after the snapshot is discarded by apply, by design (counted and reported). In the self-strip flow that tail is the stripping turn itself.
  • apply refuses if someone typed messages into the session after the snapshot: the copy is stale, and swapping it in would discard them. Slash commands, tool results and task notifications don't count, so the self-strip tail never trips this. Strip again (a fork loses nothing), or pass `--dis
Полный SKILL.md на GitHub

Установить session-stripper в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/surgery-report.mdscripts/lib/__init__.pyscripts/lib/analyze.pyscripts/lib/attachment_cost.pyscripts/lib/chain.pyscripts/lib/compact.pyscripts/lib/compact_range.pyscripts/lib/fork.pyscripts/lib/image_tokens.pyscripts/lib/migrate_persisted.pyscripts/lib/pending.pyscripts/lib/persist_layout.pyscripts/lib/persist_message.pyscripts/lib/persist_range.pyscripts/lib/persist_text.pyscripts/lib/persist_tools.pyscripts/lib/preserved_thinking.pyscripts/lib/replace_images.pyscripts/lib/strip_attachments.pyscripts/lib/strip_thinking.pyscripts/lib/strip_tools.pyscripts/stripper.py

FAQ

Что делает скилл session-stripper?

Manually trim, compact, persist, and repair Claude Code conversation sessions stored as JSONL files. Use when the user wants to: (1) fix a session hitting 'Prompt is too long' errors, (2) manually compact or strip a session to reduce context, (3) analyze a session's token usage and message chain, (4) strip tool call inputs and results from a session, (5) strip thinking blocks from a session, (6) compact part of a session before a specific message, (7) verify or repair a broken session chain, (8) persist and summarize tool results to reduce context intelligently, (9) perform any JSONL-level surgery on Claude Code sessions. Triggers on mentions of session surgery, session trimming, session stripping, context compaction, session repair, prompt too long, session compact, manual session manipulation, summarize tool results, or persist tool output.

Как установить скилл session-stripper?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл session-stripper запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить session-stripper с