Claude Anchor
rodrigooler/claude-anchor
Preserva contexto essencial em compactações do Claude Code automaticamente
Ver no GitHubPlugin que preserva contexto crítico durante compactações no Claude Code, evitando perda de caminhos de arquivos, mensagens de erro e decisões importantes. Funciona via hooks de pré e pós-compactação, mantendo um arquivo de regras persistentes que sobrevive a cada ciclo.
Instalação
npx convez-ai rodrigooler/claude-anchor1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.
Métricas
Casos de uso
- Sessões longas de codificação sem perder histórico de decisões
- Manutenção de convenções de projeto durante múltiplas compactações
- Retenção de caminhos de arquivo e mensagens de erro específicas
- Preservação de preferências de ferramentas e correções do usuário
Veredito

Solução prática para um problema real do Claude Code: degradação de contexto em sessões longas. A abordagem via hooks estruturados é robusta e o arquivo anchor-context.md oferece controle fino sobre o que preservar. Recomendado para projetos complexos com múltiplas compactações.
README
A tradução para o português deste README ainda está na fila.
⚓ claude-anchor
Stop losing context on every /compact. Claude Anchor preserves what matters.
One-line install. Zero configuration. Works with every Claude Code project.
The problem
Claude Code's built-in /compact treats all context equally — summarizing file paths, error messages, and hard-won decisions with the same blunt force as tool output noise. After a few compactions in a long session, you're re-reading files you already analyzed and re-discovering bugs you already fixed.
What actually gets lost:
- Exact file paths (paraphrased to "the config file")
- Error messages and root causes (summarized away)
- Decisions and their rationale (the WHY disappears)
- User corrections and preferences (reset each compaction)
How it works
Claude Anchor hooks into Claude Code's PreCompact and PostCompact lifecycle events:
/compact triggered
│
▼
PreCompact hook ──► Tells Claude what to preserve verbatim in the summary
│ (file paths, errors, decisions, corrections)
▼
Summary generated ──► Better quality, structured retention
│
▼
PostCompact hook ──► Re-injects your ~/.claude/anchor-context.md rules
│
▼
Session continues ──► Context intact
It also sets CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=85, so compaction triggers at 85% capacity instead of the default — before context quality starts degrading.
Research basis: Factory.ai evaluated context compression strategies across 36,000 real agent sessions. Structured, instruction-driven summarization scored 8% higher on context retention vs. the default Anthropic approach. The gap widens with multiple compaction cycles. (source)
Install
Option A — Claude Code plugin (recommended: discoverable, auto-updates):
claude plugins marketplace add rodrigooler/claude-anchor
claude plugins install anchor
Then run /anchor install once to activate the hooks.
Option B — One-liner curl (no plugin system needed):
curl -fsSL https://raw.githubusercontent.com/rodrigooler/claude-anchor/main/install.sh | bash
Custom threshold (e.g. for 1M-context Opus models):
CLAUDE_ANCHOR_PCT=65 curl -fsSL https://raw.githubusercontent.com/rodrigooler/claude-anchor/main/install.sh | bash
What gets installed
| Component | Location | Purpose |
|---|---|---|
anchor-pre-compact.sh | ~/.claude/hooks/ | Instructs summarization before compact |
anchor-post-compact.sh | ~/.claude/hooks/ | Re-injects your persistent rules after compact |
anchor-context.md | ~/.claude/ | Your custom rules that survive every compaction |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE | ~/.claude/settings.json env | Compact threshold (default: 85%) |
The anchor-context.md file
After install, ~/.claude/anchor-context.md is created with a template. Add anything here that should survive compaction:
# Anchor Context
## Tool preferences
- Always use ripgrep over grep
- Prefer TypeScript strict mode
## Project conventions
- Money values in cents (never floats)
- All IDs are UUIDs
## Ongoing work
- Refactoring auth module — do not touch adjacent files
Every time Claude Code compacts, this file is re-injected automatically.
Uninstall
curl -fsSL https://raw.githubusercontent.com/rodrigooler/claude-anchor/main/uninstall.sh | bash
Or if you installed locally:
bash uninstall.sh
How it compares
Default /compact | claude-anchor | |
|---|---|---|
| File paths | Paraphrased or dropped | Preserved verbatim |
| Error messages | Summarized | Preserved verbatim |
| Decision rationale | Lost | Preserved with WHY |
| User corrections | Reset | Re-injected via context file |
| Compact timing | ~83% capacity | Configurable (default 85%) |
| Persistent rules | None | ~/.claude/anchor-context.md |
| Setup | Built-in | One curl command |
Configuration
All configuration is optional. The defaults work well for most setups.
| Variable | Default | Description |
|---|---|---|
CLAUDE_ANCHOR_PCT | 85 | Compact threshold % (set during install) |
To change the threshold after install, edit ~/.claude/settings.json:
{
"env": {
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "90"
}
}
Threshold guidance:
200K context models(Sonnet): 85–92% → triggers at 170K–184K tokens1M context models(Opus): 60–70% → triggers at 600K–700K tokens
Contributing
See CONTRIBUTING.md. PRs welcome — especially:
- Additional hook templates for specific workflows (coding, writing, research)
- Better
anchor-context.mdexamples for different use cases - Shell completion for the
/anchorskill
License
MIT — Rodrigo Oler