context-optimization

context-optimization is a skill for Claude Code, Codex from bcastelino/agent-skills-kit. It costs 30 tokens per session (1,557 once invoked), scanned A, a copy of context-optimization, MIT.

A set of methods for fitting more useful information into an AI model’s limited context window, the amount of text it can consider at once.

In plain words
What is it for?
Use it to summarize older context, hide verbose tool output behind references, reuse cached computations, or split context into smaller parts.
Why use it?
It helps reduce token use, delays, and context-limit problems in long conversations, large documents, and long-running agent systems.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/bcastelino/agent-skills-kit/context-optimization
Any agent
npx skills add bcastelino/agent-skills-kit --skill context-optimization
Clone the repo
git clone --depth 1 https://github.com/bcastelino/agent-skills-kit

Made for: Claude Code, Codex.

Its marketplace also offers this one on its own, as the plugin context-optimization/plugin install context-optimization after adding the marketplace above.

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/bcastelino/agent-skills-kit/context-optimization.svg)](https://agentmods.dev/skills/bcastelino/agent-skills-kit/context-optimization)
Your own site
<a href="https://agentmods.dev/skills/bcastelino/agent-skills-kit/context-optimization"><img src="https://agentmods.dev/badge/skills/bcastelino/agent-skills-kit/context-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 30 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,557 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 98% 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 $0.00030 $0.01557
Opus 5 $0.00015 $0.00779
Sonnet 5 $0.00006 $0.00311
Haiku 4.5 $0.00003 $0.00156

Measured 5d ago against content hash 8e1444833ec6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 5d 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

98% identical to context-optimization — 10 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.

skills/context-optimization/SKILL.md · 185 lines

How it starts

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

When to Use This Skill

Apply compaction, masking, and caching strategies

Use this skill when working with apply compaction, masking, and caching strategies.

Context Optimization Techniques

Context optimization extends the effective capacity of limited context windows through strategic compression, masking, caching, and partitioning. The goal is not to magically increase context windows but to make better use of available capacity. Effective optimization can double or triple effective context capacity without requiring larger models or longer contexts.

When to Activate

Activate this skill when:

  • Context limits constrain task complexity
  • Optimizing for cost reduction (fewer tokens = lower costs)
  • Reducing latency for long conversations
  • Implementing long-running agent systems
  • Needing to handle larger documents or conversations
  • Building production systems at scale

Core Concepts

Context optimization extends effective capacity through four primary strategies: compaction (summarizing context near limits), observation masking (replacing verbose outputs with references), KV-cache optimization (reusing cached computations), and context partitioning (splitting work across isolated contexts).

The key insight is that context quality matters more than quantity. Optimization preserves signal while reducing noise. The art lies in selecting what to keep versus what to discard, and when to apply each technique.

Detailed Topics

Compaction Strategies

What is Compaction Compaction is the practice of summarizing context contents when approaching limits, then reinitializing a new context window with the summary. This distills the contents of a context window in a high-fidelity manner, enabling the agent to continue with minimal performance degradation.

Compaction typically serves as the first lever in context optimization. The art lies in selecting what to keep versus what to discard.

Compaction Implementation Compaction works by identifying sections that can be compressed, generating summaries that capture essential points, and replacing full content with summaries. Priority for compression goes to tool outputs (replace with summaries), old turns (summarize early conversation), retrieved docs (summarize if recent versions exist), and never compress system prompt.

Read the full file on GitHub · 185 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. 5d ago First seen · 185 lines · 30 tokens per session scan A 8e1444833ec6

Subscribe to this mod's changes

context-optimization is a skill published in the GitHub repository bcastelino/agent-skills-kit (2 stars, last pushed 1mo ago), licensed MIT. It adds 30 tokens to every session and 1,557 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. It is 98% identical to context-optimization, differing in 10 lines, and is treated as a copy.

Related

Other skills, from other repositories

agy-prompting

Internal helper — how to tighten a user request into a sharp prompt for the Antigravity CLI (agy / Gemini 3.x with native web search and agentic tools).

MarcosNahuel/antigravity-plugin-cc · 40 tokens

gemini-3-prompting

Guidance for writing effective prompts for Antigravity (agy) / Gemini 3 models.

Vit129/agy-plugin-cc · 26 tokens

gemini-proxy

Use when the operator wants their next prompts routed through Gemini before the agent acts — "enable gemini proxy", "route my prompts through Gemini", "Gemini rewrites my prompts", "включи гемини-прокладку", "переделывай мои промты через гемини", or a /gemini-proxy call; also when they ask to turn the protocol on for…

freestyler-arb/imagine-gemini-for-claude-codex · 120 tokens

agy-researcher

Delegate a deep research or survey task to Google's Antigravity CLI (agy staffer, fast Gemini). Use when the user says /skill:agy-researcher, "ask agy to research", "have the agy staffer survey X", or wants a second, independent deep-dive on a topic or codebase without spending the host model's quota.

keli-wen/agy-staff · 79 tokens

agy-staffer

Delegate a general-purpose task to Google's Antigravity CLI (agy staffer, fast Gemini) with a minimal, unopinionated prompt. Use when the user says /skill:agy-staffer, "have agy do/handle X", "have agy generate an image", or the task fits none of the specialist personas (researcher / reviewer / implementer / ask) …

keli-wen/agy-staff · 123 tokens

embedding-strategies

Select and optimize embedding models for semantic search and RAG applications. Use when choosing embedding models, implementing chunking strategies, or optimizing embedding quality for specific domains.

rmyndharis/antigravity-skills · 37 tokens