Agent skill

Context Compression

by seb1n in seb1n/awesome-ai-agent-skills

Compress selected context to a target token budget while preserving decisions, evidence, constraints, and unresolved questions.

MITAuto-check passedAI & LLM Engineering

Install Context Compression

skills CLI
$ npx skills add seb1n/awesome-ai-agent-skills --skill context-compression -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install seb1n/awesome-ai-agent-skills context-compression --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/seb1n/awesome-ai-agent-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/context-engineering/context-compression .claude/skills/context-compression && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
context-compression
GitHub stars
206
Token cost
~2.2k tokens
SKILL.md length
1,175 words
Files
1
Skills in repo
101
Repo updated
First seen
Licence
MIT

At a glance

Compress selected context to a target token budget while preserving decisions, evidence, constraints, and unresolved questions.

  • Works in 6 steps: Measure the Token Budget: Determine the… → Score Information Density: Analyze each… → Select a Compression Strategy: Choose… → …
  • Relevant material is already selected but too long
  • SKILL.md covers Workflow, Techniques, Usage and Examples, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Context Compression is an agent skill from seb1n/awesome-ai-agent-skills. Compress selected context to a target token budget while preserving decisions, evidence, constraints, and unresolved questions. Use when relevant material is already selected but too long; use context-optimization when selection, deduplication, and ordering are also required.

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in AI & LLM Engineering, covering LLM cost and token optimization, Context engineering and Data cleaning. The repository describes itself as: 103 ready-to-use AI agent skills for Claude Code, OpenAI Codex, Gemini CLI, Cursor, GitHub Copilot, Windsurf, and other Agent Skills-compatible tools. Complete SKILL.md… The licence is MIT.

When your agent uses it

  • Relevant material is already selected but too long
  • Use context-optimization when selection
  • Ordering are also required

Example prompts

  • “/context-compression”

Requirements

  • Python 3
  • Docker

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Measure the Token Budget: Determine the model's total context window (e.g., 4K, 32K, 128K tokens) and subtract the tokens reserved for the…
  2. Score Information Density: Analyze each paragraph, sentence, or chunk of the raw context and assign an information-density score based on…
  3. Select a Compression Strategy: Choose the most appropriate technique based on the compression ratio needed and the nature of the content
  4. Apply Compression: Execute the chosen strategy. For aggressive compression (>80% reduction), combine techniques — for example, first prune…
  5. Validate Information Retention: Compare the compressed output against the original to ensure no critical facts were lost. A quick…
  6. Assemble the Final Context: Insert the compressed text into the prompt in place of the raw context. Include a note to the model indicating…

What it can do on your machine

Read from SKILL.md and the folder at commit 75865a5. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Context Compression loads about 2.2k tokens when it runs. Until then it costs about 74 tokens; SKILL.md has 1,175 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~74
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from seb1n/awesome-ai-agent-skills at commit 75865a5, republished under its MIT licence (© seb1n). 1,175 words, ~2,248 tokens.

Download SKILL.mdSave it as .claude/skills/context-compression/SKILL.md (or your agent's skills folder).
name
context-compression
description
Compress selected context to a target token budget while preserving decisions, evidence, constraints, and unresolved questions. Use when relevant material is already selected but too long; use context-optimization when selection, deduplication, and ordering are also required.
license
MIT
metadata.author
awesome-ai-agent-skills
metadata.version
1.0.0

Context Compression

Context compression is the process of reducing the size of textual context provided to a language model while retaining the information most essential to the task. As conversations grow longer and retrieved documents grow larger, compression becomes critical for staying within token limits and keeping inference costs manageable without sacrificing answer quality.

Workflow

  1. Measure the Token Budget: Determine the model's total context window (e.g., 4K, 32K, 128K tokens) and subtract the tokens reserved for the system prompt, instructions, and the model's generation output. The remainder is your available context budget. If the raw context already fits, compression may be unnecessary.

  2. Score Information Density: Analyze each paragraph, sentence, or chunk of the raw context and assign an information-density score based on how many task-relevant facts it contains per token. Sentences that are purely stylistic, redundant, or off-topic receive low scores. This can be done heuristically (keyword overlap with the query) or via a lightweight classifier.

  3. Select a Compression Strategy: Choose the most appropriate technique based on the compression ratio needed and the nature of the content:

    • Extractive summarization — select the most important sentences verbatim.
    • Abstractive summarization — rewrite content in fewer words while preserving meaning.
    • Key-point extraction — pull out only named entities, facts, and figures.
    • Selective pruning — remove low-density sentences, boilerplate, and repeated information.
  4. Apply Compression: Execute the chosen strategy. For aggressive compression (>80% reduction), combine techniques — for example, first prune boilerplate, then abstractively summarize the remainder. For moderate compression (40–60%), extractive selection is often sufficient and avoids introducing paraphrasing errors.

  5. Validate Information Retention: Compare the compressed output against the original to ensure no critical facts were lost. A quick validation pass can check that key entities, numbers, and conclusions from the original are still present in the compressed version.

  6. Assemble the Final Context: Insert the compressed text into the prompt in place of the raw context. Include a note to the model indicating the context has been summarized, so it can calibrate its confidence accordingly.

Techniques

  • Extractive Summarization: Selects the top-n most important sentences from the source text based on relevance scoring. Preserves exact wording, which is important when precision matters (legal, medical, code). Tools: TextRank, LexRank, or LLM-based extraction.
  • Abstractive Summarization: Generates a new, shorter version of the text that captures the same meaning. Produces more natural and concise output but risks introducing inaccuracies. Best used with a reliable LLM and a validation step.
  • Key-Point Extraction: Reduces text to a structured list of facts, entities, and data points. Extremely space-efficient (often 90%+ compression) but loses narrative flow and nuance.
  • Selective Pruning: Removes filler sentences, repeated explanations, greetings, and boilerplate while keeping substantive content intact. Low risk of information loss and easy to implement with rule-based heuristics.
  • Token Budget Management: Dynamically allocate token budgets across multiple context sources. For example, in a RAG pipeline with 5 retrieved chunks, allocate more tokens to higher-relevance chunks and aggressively compress lower-relevance ones.

Usage

Provide the raw context text and a target token budget. The skill returns a compressed version of the text that fits within the budget. Optionally specify the compression strategy (extractive, abstractive, key-points, or auto) and a list of must-retain keywords or entities.

Examples

Example 1: Compressing a Document for a Q&A Task

Input (excerpt, ~800 tokens):

The Acme Corporation was founded in 1987 by Jane Doe in Austin, Texas. It started as a small consulting firm specializing in environmental compliance. Over the years, the company expanded into waste management technology, receiving its first patent in 1994 for an automated sorting system. By 2005, Acme had grown to 500 employees across 12 offices nationwide. The company went public in 2010 with an IPO price of $18 per share. In 2018, Acme acquired GreenTech Solutions for $240 million, adding recycling automation to its portfolio. As of 2024, Acme reports annual revenue of $1.2 billion and employs 3,400 people. The CEO since 2020 is Michael Chen, who previously served as CTO. Acme's headquarters relocated to Denver, Colorado in 2021. The company's mission statement emphasizes sustainable industrial practices and carbon-neutral operations by 2030.

Compressed Output (key-point extraction, ~150 tokens):

  • Acme Corporation: founded 1987 by Jane Doe, Austin TX; now HQ in Denver CO (relocated 2021)
  • Business: environmental compliance consulting → waste management tech → recycling automation
  • Key milestones: first patent 1994 (automated sorting), IPO 2010 ($18/share), acquired GreenTech Solutions 2018 ($240M)
  • Current: CEO Michael Chen (since 2020), 3,400 employees, $1.2B annual revenue
  • Goal: carbon-neutral operations by 2030
Show full SKILL.md (437 more words)Show less
Example 2: Compressing Conversation History

Input (long-running chat, ~3,000 tokens across 18 messages):

User asks about setting up a Python virtual environment. Agent explains venv creation, pip usage, and requirements.txt. User then asks about Docker containerization. Agent explains Dockerfiles, docker-compose, and volume mounts. User encounters a port-binding error. Agent helps debug by checking for conflicting processes. User resolves the issue. User then asks about deploying to AWS ECS.

Compressed Output (abstractive summary, ~400 tokens):

Conversation summary: The user is setting up a Python application with Docker and deploying to AWS. Key context:

  1. Python environment is configured with venv and requirements.txt (resolved).
  2. Docker setup uses a Dockerfile and docker-compose with volume mounts (resolved).
  3. A port-binding conflict on port 8080 was resolved by killing a conflicting process.
  4. Current topic: User is now asking about deploying the Dockerized Python app to AWS ECS. They have a working Docker setup locally and need guidance on ECS task definitions, service configuration, and load balancing.

Best Practices

  • Compress progressively — apply light pruning first, measure the result, then apply heavier techniques only if you still exceed the budget. This minimizes unnecessary information loss.
  • Preserve numbers and names — quantitative data, proper nouns, dates, and code identifiers are disproportionately important and should be retained even in aggressive compression.
  • Tag compressed context — always indicate to the model that the context has been compressed so it can appropriately hedge when details might have been lost.
  • Prefer extractive methods for code — abstractive summarization can introduce subtle errors in code snippets. Use extractive selection or selective pruning for technical content.
  • Keep the most recent turns — when compressing conversation history, preserve the last 2–3 turns verbatim and summarize earlier turns. Recency is a strong signal for relevance.
  • Measure information loss — after compression, check that answers to key questions about the content remain correct. If a fact is lost that the task depends on, the compression was too aggressive.

Edge Cases

  • Context already within budget: Skip compression entirely — unnecessary compression always loses some information. Only compress when the raw context exceeds available tokens.
  • Highly technical or structured content: Tables, JSON, and code blocks compress poorly with abstractive methods. Use selective pruning or extract only the relevant rows/fields rather than summarizing.
  • Multiple languages in context: Compression models may perform unevenly across languages. Compress each language segment independently or use a multilingual summarization model.
  • Critical safety information: Never compress away safety warnings, legal disclaimers, or medical dosage information. Mark these as must-retain before applying any compression.
  • Near-budget context: If the context is only 10–15% over budget, simple pruning of whitespace, boilerplate headers, and duplicate sentences is safer than full summarization.

© seb1n, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in context-engineering/context-compression of seb1n/awesome-ai-agent-skills.

Open the folder on GitHubat commit 75865a5

Compare with similar skills

Context Compression next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Context Compression compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Context Compression this skillseb1n/awesome-ai-agent-skills206—~2.2kAutomated safety check: PassMIT
Cco Budgetegorfedorov/claude-context-optimizer114—~808Automated safety check: PassMIT
Openrouter Context Optimizationjeremylongshore/tons-of-skills-marketplace2.8k—~2.4kAutomated safety check: PassMIT
Context Engineering Reviewmohitagw15856/pm-claude-skills1.4k—~1.4kAutomated safety check: PassMIT
Agents Best PracticesDenisSergeevitch/agents-best-practices2.4k—~7.4kAutomated safety check: PassMIT
OmniRoute RTK Context Filtersdiegosouzapw/OmniRoute74k—~618Automated safety check: PassMIT

Similar skills

  • Cco Budget

    egorfedorov/claude-context-optimizer

    Configure token budget limits, auto-compact settings, and view current budget status (model-aware — Claude 5 lineup, Opus 5.5 default fallback, full 1M context at standard price)

    114 GitHub stars~808 tokensUpdated 9 days ago
    AI & LLM EngineeringAuto-check passed
  • Openrouter Context Optimization

    jeremylongshore/tons-of-skills-marketplace

    Optimize context window usage for OpenRouter models to reduce cost and improve quality.

    2.8k GitHub stars~2.4k tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • Context Engineering Review

    mohitagw15856/pm-claude-skills

    Review what an LLM feature or agent actually puts in its context window — and find what's bloating, missing, or fighting itself.

    1.4k GitHub stars~1.4k tokensUpdated yesterday
    AI & LLM EngineeringAuto-check passed
  • Agents Best Practices

    DenisSergeevitch/agents-best-practices

    A skill your agent uses when designing, generating an MVP blueprint for, auditing, troubleshooting, refactoring, or explaining an agentic harness for any domain.

    2.4k GitHub stars~7.4k tokensUpdated 4 days ago
    AI & LLM EngineeringAuto-check passed
  • OmniRoute RTK Context Filters

    diegosouzapw/OmniRoute

    Controls the RTK filter set and context-handling settings in OmniRoute, with endpoints to try compression on sample text and read back retained output.

    74k GitHub stars~618 tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • Token Optimization

    cwinvestments/memstack

    A skill your agent uses when the user says 'token optimization', 'save tokens', 'context window', 'reduce tokens', 'token stack', or 'TokenStack', or asks about extending context window capacity.

    423 GitHub stars~1.4k tokensUpdated 12 days ago
    AI & LLM EngineeringAuto-check passed

More from seb1n/awesome-ai-agent-skills

All 101 skills in this repo
  • Agent Red Teaming

    seb1n/awesome-ai-agent-skills

    Plan, execute, document, and retest authorized security assessments of AI agents and multi-agent workflows using safe adversarial cases, synthetic identities, canaries, and evidence-based findings.

    206 GitHub stars~2.8k tokensUpdated 2 mo ago
    Auto-check passed
  • Eu AI Act Readiness

    seb1n/awesome-ai-agent-skills

    Build a preliminary, evidence-based EU AI Act readiness assessment across AI-system inventory, territorial scope, operator roles, prohibited-practice screening, risk classification, transparency…

    206 GitHub stars~3.3k tokensUpdated 2 mo ago
    Auto-check passed
  • Human In The Loop

    seb1n/awesome-ai-agent-skills

    Design and verify auditable human oversight, approval gates, escalation paths, and safe state transitions for AI agent workflows.

    206 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed
  • MCP Server Building

    seb1n/awesome-ai-agent-skills

    Design, implement, harden, and verify Model Context Protocol (MCP) servers with precise tool contracts, least-privilege authorization, safe transports, structured errors, and interoperability tests.

    206 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed
  • PDF Processing

    seb1n/awesome-ai-agent-skills

    Inspect, extract, OCR, create, merge, split, reorder, rotate, annotate, fill, redact, compress, secure, and verify PDF documents while preserving source files and visual fidelity.

    206 GitHub stars~2.5k tokensUpdated 2 mo ago
    Auto-check passed
  • Skill Supply Chain Audit

    seb1n/awesome-ai-agent-skills

    Audit agent skills, plugins, prompts, manifests, scripts, dependencies, and bundled assets for provenance, prompt-injection, permission, execution, exfiltration, persistence, and update risk.

    206 GitHub stars~2.4k tokensUpdated 2 mo ago
    Auto-check passed

Questions about Context Compression

What does Context Compression do?

Compress selected context to a target token budget while preserving decisions, evidence, constraints, and unresolved questions. Context Compression is an agent skill from seb1n/awesome-ai-agent-skills. Compress selected context to a target token budget while preserving decisions, evidence, constraints, and unresolved questions.

When should I use Context Compression?

Context Compression fits situations like: relevant material is already selected but too long; use context-optimization when selection; ordering are also required.

How do I install Context Compression in Claude Code?

Run `npx skills add seb1n/awesome-ai-agent-skills --skill context-compression -a claude-code`. Or copy the skill folder (context-engineering/context-compression in seb1n/awesome-ai-agent-skills) into .claude/skills/context-compression in your project. Claude Code loads it when a task matches its description.

How do I install Context Compression in Codex?

Run `npx skills add seb1n/awesome-ai-agent-skills --skill context-compression -a codex`. Or copy the skill folder (context-engineering/context-compression in seb1n/awesome-ai-agent-skills) into .agents/skills/context-compression in your project. Codex loads it when a task matches its description.

Can I use Context Compression in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add seb1n/awesome-ai-agent-skills --skill context-compression -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/context-compression, .gemini/skills/context-compression, .github/skills/context-compression and .opencode/skills/context-compression in your project.

What does Context Compression need to run?

SKILL.md names no scripts, command-line tools or credentials: Context Compression is instructions for the agent only. Our summary lists: Python 3; Docker.

Does Context Compression access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Context Compression safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Context Compression use?

Context Compression is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Context Compression use?

About 2.2k tokens (SKILL.md is roughly 9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Context Compression?

Skills that share tags, products or a category with Context Compression: Cco Budget (egorfedorov/claude-context-optimizer, 114 stars), Openrouter Context Optimization (jeremylongshore/tons-of-skills-marketplace, 2.8k stars), Context Engineering Review (mohitagw15856/pm-claude-skills, 1.4k stars) and Agents Best Practices (DenisSergeevitch/agents-best-practices, 2.4k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Context Compression?

seb1n (a GitHub user) maintains it in seb1n/awesome-ai-agent-skills, which has 206 GitHub stars. The repository holds 101 skills in this directory. The repository was last updated on August 9, 2026.

Source: seb1n/awesome-ai-agent-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.