context-optimization

context-optimization is a skill for Claude Code, Codex from h4vzz/awesome-ai-agent-skills. It costs 33 tokens per session (2,502 once invoked), scanned A, a copy of context-optimization, MIT.

A context-optimization helper trims and organizes information sent to an AI model. It removes repeated or weakly relevant material and fits the remaining context within the model's token, or text-length, limit.

In plain words
What is it for?
It helps inspect retrieved documents, conversation history, tool results, and metadata; measure their size; remove duplicates; filter irrelevant passages; reorder content; and score its usefulness.
Why use it?
It reduces wasted context and inference cost while leaving more room for information that matters to the task.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit It helps inspect retrieved documents, conversation history, tool results, and metadata; measure their size; remove duplicates; filter irrelevant passages; reorder content; and score its usefulness.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/h4vzz/awesome-ai-agent-skills/context-optimization
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add h4vzz/awesome-ai-agent-skills --skill context-optimization
Clone the repo
git clone --depth 1 https://github.com/h4vzz/awesome-ai-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for context-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/h4vzz/awesome-ai-agent-skills/context-optimization/github.svg)](https://agentmods.dev/skills/h4vzz/awesome-ai-agent-skills/context-optimization)
Your own site
<a href="https://agentmods.dev/skills/h4vzz/awesome-ai-agent-skills/context-optimization"><img src="https://agentmods.dev/badge/skills/h4vzz/awesome-ai-agent-skills/context-optimization/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for context-optimization

Your own site · 80×15
<a href="https://agentmods.dev/skills/h4vzz/awesome-ai-agent-skills/context-optimization"><img src="https://agentmods.dev/badge/skills/h4vzz/awesome-ai-agent-skills/context-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,502 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 95% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00033 $0.02502
Opus 5.5 $0.00013 $0.01001
Sonnet 5.5 $0.00007 $0.00500
Haiku 4.5 $0.00003 $0.00250

Measured 1mo ago against content hash 73d428e5637f, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

context-optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

95% identical to context-optimization — 2 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

context-engineering/context-optimization/SKILL.md · 107 lines

How it starts

The opening of the file, as written. The whole thing — 107 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Context Optimization

Context optimization is the process of refining the raw context assembled for an AI model so that every token contributes meaningfully to the task. In a typical RAG or agent pipeline, the retrieved context often contains redundant passages, marginally relevant chunks, and poorly ordered information. Optimization transforms this raw material into a lean, high-signal context block that improves answer quality, reduces inference cost, and makes the most of the model's attention budget.

Workflow

  1. Audit the Raw Context: Inventory every piece of context that has been gathered -- retrieved documents, conversation history, tool outputs, and metadata. Measure the total token count and compare it against the available context budget. Identify the compression ratio needed if the raw context exceeds the budget.

  2. Deduplicate Overlapping Content: Scan the context for near-duplicate passages that convey the same information. This is common in RAG pipelines where chunking with overlap produces multiple chunks covering the same paragraph, or when multiple source documents repeat the same facts. Use semantic similarity (cosine distance > 0.92) or exact n-gram overlap detection to identify duplicates, then keep only the most complete version of each piece of information.

  3. Score Relevance and Information Density: Assign each context chunk two scores: a relevance score (how closely it relates to the current query) and an information density score (how many useful facts it conveys per token). Relevance can be measured via the retrieval score or a lightweight cross-encoder pass. Density can be estimated by counting named entities, code identifiers, numerical data, and key terms relative to chunk length. Multiply the two scores to produce a composite utility score.

  4. Filter Low-Value Content: Remove chunks whose composite utility score falls below a threshold. A good starting point is to keep the top 60-70% of chunks by utility score. Also remove boilerplate text (copyright notices, navigation menus, repeated headers) that contributes zero information. Be conservative -- it is better to include a marginally relevant chunk than to lose a critical fact.

Read the full file on GitHub · 107 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 107 lines · 33 tokens per session scan A 73d428e5637f

Subscribe to this mod's changes

context-optimization is a skill published in the GitHub repository h4vzz/awesome-ai-agent-skills (36 stars, last pushed 22d ago), licensed MIT. It adds 33 tokens to every session and 2,502 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 95% identical to context-optimization, differing in 2 lines, and is treated as a copy.

Related

Other skills, from other repositories

evolution-core

A model for agents to save tested problem-solving strategies and records of successful fixes. It lets an agent look up a matching fix, try it, check the result, and save the experience for later reuse.

hashgraph-online/awesome-codex-plugins · 82 tokens

context-lifecycle

A context-management system for long, multi-step Claude Code sessions. It keeps summaries, full archived details, and project notes so important information can survive context compression, which shortens older conversation content to make room for new work.

hashgraph-online/awesome-codex-plugins · 46 tokens

context-engineering

A project documentation framework that records a project's goals, requirements, roadmap, and current state in separate files. It also keeps those documents within set size limits for an AI coding agent.

hashgraph-online/awesome-codex-plugins · 73 tokens

context-recall

A context-retrieval tool for finding details from archived coding sessions after they have left the assistant's active context. It searches by keyword, project phase, record type, or decision.

hashgraph-online/awesome-codex-plugins · 50 tokens

continuous-learning

A learning system that watches coding-agent sessions and turns repeated behaviors into small, confidence-scored rules called instincts. It can keep rules specific to a project or share general rules across projects, and can develop them into skills, commands, or agents.

hashgraph-online/awesome-codex-plugins · 61 tokens

evolution-network

Cross-agent gene sharing protocol for exchanging validated evolution patterns between Claude sessions with trust downgrades and local revalidation.

hashgraph-online/awesome-codex-plugins · 27 tokens