agent-kit-cost
Skill2 starsChanged 2 days agoMITView on GitHub
Spend fewer tokens on agent work by routing each task to the cheapest model tier that can finish it, giving every agent a checkable finish line, and not spawning agents the task doesn't need. Use WHENEVER you are about to spawn a subagent, fork, parallel agents or a Workflow, choose a model for an agent, plan a multi-agent job, switch models mid-session, or the user says "cost", "cheaper agents", "token budget", "which model", "too many agents", "ลดค่า token". Ships a PreToolUse hook that nudges every Agent call that sets no model.
In this repository23 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- new-skillSkill
- agent-kit-prompt-cacheSkill
- agent-kitSkill
- containers-podmanSkill
- containersSkill
- dependency-vuln-explainerSkill
- design-coreSkill
- design-flowSkill
- devops-changeSkill
- devops-network-diagramSkill
- devops-release-scopeSkill
- devopsSkill
- documentation-doc-styleSkill
- documentation-pdf-operationsSkill
- documentationSkill
- poc-spec-driven-builderSkill
- qa-answer-reviewSkill
- qa-excel-importSkill
- qa-export-evidenceSkill
- qaSkill
- qa-ticket-reportSkill
- thai-mock-namingSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 39
Effort is the user's knob: Don't raise an agent's effort unless the user or the project's instructions ask.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Agent cost
Most agent spend is waste of three kinds: a frontier model doing a search, an agent with no finish
line looping, and an agent spawned for work that was five tool calls. Each rule below cuts one of them.
Prompt-cache rules (byte-stable prefixes, forks, SendMessage, TTL) live in
../prompt-cache/SKILL.md; follow both.
Rules
- Do it inline first. A lookup whose target you know, or a handful of tool calls, costs less in this session than any agent: an agent re-reads context, and its summary drops detail you then redo. Spawn only for independent work that can run in parallel, or a side task that would flood this context with file dumps.
Route by tier, start cheap. Set
modelon every Agent call:Work modelsearch, file inventory, reading logs, collecting facts haikua bounded code change with a test, a review of one diff sonnetplanning, multi-file architecture, a task a cheaper tier already failed omit (inherit) or opusEscalate one tier when an agent fails its finish line, not before. The orchestrator plans; workers on cheaper tiers execute.
- Every brief has a finish line. Goal, scope (files, what not to touch), what to return, and how done is checked (a command and its expected output, a test name, a count). "Improve this" with no check is how an agent loops.
- Split big jobs into checkpoints. Several small agents with testable outputs beat one long agent you can only judge at the end. Small jobs stay single-session: multi-agent overhead (briefs, handoffs, re-reading) outweighs the parallelism.
- Don't switch the session's model mid-task. The prompt cache is per model; a switch makes the
new model read the whole history at full price. Run
/compactor start a fresh session first. A subagent on another tier doesn't touch the parent's cache, but starts its own prefix cold, so give siblings the same brief prefix. - Effort is the user's knob. Don't raise an agent's
effortunless the user or the project's instructions ask. Top effort tiers buy little accuracy for many more tokens. - Pre-allow what is reversible. An agent stalled on a permission prompt burns wall-clock and
context. Allowlist reads, tests and builds in
settings.json(/fewer-permission-prompts); keep deletes, pushes and anything outward-facing behind a confirmation. - The final report stands alone. Written for someone who didn't watch: what changed, the proof (test or command output), what's left. Relay what matters; the user never sees an agent's report.
The hook
scripts/agent_guard.py is a PreToolUse hook on Agent. When a call sets no model (forks
excepted: they always inherit), it adds the tier table to the context. It never blocks. Register it in
the project's or user's settings.json:
{"hooks": {"PreToolUse": [{"matcher": "Agent", "hooks": [{"type": "command",
"command": "uv run --script /path/to/agent-kit/cost/scripts/agent_guard.py"}]}]}}uv run --script scripts/agent_guard.py --selftest checks it.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

