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.
npx skills add RBraga01/builder-ai --skill context-optimizationgit clone --depth 1 https://github.com/RBraga01/builder-aiWrote 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.
[](https://agentmods.dev/skills/rbraga01/builder-ai/context-optimization)<a href="https://agentmods.dev/skills/rbraga01/builder-ai/context-optimization"><img src="https://agentmods.dev/badge/skills/rbraga01/builder-ai/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.
<a href="https://agentmods.dev/skills/rbraga01/builder-ai/context-optimization"><img src="https://agentmods.dev/badge/skills/rbraga01/builder-ai/context-optimization.svg" alt="Reviewed on agentmods" width="80" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00048 | $0.01282 |
| Opus 5.5 | $0.00019 | $0.00513 |
| Sonnet 5.5 | $0.00010 | $0.00256 |
| Haiku 4.5 | $0.00005 | $0.00128 |
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.
How it starts
The opening of the file, as written. The whole thing — 138 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Context Optimization
The Law
PROMPT COST IS NOT OPTIMISED BY GUESSING.
"I already have a short prompt" is a guess about token count.
"Reducing context will hurt quality" is a guess about the quality/cost curve.
Measure first. Apply the hierarchy. Measure again. THEN claim improvement.
When to Use
Trigger when:
- Prompt + context exceeds 60% of the model's context window
- p95 latency is above target
- Cost per 1k calls exceeds budget
- RAG pipeline is stuffing too many chunks into each call
- Output quality is degrading on long inputs (long context dilution)
When NOT to Use
- The feature has < 100 calls/month and total monthly cost is < $20 — optimisation ROI is negative at this volume
- Quality is currently below threshold — fix quality first; optimising a broken pipeline only makes it cheaper to be wrong
- The system prompt changes every call — prompt caching (Level 5) has no effect; skip straight to Level 1–3
The Reduction Hierarchy
Apply in order. Stop when the target is met. Do not apply all steps preemptively.
Level 1 — Trim the System Prompt
Audit every sentence:
- Run the prompt without each instruction — does output quality change?
- Remove any instruction the model follows without it
- Remove few-shot examples that duplicate knowledge the model already has
- Replace verbose explanations with single directives
Target: system prompt under 500 tokens for most tasks. Measure token count precisely:
import tiktoken
enc = tiktoken.get_encoding("cl100k_base")
print(len(enc.encode(system_prompt)))
Level 2 — Reduce Retrieved Context
If using RAG, before any other change:
- Reduce
top_kby 1 and run eval-before-ship — recall often holds at lower top_k - Add or tighten a similarity threshold (filter chunks below 0.75 cosine similarity)
- Set a hard context budget:
MAX_CONTEXT_TOKENS = context_window × 0.4
Level 3 — Compress Retrieved Content
Before injecting:
- Strip document headers, footers, and repeated boilerplate
- Normalise whitespace and remove formatting artefacts
- Convert verbose JSON to compact tabular format
- For chunks over 600 tokens: LLM-summarise to 1/3 length with a fast model
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.
- 1mo ago First seen · 138 lines · 48 tokens per session scan A 139a70ad55ad
context-optimization is a skill published in the GitHub repository RBraga01/builder-ai (2 stars, last pushed 10d ago), licensed MIT. It adds 48 tokens to every session and 1,282 once invoked, about $0.0002 per session on Opus 5.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-31.
Other skills, from other repositories
ai-engineering-toolkit
Overview of six AI engineering workflows: prompt evaluation (8-dimension scoring), context budget planning, RAG pipeline design, agent security audit (65-point checklist), eval harness building, and product sense coaching.
prompt-master
Generates optimized prompts for AI tools. Activates only when the user explicitly asks to write, fix, improve, or adapt a prompt for a specific AI tool (LLM, Cursor, Midjourney, image AI, video AI, coding agents, etc.). Does not activate for general conversation, coding tasks, document writing, or other…
ai-prompt-engineering-expert
Expert guide for Prompt Engineering, Chain-of-Thought, few-shot prompting, structured output, prompt injection defense, and automated AI evaluations & regression benchmarking (Promptfoo, DeepEval) / Panduan ahli rekayasa prompt dan evaluasi otomatis AI.
kv-cache-prefix-optimizer
Expert guide for deterministic prompt prefix engineering, KV-cache locking for Gemini 4 Pro / Claude 5.5 / GPT Astra 6, canonical tool sorting, and achieving 90%+ prompt cache hit rates / Panduan ahli rekayasa prefix prompt deterministik, penguncian KV-cache untuk Gemini 4 Pro / Claude 5.5 / GPT Astra 6, pengurutan…
test-time-compute-optimizer
Expert guide for scaling test-time compute, dynamic reasoning token allocation (Gemini 4 Pro, Claude 5.5, GPT Astra 6), Monte Carlo Tree Search (MCTS), and Process Reward Models / Panduan ahli penskalaan komputasi waktu uji (test-time compute), alokasi dinamis budget penalaran, MCTS, dan Process Reward Models.
oracle
Designing and evaluating AI/ML systems: prompt engineering, RAG design, LLM application patterns, AI safety, evaluation frameworks, MLOps, cost optimization. Use for AI pipelines or eval harnesses.