context-optimization

context-optimization is a skill for Claude Code from RBraga01/builder-ai. It costs 48 tokens per session (1,282 once invoked), scanned A, original, MIT.

A method for reducing the amount of text and data sent to an AI model while measuring cost, latency, and output quality.

In plain words
What is it for?
Use it when prompts are large, response times are high, context limits are near, or per-call costs exceed the target.
Why use it?
It prevents unsupported claims that a shorter prompt is cheaper or faster by requiring measurements before and after each change.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: positional $N argument.

Part of the builder-ai plugin — 8 skills, 5 agents shipped together

Good fit Use it when prompts are large, response times are high, context limits are near, or per-call costs exceed the target.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/rbraga01/builder-ai/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 RBraga01/builder-ai --skill context-optimization
Clone the repo
git clone --depth 1 https://github.com/RBraga01/builder-ai

Made for: Claude Code.

Or install builder-ai, the plugin that ships this one along with the rest of its 8 skills, 5 agents.

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/rbraga01/builder-ai/context-optimization/github.svg)](https://agentmods.dev/skills/rbraga01/builder-ai/context-optimization)
Your own site
<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.

agentmods 80×15 button for context-optimization

Your own site · 80×15
<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>
Per session 48 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,282 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 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.00048 $0.01282
Opus 5.5 $0.00019 $0.00513
Sonnet 5.5 $0.00010 $0.00256
Haiku 4.5 $0.00005 $0.00128

Measured 1mo ago against content hash 139a70ad55ad, 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.

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

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:

  1. Reduce top_k by 1 and run eval-before-ship — recall often holds at lower top_k
  2. Add or tighten a similarity threshold (filter chunks below 0.75 cosine similarity)
  3. 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

Read the full file on GitHub · 138 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 · 138 lines · 48 tokens per session scan A 139a70ad55ad

Subscribe to this mod's changes

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.

Related

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.

sickn33/agentic-awesome-skills · 47 tokens

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…

nidhinjs/prompt-master · 78 tokens

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.

roedyrustam/vibes-plug · 58 tokens

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…

roedyrustam/vibes-plug · 102 tokens

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.

roedyrustam/vibes-plug · 84 tokens

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.

simota/agent-skills · 45 tokens