context-anchoring
# Context Anchoring System
What this skill does
# Context Anchoring System
Preserve critical information across `/compact` events, session boundaries, and agent handoffs.
Context anchoring ensures your most important rules, decisions, and state survive compression.
## What Survives Compaction
```
┌─────────────────────────────────────────────────┐
│ ANCHORED (survives /compact) │
│ │
│ CLAUDE.md ← Full file, re-injected │
│ .claude/rules/* ← All matching rules reloaded │
│ MEMORY.md ← First 200 lines reloaded │
│ Session metadata ← Project path, git, env │
│ │
├─────────────────────────────────────────────────┤
│ NOT ANCHORED (summarized away) │
│ │
│ Conversation turns ← Compressed to summary │
│ Tool outputs ← Discarded or summarized │
│ MEMORY.md >200 lines ← Not auto-loaded │
│ Inline instructions ← Lost after compact │
│ Variable state ← Gone unless saved │
│ │
└─────────────────────────────────────────────────┘
```
## Anchoring Mechanisms
### Mechanism 1: CLAUDE.md (Strongest Anchor)
CLAUDE.md is the **strongest anchor** — fully re-injected after every compaction.
```markdown
# CLAUDE.md — Use for critical, must-not-forget rules
## Build Commands (ANCHORED)
- Install: `pnpm install`
- Test: `pnpm test`
## Architecture Decisions (ANCHORED)
- Always use Context7 before making library decisions
- All agent outputs must be audited before acceptance
```
**Best practice**: Keep CLAUDE.md under 200 lines. Every line has weight because it's always loaded.
### Mechanism 2: Rules Files (Path-Scoped Anchors)
Files in `.claude/rules/` are loaded for matching file types. They survive compaction because they're re-injected from disk, not from conversation history.
```
.claude/rules/
├── architecture.md ← Global anchor (always loaded)
├── code-style.md ← Loaded when editing *.ts, *.tsx
├── git-workflow.md ← Global anchor (always loaded)
├── lessons-learned.md ← Global anchor (always loaded)
└── research.md ← Global anchor (always loaded)
```
**Best practice**: Put critical patterns in global rules files (no `paths:` frontmatter). These are always active regardless of what files Claude is working on.
### Mechanism 3: MEMORY.md (200-Line Anchor)
Auto-memory is re-injected after compaction, but only the first 200 lines.
```markdown
# MEMORY.md — Keep under 200 lines
## Critical State (lines 1-50) — ALWAYS LOADED
- Current sprint goal: {goal}
- Active branch: {branch}
- Key decisions: {list}
## Index (lines 51-200) — ALWAYS LOADED
- [Debugging patterns](debugging.md)
- [API conventions](api-conventions.md)
- [Architecture decisions](architecture.md)
## Overflow (lines 201+) — NOT AUTO-LOADED
<!-- Move detailed content to topic files -->
```
**Best practice**: Treat MEMORY.md as an index. Put details in topic files.
### Mechanism 4: PreCompact Hook (State Capture)
Save critical state before compaction happens.
```json
{
"hooks": {
"PreCompact": [{
"matcher": "",
"hooks": [{
"type": "command",
"command": "bash .claude/hooks/anchor-state.sh"
}]
}]
}
}
```
```bash
#!/bin/bash
# .claude/hooks/anchor-state.sh
# Save state to a file that Claude can read after compaction
INPUT=$(cat)
# Save current git state
{
echo "## Anchored State ($(date -u +%Y-%m-%dT%H:%M:%SZ))"
echo ""
echo "### Git State"
echo "- Branch: $(git branch --show-current 2>/dev/null)"
echo "- Modified: $(git diff --name-only 2>/dev/null | wc -l) files"
echo "- Staged: $(git diff --cached --name-only 2>/dev/null | wc -l) files"
echo ""
echo "### Recent Changes"
git diff --stat 2>/dev/null | tail -5
} > .claude/anchored-state.md 2>/dev/null
echo "Anchored state saved to .claude/anchored-state.md" >&2
```
### Mechanism 5: PostCompact Hook (State Recovery)
Re-inject critical context after compaction completes.
```bash
#!/bin/bash
# .claude/hooks/recover-state.sh
# Remind Claude about anchored state after compaction
if [ -f ".claude/anchored-state.md" ]; then
echo "Anchored state available at .claude/anchored-state.md — read it to restore context" >&2
fi
```
### Mechanism 6: Anchor Tags in Rules Files
Use explicit anchor markers in rules files to flag critical content:
```markdown
# .claude/rules/architecture.md
<!-- ANCHOR: critical-patterns -->
## Critical Patterns (Must Not Forget)
- All agent outputs must be audited before acceptance
- Use Context7 before any library/framework decisions
- Perplexity for knowledge queries, Firecrawl for extraction
- Never deploy without running full test suite
<!-- /ANCHOR -->
## Non-Critical Guidelines
- Prefer functional style over OOP
- Use 2-space indentation
```
## Anchoring Strategy by Information Type
| Information | Anchor Location | Survives Compact? |
|-------------|----------------|-------------------|
| Build commands | CLAUDE.md | Yes (always) |
| Code conventions | `.claude/rules/code-style.md` | Yes (when editing code) |
| Architecture decisions | `.claude/rules/architecture.md` | Yes (always) |
| Error patterns | `.claude/rules/lessons-learned.md` | Yes (always) |
| Git workflow | `.claude/rules/git-workflow.md` | Yes (always) |
| Current task state | PreCompact hook → file | Yes (if saved) |
| User preferences | MEMORY.md (first 200 lines) | Yes |
| Session history | Conversation | No (summarized) |
| Tool outputs | Conversation | No (discarded) |
| Inline instructions | Conversation | No (lost) |
## Cross-Agent Anchoring
When agents hand off work, critical context must be anchored:
### Agent-to-Agent State Transfer
```yaml
handoff_protocol:
before_handoff:
- Save findings to a shared file (.claude/handoff-state.md)
- Include: task, findings, decisions, open questions
- Format: structured markdown with clear sections
receiving_agent:
- Read .claude/handoff-state.md before starting work
- Inherit: decisions and constraints from previous agent
- Continue: from where previous agent left off
after_handoff:
- Delete temporary handoff file
- Update MEMORY.md with key decisions
```
### Orchestrator Anchor Pattern
The orchestrator maintains a persistent state file:
```markdown
# .claude/orchestration-state.md (updated by orchestrator)
## Active Task: {description}
## Agents Spawned: [{id, type, status}]
## Audit Status: {pass/fail/pending for each agent}
## Key Decisions: [{decision, rationale}]
## Open Questions: [{question, who should answer}]
<!-- Updated after each agent completes -->
<!-- Read by orchestrator after any /compact event -->
```
## Anchoring for Long Sessions
For sessions that will hit compaction multiple times:
### Progressive Anchoring
```
Session Start
├─ CLAUDE.md loaded (anchor)
├─ Rules loaded (anchor)
├─ MEMORY.md loaded (anchor)
│
├─ Phase 1: Research
│ └─ Save findings → .claude/rules/memory-sessions.md
│
├─ /compact (auto or manual)
│ ├─ PreCompact: save state → .claude/anchored-state.md
│ ├─ Compression: conversation summarized
│ ├─ PostCompact: remind about anchored state
│ └─ Re-inject: CLAUDE.md + rules + MEMORY.md
│
├─ Phase 2: Implementation
│ └─ Key decisions → MEMORY.md or rules file
│
├─ /compact (again)
│ └─ Same cycle — all anchored content persists
│
└─ Session End
└─ Final state → MEMORY.md for next session
```
### Anchor Budget
Keep total anchored content under these limits for optimal performance:
| Anchor | Max Size | Tokens |
|--------|----------|--------|
| CLAUDE.md | 200 lines | ~3,000 |
| Rules (global) | 500 lines total | ~8,000 |
| Rules (scoped) | 200 lines per file | ~3,000 |
| MEMORY.md | 200 lines | ~3,000 |
| **Total always-loaded** | | **~17,000** |
**Rule of thumb**: If total anchored content exceedRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.