agentleFS
irfad7irfad7/claude-power-skills/skills/context-compression/SKILL.md

context-compression

Skill4 starsChanged 8 months agoMITView on GitHub

When conversation context is getting long, when approaching token limits, when the user says "compress," "summarize context," "too long," "running out of context," "compact," or when you notice degraded performance due to context length. Implements a 3-layer compression pipeline (MicroCompact, AutoCompact, Full Compact).

16 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use bdi-mental-states, hosted-agents and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Downey6689Skill

    bdi-mental-states

    Transforms external RDF context into BDI mental states. Invoke when modeling beliefs, desires, and intentions.

    Also in 3 projects that use this

  • Downey6689Skill

    hosted-agents

    Guidance for hosted/sandboxed agents. Invoke when running background agents in isolated VMs or multi-client setups.

    Also in 3 projects that use this

  • Svenja-devSkill

    project-development

    Design and build LLM-powered projects from ideation through deployment. Use when starting new agent projects, choosing between LLM and traditional approaches, or structuring batch processing pipelines.

    Also in 3 projects that use this

  • +1 more from Downey6689

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 12 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 14 edited versions we read keep these.

  • 12

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before a complex multi-step task that needs headroom

    line 19
  2. Distinctive:

    Goal: Remove noise without losing any information.

    line 24
  3. Distinctive:

    Remove failed attempts that were superseded by successful ones

    line 29
  4. Distinctive:

    Remove conversational filler ("Let me think about this...", "Great question...")

    line 31
  5. Distinctive:

    No code snippets — just file paths

    line 81
  6. Distinctive:

    No exploration history — just conclusions

    line 82
  7. Distinctive:

    When triggered, assess which layer is appropriate:

    line 89
  8. Distinctive:

    After compression, present the compressed context to the user:

    line 101
  9. Distinctive:

    Never compress away: user decisions, architectural choices, active task state, error patterns that haven't been resolved

    line 120
  10. Distinctive:

    Always compress away: greetings, confirmations, exploration that led nowhere, superseded attempts

    line 121
  11. Distinctive:

    When in doubt, keep it in Layer 1/2 and let the user decide

    line 122
  12. Distinctive:

    After compression, re-read any critical files to refresh your understanding

    line 123

“Common” is measured: kept by at least 6 in 10 of the 14 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Context Compression — 3-Layer Pipeline

You are a context compression engine. When conversations grow long, you systematically reduce context size while preserving all decision-critical information.

When To Trigger

  • Conversation exceeds ~50 turns
  • User mentions context is getting long or responses are degrading
  • You notice you're losing track of earlier decisions
  • User explicitly asks for compression
  • Before a complex multi-step task that needs headroom

The Three Layers

Layer 1: MicroCompact (Light Touch)

Goal: Remove noise without losing any information.

Do this:

  • Strip redundant confirmations ("Yes, that looks good", "Sure, I'll do that")
  • Collapse repeated tool outputs into summaries ("Read 12 files — all TypeScript, avg 200 lines")
  • Remove failed attempts that were superseded by successful ones
  • Collapse verbose error messages into one-line summaries
  • Remove conversational filler ("Let me think about this...", "Great question...")

Compression ratio: ~30-40% reduction Information loss: Zero

Layer 2: AutoCompact (Structural)

Goal: Restructure retained information for density.

Do this:

  • Convert sequential discoveries into a structured summary:
    ## What We Know
    - The API uses Express with 14 endpoints
    - Auth is JWT-based, tokens expire in 24h
    - Database is Postgres via Drizzle ORM
    - Tests use Vitest, 73% coverage
    
    ## Decisions Made
    - Using server components by default
    - API routes return { data } or { error }
    - Commit style: conventional commits
    
    ## Current Task
    - Building the user dashboard
    - Blocked on: auth middleware refactor
    - Next step: implement session management
  • Group related file reads into summaries
  • Merge multiple rounds of the same type of work into outcomes
  • Replace code snippets with references ("see src/auth.ts:45-67")

Compression ratio: ~60-70% reduction Information loss: Minimal — details available via file re-reads

Layer 3: Full Compact (Aggressive)

Goal: Maximum compression. Only essential state survives.

Do this:

  • Reduce to three sections only:
    ## State
    [What exists right now — files created/modified, current branch, build status]
    
    ## Intent
    [What the user wants to achieve — the goal, not the steps]
    
    ## Constraints
    [Critical decisions, patterns, rules that must be followed]
  • Everything else is discardable and can be re-derived from the codebase
  • No code snippets — just file paths
  • No exploration history — just conclusions

Compression ratio: ~85-90% reduction Information loss: Moderate — but all recoverable from codebase

How To Apply

When triggered, assess which layer is appropriate:

SituationLayer
"Getting long but still fine"Layer 1
"Losing context, need clarity"Layer 2
"About to hit limits, need maximum headroom"Layer 3
User says "compact" or "compress"Layer 2 (default)
User says "hard compress" or "nuke context"Layer 3

Output

After compression, present the compressed context to the user:

Context compressed (Layer [N]):
- Before: ~[X] turns, ~[Y]k tokens (estimated)
- After: ~[Z]k tokens (estimated)
- Preserved: [list key items kept]
- Dropped: [list what was removed]

Compressed context follows:
---
[compressed context block]
---

Does this capture everything important? Anything I should keep that I dropped?

Rules

  • Never compress away: user decisions, architectural choices, active task state, error patterns that haven't been resolved
  • Always compress away: greetings, confirmations, exploration that led nowhere, superseded attempts
  • When in doubt, keep it in Layer 1/2 and let the user decide
  • After compression, re-read any critical files to refresh your understanding
  • Flag if compression might lose something important: "I'm about to drop [X] — should I keep it?"

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.