context-optimization

context-optimization is a skill for Claude Code, Codex from VoDaiLocz/kilo-kit-mcp. It costs 45 tokens per session (869 once invoked), scanned A, original, Apache-2.0.

Guidance for managing the amount and arrangement of information sent to language-model agents. It covers prompt caching, token costs, context windows, and compact representations of code.

In plain words
What is it for?
Use it when designing prompts or agent workflows that need semantic pruning, token-budget control, cache-friendly ordering, or summarized code structures.
Why use it?
It helps reduce unnecessary context, preserve useful information, and make repeated agent interactions more efficient.

Skill for Claude CodeCodex

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

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/vodailocz/kilo-kit-mcp/context-optimization
Any agent
npx skills add VoDaiLocz/kilo-kit-mcp --skill context-optimization
Clone the repo
git clone --depth 1 https://github.com/VoDaiLocz/kilo-kit-mcp

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/vodailocz/kilo-kit-mcp/context-optimization.svg)](https://agentmods.dev/skills/vodailocz/kilo-kit-mcp/context-optimization)
Your own site
<a href="https://agentmods.dev/skills/vodailocz/kilo-kit-mcp/context-optimization"><img src="https://agentmods.dev/badge/skills/vodailocz/kilo-kit-mcp/context-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 45 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 869 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found 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.00045 $0.00869
Opus 5 $0.00023 $0.00434
Sonnet 5 $0.00009 $0.00174
Haiku 4.5 $0.00005 $0.00087

Measured 6d ago against content hash a5fcdfaa867d, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, 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 6d 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.

skills/engineering/context-optimization/SKILL.md · 82 lines

How it starts

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

Context Optimization Skill

This skill provides methodologies and best practices for maximizing context window efficiency, reducing token costs, and improving the performance of LLM-based agentic workflows.

1. Prompt Cache Alignment

To maximize Key-Value (KV) cache hits, prioritize stability in the early parts of the prompt.

  • Static Prefixes: Design system prompts to remain identical across agent turns.
  • Tool Order: Sort tool definitions alphabetically or by frequency of use. Keep this ordering constant.
  • Prefix Consistency: Reserve the top 70% of the KV cache for global system instructions and tool definitions.
  • Avoid Dynamic Data: Move dynamic session-specific data (dates, current file list) to the end of the context window.

2. Semantic Pruning & AST Compaction

Reduce unnecessary data before sending it to the model.

  • Removal of Non-Essentials: Strip comments, debug logs, and unused boilerplate code.
  • AST Compaction: Convert deep code structures into simplified, representative summaries or pseudocode.
  • Whitespace Stripping: Use minification for configuration files (JSON, YAML) and standard code.
  • Irrelevant Body Dropping: Replace large, irrelevant function bodies with docstrings or signatures if the model doesn't need to reason about the implementation details.

3. Lost-in-the-Middle Mitigation

LLMs often suffer from recall degradation for information in the center of the context window.

  • Boundary Priority: Place high-priority constraints, critical instructions, and schema definitions at the very beginning (Head) or the very end (Tail) of the context.
  • Sandwich Strategy: If critical information must be in the middle, sandwich it between two clear, high-level summary points that repeat its purpose.

4. Sliding Windows & Recursive Summarization

Manage long-running conversations without exceeding token thresholds.

  • Sliding Window: Keep only the N most recent turns for immediate interaction.
  • Recursive Summarization: Periodically collapse historical turns into a compressed "Session State Summary".
  • State Archiving: Store older, less relevant interactions in a side-car file (e.g., archive.md) that the agent can read only when necessary.

Read the full file on GitHub · 82 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. 6d ago First seen · 82 lines · 45 tokens per session scan A a5fcdfaa867d

Subscribe to this mod's changes

context-optimization is a skill published in the GitHub repository VoDaiLocz/kilo-kit-mcp (26 stars, last pushed 3d ago), licensed Apache-2.0. It adds 45 tokens to every session and 869 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.