Kompakt
Custom summarization for Claude Code's /compact
Claude Code's built-in /compact summarization has several issues that break workflow continuity:
- →Switches to English even when chatting in other languages
- →Paraphrases user messages — losing original intent and context
- →Includes unnecessary code snippets that waste context window
- →Over-explains reasoning instead of preserving actionable state
From GitLab (recommended)
$ /plugin marketplace add https://gitlab.com/treetank/kompakt.git
$ /plugin install kompakt@kompakt-marketplace
Local install
$ claude --plugin-dir /path/to/kompakt
Kompakt uses Claude Code's PreCompact hook to inject custom instructions before summarization starts. No patching, no hacks — just the official hook system.
/compactThe PreCompact Hook
Claude Code supports PreCompact hooks — shell commands that run before /compact starts summarizing. Kompakt registers a single bash script that fires on every compaction:
{
"hooks": {
"PreCompact": [{
"matcher": "",
"hooks": [{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/precompact_inject.sh"
}]
}]
}
}Empty matcher means “trigger on every /compact”. CLAUDE_PLUGIN_ROOT is set by Claude Code to the plugin's install directory.
The Hidden Prompt Trick
Hook output normally shows up in your terminal. Nobody wants a wall of summarization instructions on every /compact. Kompakt solves this by exploiting how Claude Code wraps command output in <local-command-stdout> tags:
# The script outputs: </local-command-stdout> [your entire custom prompt here] <local-command-stdout>
The closing tag ends the visible output block. The prompt text lands between the tags — invisible in your terminal, but Claude still reads it. The opening tag resumes normal output. Result: Claude gets full instructions, you see nothing but hook completed successfully.
Prompt Resolution
The inject script checks for a custom prompt first, then falls back to the plugin's default template:
# Priority: 1. .claude/kompakt-prompt.md (project-level) 2. ~/.claude/kompakt-prompt.md (global) 3. templates/default-prompt.md (plugin fallback)
This means every project can have its own summarization style. The tengumail example above uses a project-level prompt with hardcoded context about active design docs — something that would make no sense as a global setting.
Why It Actually Works
Claude is resistant to prompt injections that try to manipulate its behavior. But Kompakt's instructions aren't adversarial — they align with what a good summary should do: preserve language, keep user messages intact, omit noise. Claude follows them because they make the output genuinely better, not because they trick it into something it wouldn't normally do.
kompakt default
Concise summaries focused on continuing work efficiently.
- ✓Language preserved
- ✓Verbatim user messages
- ✓No code snippets
- ✓~500-800 words
code
Like kompakt, but includes essential code snippets.
- ✓Language preserved
- ✓Verbatim user messages
- ✓Essential code included
- ✓~600-1000 words
planner
Decision-focused — preserves business plans verbatim.
- ✓Plan authority levels
- ✓Plan-reality drift detection
- ✓Minimal message history
- ✓Best for planning sessions
original
Claude's default detailed summarization style.
- ✗May switch language
- ✓All messages preserved
- ✓Full code snippets
- ✓~1000+ words
/kompakt:configMain configuration menu — change presets, prompt path, and logging settings/kompakt:presetQuick preset switch between kompakt, code, and original/kompakt:adjustInteractive property tuner — discovers quantifiable settings in your prompt and lets you tweak them/kompakt:logsConfigure logging — toggle debug output and view log files/kompakt:adjust is particularly interesting — it reads your current prompt, discovers tunable properties (summary length, code snippets, verbosity, context horizon), and lets you change them interactively without editing markdown by hand.
Create your own summarization prompt to get exactly the output format you want. Kompakt checks these locations in priority order:
.claude/kompakt-prompt.mdproject-specific~/.claude/kompakt-prompt.mdglobaltemplates/default-prompt.mdfallbackThis is an excerpt from an actual .claude/kompakt-prompt.md used in a production project. It shows how far you can take customization — from project-specific context that survives compaction to rules about how agent actions should be summarized.
# OVERRIDE SUMMARIZATION:
- NO code snippets
- NO English if user wrote in other language
- Preserve last user messages VERBATIM
- Brief action descriptions only
## PROJECT-SPECIFIC CONTEXT (hardcoded — survives compaction)
- **Active plan**: `docs/design/pipeline-executor-cleanup.md`
- **Design doc**: `docs/architecture/unified-execution-context.md`
- **MEMORY.md may be stale** — always verify against actual files
## Critical Rules
1. **Language**: Write summary in THE SAME LANGUAGE as the
user's messages. Even headings should match.
2. **Last user messages**: Include ALL user messages VERBATIM.
- **Screenshots/images**: Won't survive compaction.
Add: `> [screenshot: 404 error on /api/users]`
3. **Your actions**: Brief but SPECIFIC.
- BAD: "[Presented priorities]"
- GOOD: "[Recommended 30.9 Trial flow as quick win,
user chose to proceed]"
4. **Agent context horizon**: Temporal detail decay —
- Recent actions (last ~30%): Detailed
- Older actions (earlier ~70%): One-line outcome
- User messages: ALWAYS verbatim regardless of age
5. **Epistemic Humility Preface**: At the END, always:
⚠️ COMPACTION WARNING: This summary is lossy.
Do NOT trust interface shapes or file contents —
verify against actual files.
6. **Active Plan Preservation**: ALWAYS include:
- Plan document path
- Current step name and number
- What to do next after resumingKey ideas worth stealing: hardcoded project context that persists across compactions, temporal decay for agent actions (recent = detailed, older = compressed), epistemic humility warnings, and active plan preservation so the next session knows exactly where to resume.
Use Kompakt together with compaction-advisor for the best context management experience:
compaction-advisor
Shows when to compact — monitors token usage and warns before context window fills up.
Kompakt
Controls how compact works — custom prompt format, language preservation, verbatim messages.