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 agentmods add skills/mickeyyaya/refactoring-skills/agent-token-optimization-patternsnpx skills add mickeyyaya/refactoring-skills --skill agent-token-optimization-patternsgit clone --depth 1 https://github.com/mickeyyaya/refactoring-skillsWrote 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/mickeyyaya/refactoring-skills/agent-token-optimization-patterns)<a href="https://agentmods.dev/skills/mickeyyaya/refactoring-skills/agent-token-optimization-patterns"><img src="https://agentmods.dev/badge/skills/mickeyyaya/refactoring-skills/agent-token-optimization-patterns.svg" alt="Measured on agentmods" 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.00062 | $0.04115 |
| Opus 5 | $0.00031 | $0.02057 |
| Sonnet 5 | $0.00012 | $0.00823 |
| Haiku 4.5 | $0.00006 | $0.00411 |
Grade A, and why
agent-token-optimization-patterns 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.
How it starts
The opening of the file, as written. The whole thing — 432 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Agent Token Optimization Patterns
Overview
Token = cost + latency. Every token you can save without losing quality is pure value — lower bills, faster responses, and more headroom before context limits bite. At scale, unoptimized agents burn 3-10× more tokens than necessary, primarily through context stuffing, wrong-model routing, and cache thrashing.
Token optimization is not about cutting corners. It is about precision: sending exactly the information the model needs, in exactly the right form, to the right model, at the right time.
Quick Reference
| Technique | Token Savings | Implementation Complexity | Risk |
|---|---|---|---|
| Prompt caching (stable content first) | 45-80% on cache hit | Low | Cache thrashing if content rotates |
| Model routing (haiku for simple tasks) | 60-90% cost reduction | Medium | Quality degradation on misrouted tasks |
| Structured data over prose | 20-40% | Low | Schema design overhead |
| Progressive summarization | 30-60% | Medium | Lossy compression of earlier context |
| System prompt deduplication | 10-30% | Low | Divergence if copies drift out of sync |
| Context slicing (role-based) | 20-50% | Medium | Missing context if slices are too narrow |
| Sliding window (drop oldest turns) | Variable | Low | Loss of early conversation context |
| Spawn new agent vs stuff context | High (resets window) | High | Coordination overhead, handoff cost |
Context Engineering
Context engineering is the systematic practice of controlling what goes into an agent's context window. The framework has four operations: Write, Select, Compress, Isolate.
Write — Craft Precise Prompts
Write prompts that express the task in minimum tokens without ambiguity. Prefer imperative verbs over explanatory prose. Replace "Could you please help me understand..." with "Explain:". Remove politeness markers, hedges, and meta-commentary — the model does not need them.
// WRONG: verbose and hedging
const verbose = `
I was wondering if you could help me take a look at the following code
and maybe identify any potential issues that might be present in it.
Please be thorough but also concise in your response if possible.
`;
// CORRECT: imperative, direct
const precise = `Review this code. List issues by severity (critical/high/medium/low). One line each.`;
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.
- 6d ago First seen · 432 lines · 62 tokens per session scan A e9b654347b01
agent-token-optimization-patterns is a skill published in the GitHub repository mickeyyaya/refactoring-skills (6 stars, last pushed 5mo ago), licensed MIT. It adds 62 tokens to every session and 4,115 once invoked, about $0.0003 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-31.
Other skills, from other repositories
llm-app-patterns
Production-ready patterns for building LLM applications. Covers RAG pipelines, agent architectures, prompt IDEs, and LLMOps monitoring. Use when designing AI applications, implementing RAG, building agents, or setting up LLM observability.
prompt-optimization
Improve a prompt on the evaluations workbench through a measured loop. Score the baseline first, then duplicate the target column, form a hypothesis from failing rows, edit the copy's prompt draft, run, compare pass rate and cost, and repeat until the numbers hold. Use when the user asks to optimize or improve a…
enhance-prompt
Transforms vague UI ideas into polished, Stitch-optimized prompts. Enhances specificity, adds UI/UX keywords, injects design system context, and structures output for better generation results.
prompt-engineer
Writes, refactors, and evaluates prompts for LLMs — generating optimized prompt templates, structured output schemas, evaluation rubrics, and test suites. Use when designing prompts for new LLM applications, refactoring existing prompts for better accuracy or token efficiency, implementing chain-of-thought or few-shot…
seedance-vocab-en
This skill should be used when an English Seedance 2.0 prompt is slop-heavy, generic, padded with empty quality words, tripping false-positive filters, or needs precise English production vocabulary for camera, lighting, motion, VFX, audio, and constraints.
omh-model-optimization
This is a Hermes-native model-optimization workflow skill.