agentleFS
The-Artificer-of-Ciphers-LLCThe-Artificer-of-Ciphers-LLC/skills-from-the-artificer/cost-routing/SKILL.md

cost-routing

Skill6 starsChanged 34 days agoMITView on GitHub

Top-level dispatcher that classifies every incoming request into scout / coder / architect tiers BEFORE any tool call. Routes Read, Grep, Glob, file-search, symbol-lookup, "where is X", and "list files matching Y" to haiku-scout. Routes known-location Edit, Write, multi-file refactor, test authoring, and bounded code changes to sonnet-coder. Reserves the main opus context for ambiguous design questions, ADRs, and tradeoff analysis. Use whenever a request lands in the main context and might involve file IO, code search, code edits, or design reasoning — which is almost every turn.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before reaching for any tool, run this classifier against the incoming request:

    line 20
  2. Distinctive:

    If the answer to #1 is yes and you find yourself reaching for Read / Grep / Glob in the main context anyway — STOP.

    line 29
  3. Distinctive:

    Default mode: warn (writes to stderr, the call proceeds).

    line 43

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cost-Tier Routing

The main context runs on opus. Every Read, Grep, Glob, and Edit invoked at this tier bills at opus rates. Most operations don't need opus reasoning — they need a model that can run a command and report a result. This skill is the dispatch gate that stops opus from doing work haiku or sonnet would complete just as correctly for a fraction of the cost.

The three tiers

TierModelOwnsExample requests
scouthaikuRead-only lookup, search, location"Where is Foo defined?", "List files matching *.test.ts", "Count LOC in src/", "Read X and report Y"
codersonnetBounded code changes at known locations"Add a test for parseDate", "Refactor auth.ts to use the new client", "Rename A → B repo-wide"
architectopusAmbiguous spec, tradeoff analysis, design"Should we use Redux or Zustand?", "Draft an ADR for the auth rewrite", "Why is this architecture failing?"

The dispatch decision (run this first, every turn)

Before reaching for any tool, run this classifier against the incoming request:

  1. Is the work entirely read / search / location? → scout. Dispatch haiku-scout. Never call Read / Grep / Glob in the main context.
  2. Is the change scope AND the design already decided? → coder. Dispatch sonnet-coder with a precise brief.
  3. Is the user asking "should we", "why", "what are the tradeoffs", "design X"? → architect. Stay in-context (you ARE opus) or dispatch with model: "opus".
  4. Mixed? → split. Scout first to gather facts, then re-classify the next step. Never bundle scout work into an architect dispatch.

Tool split (CodeGraph first, Memtrace for heavy hits). Use CodeGraph (codegraph_explore / codegraph CLI) for symbol lookup, file reads, callers/callees, and ordinary blast radius. Reserve Memtrace (and cortex) for git history/evolution, recall_decision, cross-repo/API topology, risky blast radius (get_impact), PR review evidence, and dead code/complexity, because Memtrace costs quota. If ~/.claude/state/memtrace-quota.json says blocked with a future until, never call Memtrace; use CodeGraph until that time.

If the answer to #1 is yes and you find yourself reaching for Read / Grep / Glob in the main context anyway — STOP. That is the violation this skill exists to prevent.

Dispatch templates

See PROMPTS.md for the canonical brief for each tier. Use them verbatim — every field is load-bearing.

Worked examples

See EXAMPLES.md for ~15 classifications across the boundary cases (multi-file search, bug fixes with unknown root cause, "small" edits that hide design questions).

Enforcement

The companion PreToolUse hook (hooks/pre-tool-use-cost-check.sh) warns when Read / Grep / Glob fires in the main context. Register it in ~/.claude/settings.json (see EXAMPLES.md § Installing the hook).

  • Default mode: warn (writes to stderr, the call proceeds).
  • COST_ROUTING_BLOCK=1 upgrades the warning to a hard deny — useful for sessions where you want zero tolerance.
  • COST_ROUTING_BYPASS=1 silences the hook for legitimate one-shot inspection (a single Read of a file the user pasted a path to).

The hook cannot perfectly distinguish "top level opus" from "inside a subagent" — Claude Code does not currently expose that bit to hooks. It warns on every Read / Grep / Glob; you teach yourself to recognize the warning as "I'm probably in opus, should I have dispatched?"

When NOT to dispatch

  • The entire task is one unattended CLI command (gh pr view, docker ps). Use Bash directly — wrapping a one-shot command in an agent is pure overhead.
  • The user pasted a single file path and asked for a single fact. Read it directly; dispatch overhead exceeds the saved tokens.
  • The work is genuinely ambiguous design that needs opus reasoning. Don't dispatch yourself to yourself.

Common failure modes

  • Tier creep — classifying a multi-file search as "design work" because it touches many files. Multi-file search is still scout.
  • Dispatch without model: — calling Agent with subagent_type: "general-purpose" and no model: parameter inherits the parent tier (opus → opus). Always pin the model.
  • Skipping the classifier — jumping to Read on instinct. The classifier IS the skill; running it costs two seconds and saves the budget every time.
  • Bundling tiers — handing scout work to a coder dispatch ("find the file, then edit it"). The coder agent will burn sonnet tokens doing scout work. Split: scout reports the path; coder edits at that path.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.