AgentSkillsCN

context-cleaner

Claude 代码转录清理器,可在保留对话流畅性的前提下,将令牌用量减少 60–80%。当用户希望清理、优化或压缩会话转录,减少上下文令牌,或为高效恢复会话做好准备时,可使用此技能。可通过“上下文清理”、“转录清理”、“令牌优化”、“会话压缩”、“上下文缩减”、“会话擦除”等关键词触发。

SKILL.md
--- frontmatter
name: context-cleaner
description: Claude Code transcript cleaner that reduces token usage by 60-80% while preserving conversation flow. Use when the user wants to clean, optimize, or compact a session transcript, reduce context tokens, or prepare a session for efficient resume. Triggers on keywords like context clean, transcript clean, token optimization, session compact, context reduction, effaced session.

Context Cleaner

Transcript cleaning tool that strips bulky tool data (thinking blocks, file contents, diffs, stdout) while preserving conversation flow, edit intent, and filenames.

Workflow

  1. Get the transcript path
  2. Run the cleaning script
  3. Report results and resume command

Step 1: Get Transcript Path

Check these sources in order:

  1. SessionStart hook context - Look for Transcript: in the system-reminder at the top of conversation
  2. Environment variable - Run echo $TRANSCRIPT_PATH in Bash
  3. Ask the user - If neither is available, ask for the path

Step 2: Run the Cleaning Script

bash
python3 <skill-path>/scripts/context-cleaner.py <transcript_path>

The script:

  • Creates a NEW file with 00effaced{NNN} suffix (original preserved)
  • Unifies all sessionId entries to match the new filename
  • Strips: thinking blocks, Read/Write/Edit/Bash contents, file paths, tool results, hook progress lines
  • Preserves: conversation text, edit intent, filenames, uuid chain

Step 3: Report Results

The script outputs cleaning statistics and a resume command. Share the resume command with the user:

code
claude --resume <new_session_id> --verbose

SessionStart Hook

The src/contextCleaner_sessionStartHook.sh file provides:

  • Transcript path injection into Claude context (every session)
  • CLAUDE_ENV_FILE env vars ($SESSION_ID, $TRANSCRIPT_PATH)
  • Resume command copied to clipboard
  • Cleaned session detection (00effaced pattern)

Installation: copy to ~/.claude/hooks/ and register in ~/.claude/settings.json under SessionStart.