Maestro
A MoE routing layer for Claude Code — deterministic hooks, a declarative routing
table, and a roster of cost-tiered agents.

Leia em português. Internal docs (docs/) are in pt-BR.
Philosophy: deterministic rails, AI at the edges. Hooks guarantee THAT a
routing decision happens; the session's Claude decides WHAT to do, guided by
the table. No LLM on the critical path, no network on the critical path, no
component that blocks work when it fails.
The problem
In a long Claude Code session, the main model tends to do everything itself — in the
most expensive context in the house. A mechanical one-line bugfix costs the same
premium reasoning as an architecture decision. Maestro inverts the default:
delegating is the rule, working directly is the exception, and each task drops to
the cheapest model that can handle it. In a blind eval, this inversion took routing
accuracy from 73% (11/15, best judge, round 2) to 100% (15/15, two independent judges,
round 6) — best of six rounds against the same 15 cases, so overfitting is a declared
caveat. The field number, measured on 479 real decisions, is a different metric and
comes with its own caveat: see docs/ROUTING_EVAL.md.
How it works
flowchart LR
subgraph hooks["hooks (pure bash, <50ms)"]
SS[SessionStart] -->|injects| INJ["routing table + roster<br/>+ gates + heuristics"]
PT[PreToolUse] -->|Edit/Write| GATE{decision<br/>record?}
PB[PreToolUse] -->|Bash| GUARD["destructive-command guard<br/>(rm -rf, force push, DROP)"]
end
subgraph cli["CLI (Bun)"]
DEC["maestro decide"] --> REC[("decision record<br/>4h TTL")]
DOC["maestro doctor"] --> ENV[("capabilities.json<br/>+ drift snapshots")]
end
GATE -.->|no record: warn| REC
INJ -->|"the session's Claude<br/>picks workflow + agent"| DEC
-
SessionStart injects a <maestro-routing> block (~6KB, budget enforced by a
tested ratchet): intent → workflow routes, step → executor bindings, delegation
heuristics, human gates, and the roster filtered by the project's .maestro.yaml.
-
The session's Claude records its decision before editing code:
maestro decide --session <id> --workflow fix --mode subagent \
--agents golang-pro --reason "bug in 1 Go module"
-
PreToolUse checks: editing code without a valid decision record raises a
warning on every edit (gate.mode: warn is the default; promotion to block is
one line of config, made with dogfood data — not on faith).
-
maestro log --summary closes the loop: manual-override rate, model distribution
per task — the instrument that tells you whether routing is actually working.
Situational awareness — no more cold-start sweeps
A fresh session normally re-scans the repo to figure out where the project
stands. Maestro fixes this with a project brief: the outgoing session writes
a short narrative (maestro brief --write — what was in flight, open decisions,
next step), the CLI stamps it with timestamp + git HEAD + a content fingerprint,
and SessionStart injects a ~300-byte pointer with an honest freshness verdict:
## Projeto
brief: FRESH (2h, HEAD 73394c8) → read ~/.maestro/briefs/… BEFORE sweeping the repo
A stale brief says so — "STALE (3 commits behind) → the brief gives context; git
gives the truth". The rails guarantee THAT the state exists and is fresh; the AI
writes WHAT it says. The brief is local working state — never memory, never logged.
The same freshness treatment covers structure: if the project has a
graphify knowledge graph (graphify-out/), the
injection points at it — fresh → "answer structure via graph query BEFORE
reading code"; stale → "do not trust it". A versioned operator routine
(bin/maestro-graph-refresh, weekly crontab) incrementally refreshes only
stale graphs, capped per run. A stale map is worse than no map.
Habit sensors — anti-slop nudges at edit time