Skill

Optimize Claude Code Model Routing and Costs

Claude Code skill that auto-routes subtasks to the cheapest capable model and logs real token/cost data to verify routing decisions.

Works with claude

72
Spark score
out of 100
Updated last month
Version 13.1.1
Models
claude 3 5 haikuclaude 3 5 sonnetclaude 3 opus

Add to Favorites

Why it matters

Dramatically reduce Claude Code token spend by intelligently routing tasks to the most cost-effective model (Haiku, Sonnet, or Opus) without sacrificing output quality. Validate routing decisions with built-in A/B testing and gain visibility into token usage.

Outcomes

What it gets done

01

Automatically route subtasks to the cheapest capable Claude model.

02

Log detailed token and cost data for each routed task.

03

Perform A/B tests to compare model quality on specific tasks.

04

Audit Opus token consumption and identify optimization opportunities.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-tokenwise | bash

Overview

TokenWise - Measurement-Driven Model Router

A Claude Code skill that measures real token usage and auto-routes subtasks to the cheapest model tier that can handle them, logging cost data locally and offering an A/B test mode to verify routing decisions. Use it when Claude Code token spend is concentrated on Opus and you want measured, reversible cost savings; it's Anthropic-only, so cross-vendor setups need LiteLLM or OpenRouter instead.

What it does

TokenWise is a measurement-driven model router for Claude Code: it auto-routes subtasks to the cheapest model that can handle them (Haiku for mechanical grunt work, Sonnet for scoped reasoning, Opus only for synthesis-level decisions), then logs every routed task to a local NDJSON file with real token and cost numbers. It includes an A/B test subcommand that runs the same task across multiple model tiers and scores quality, so routing decisions are verified against the user's actual workload rather than estimated from vibes. It exists because Anthropic's own bug tracker (Issue #27665) reports 93.8% of Max-subscriber Claude Code tokens flow to Opus, and existing routers (claude-router, wshobson, VoltAgent) either pin models statically or route by heuristics with no measurement behind them.

When to use - and when NOT to

Use it to cut Claude Code token spend without sacrificing output quality, to validate whether Haiku or Sonnet is "good enough" for a specific task class before trusting auto-routing, to audit where Opus tokens are actually being burned, or to log per-session cost data for finance/chargeback. It is Anthropic-only by design - for cross-vendor routing use LiteLLM or OpenRouter instead. The A/B test mode intentionally costs extra tokens (one task run across N tiers) as a one-time validation cost, not something to run on every task.

Inputs and outputs

Five subcommands: /tokenwise:install (guided installer with diff preview, automatic backups, --dry-run mode), /tokenwise:report (per-session token + cost summary vs an all-Opus baseline), /tokenwise:summary [--week|--month|--all] (historical aggregate with trend), /tokenwise:ab "<task>" (A/B tests the same task at multiple tiers and generates a markdown comparison), and /tokenwise:undo (restores CLAUDE.md / settings.json from backup). The routing taxonomy maps Haiku 4.5 to mechanical work (file reads, grep, format, rename, simple edits, doc lookups), Sonnet 4.6 to scoped reasoning (single-file refactor, scoped research, test writing), and Opus 4.7 to synthesis (architecture decisions, multi-file refactor, security review).

/plugin marketplace add CodeShuX/tokenwise
/plugin install tokenwise@tokenwise

Integrations

Built-in safety caps: Haiku never spawns further subagents, max spawn depth is 2, subagents that need a smarter model return to the parent rather than escalating themselves, tasks under 100 characters with no file context run inline since subagent overhead would exceed the savings, and subagent context over 30k tokens bumps a tier automatically. Privacy is zero-telemetry: all logs stay local in .tokenwise/log.ndjson, task descriptions are truncated to 80 characters and stripped of file contents before logging, and no analytics endpoint exists in the source. Token counts approximate Anthropic billing to within about 2%. The skill also probes for a known silent-fail bug in some Claude Code builds' subagent model: parameter at install time and refuses to configure routing if it detects broken routing.

Who it's for

Claude Code Max subscribers and teams who want measured, verified cost savings on token spend instead of guessing which model tier a task needs.

Source README

A Claude Code skill that auto-routes subtasks to the cheapest model that can handle them (Haiku for grunt work, Sonnet for scoped reasoning, Opus only for synthesis), then logs every routed task to a local NDJSON with real token + cost numbers. Includes an A/B test subcommand that runs the same task across multiple tiers and scores quality, so the routing decisions are verified against the user's real workload - not estimated.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.