agentleFS
Moriarty33Moriarty33/jb-kaizen/skills/model-balance/SKILL.md

model-balance

Skill1 starsChanged 7 days agoMITView on GitHub

Analyzes model + effort usage across all Claude Code sessions and rebalances the two dials - intelligence (haiku/sonnet/opus) and effort (low/medium/high/xhigh/max) - so cheaper, faster tiers carry everything that does not need the expensive ones, saving cost and latency with no quality loss. Reads ccusage spend distribution + config routing sites (--model in job/skill scripts, skill frontmatter, workflow agent() calls) and flags over-provisioning (opus where sonnet/haiku suffices) and mis-provisioning. Hybrid apply - auto-applies high-confidence reversible config edits backup-first, defers risky ones to a journal for review. Runs manually and as Phase 2.8 inside self-learn. Use when the user says "balance the models", "optimize model usage", "which models am I overusing", "we could save cost/speed on models", "where can I save on models", or types /model-balance.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Scope (hard rule): read/write only within ~/.claude and your workspace.

    line 16
  2. Very specific:

    Every <skill-dir>/… path below means that directory.

    line 29
  3. Distinctive:

    Never downgrade a site where transcripts show the cheaper tier already caused rework.

    line 78
  4. Very specific:

    Write <skill-dir>/journal/<date>.md: the spend snapshot, applied changes (with backup paths + est.

    line 82
  5. Distinctive:

    Never overfit one project's routing onto another.

    line 92

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

model-balance - intelligence x effort routing optimizer

Rebalances which model and which effort level each Claude Code routing site uses, driven by real spend data, so the setup spends the least while keeping quality. The reference decision matrix is references/routing-rubric.md - read it first every run.

Scope (hard rule): read/write only within ~/.claude and your workspace. Never touch personal folders. Read-only except for the config edits you apply under the hybrid boundary below.

Modes

  • /model-balance or propose (default): analyze and produce the recommendations digest; apply nothing.
  • apply: analyze, then apply under the hybrid boundary (auto-apply safe, journal the rest).
  • status: show the last run's digest + what was applied/deferred, no new analysis.

Procedure

SKILL DIR: resolve once - ${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills/model-balance if it exists, else the newest match of ${CLAUDE_CONFIG_DIR:-$HOME/.claude}/plugins/cache/*/kaizen/*/skills/model-balance. Every <skill-dir>/… path below means that directory. The skill is /model-balance on a standalone install and /kaizen:model-balance under the plugin - same skill.

1. Collect (one read-only command)

bash <skill-dir>/scripts/collect-stats.sh

Gives: spend distribution by model (weekly + all-time, cost-equiv from ccusage), the explicit --model routing sites in job/skill scripts, skill-frontmatter model/effort pins, and the tiers workflows actually pick. This is the evidence base - do not re-derive it by hand. Add extra job directories to scan via MODEL_BALANCE_EXTRA_DIRS="dir1 dir2".

Reading live usage: ccusage gives cost-equiv $ and per-model distribution only - not the plan's weekly-limit %. /usage is a client-side CLI command the model cannot call and its % is not on disk, so when a run needs the live weekly-cap % lead by asking the user to run /usage and paste it - don't spend turns saying "I can't". Derive a literal cap from what you have: cap_usd ≈ this_week_ccusage_cost / (pasted /usage %).

2. Classify each routing site

For every site the collector surfaces (a --model flag, a skill model: pin, a workflow agent({model,effort}) choice, an agent's inherited default, the session default), determine the task class it runs and apply the rubric's decision procedure. Agents/*.md declare no model/effort - a recommendation for them targets either their invocation site or an explicit frontmatter addition.

Optionally corroborate with session transcripts under ~/.claude/projects/*/ (in-scope only): look for under-provisioning signals (retries, "that's wrong" corrections, re-runs) that mean a cheaper tier already hurt quality - those sites should NOT be downgraded.

3. Rank recommendations

Each recommendation is a concrete diff: site (file:line) - task class - current (model, effort) -> proposed (model, effort) - est. $/latency saving - confidence. Sort by (confidence x saving).

Typical standing candidates (verify against fresh data each run, do not hardcode): unattended job scripts running --model opus for web-search / log-digest / summary work that sonnet or haiku handles - high-confidence downgrades. self-learn on the strongest tier is defensible (deep multi-agent analysis and adversarial verification) - leave unless evidence says otherwise.

4. Hybrid apply boundary

  • Auto-apply (backup-first, reversible only): a single-line --model change in a job script, or a skill-frontmatter model:/effort: change, where the task class is unambiguous and confidence is HIGH. Back up the file first (cp <f> <f>.bak-modelbalance-<date>), edit, note it.
  • Defer to journal (never auto-apply): anything touching the session default or interactive behavior; any under-provisioning (raising a tier) unless evidence shows current quality loss; changes to many sites at once; anything you are not HIGH-confident is reversible and safe.
  • Never downgrade a site where transcripts show the cheaper tier already caused rework.

5. Write the digest

Write <skill-dir>/journal/<date>.md: the spend snapshot, applied changes (with backup paths + est. saving), deferred candidates as - [ ] checkboxes for the user to approve, and one line of "what next run should watch." When run as a self-learn phase, fold these into the self-learn journal instead of a separate file.

Non-negotiables

  • Quality first: a downgrade that causes rework costs MORE - weigh it as a regression, not a saving.
  • Evidence-backed only: cite file:line + ccusage numbers for every claim; no vibes.
  • Reversible: every applied edit is backed up; list the exact revert command in the digest.
  • Never overfit one project's routing onto another.

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.