PLUGIN brewtools / Skills
On this page
Agent Router Setup — spawn the right agent, not the habitual one
sonnet project only opt-in experimentalView README on GitHub (opens in a new tab)
/brewtools:agent-router-setup installs one PreToolUse hook, matcher Agent. When a project agent from .claude/agents/ or a brewcode specialist clearly owns the task and the main loop reached for a generic type, the hook denies the spawn and names the real expert. When several agents look equally plausible, it only appends a nudge. Everything else stays silent.
EXPERIMENTAL. Opt-in, installed per project only, and not registered in brewtools/hooks/hooks.json: installing the brewtools plugin does nothing until this skill runs.
Quick reference
| Field | Value |
|---|---|
| Command | /brewtools:agent-router-setup |
| Arguments | [prompt] [status|install|upgrade|enable|disable|uninstall|purge] [level fast|strict] [--unattended] |
| Model | sonnet |
| Scope | Project only |
| Default | status with no argument |
Two tiers
| Tier | Wiring | Cost |
|---|---|---|
1, level fast (default) | Deterministic Node command hook, PreToolUse matcher Agent | 0 tokens, under 100 ms including node startup |
2, level strict (opt-in) | Agent-hook LLM judge, no model key (Claude Code default small model, claude-haiku-5-5 on 2.1.296), plus a heartbeat entry | One model call on every Agent spawn |
A judge timeout or model error is a silent allow; tier 2 cannot fail closed, and tier 1 still decides on its own.
Claude Code runs all hooks matching an event in parallel and none can skip another, so tier 1 cannot gate tier 2. Once level strict is wired, the judge fires on every Agent spawn. That is why fast is the default.
When to use
| Situation | Invocation |
|---|---|
The main loop keeps picking general-purpose despite project agents | /brewtools:agent-router-setup install |
| Check what is wired | /brewtools:agent-router-setup status |
| Pick up a new hook version, same level | /brewtools:agent-router-setup upgrade |
| Add or drop the LLM judge | /brewtools:agent-router-setup level strict / level fast |
| Stop enforcing, keep files | /brewtools:agent-router-setup disable |
| Remove everything, config included | /brewtools:agent-router-setup purge |
Example
/brewtools:agent-router-setup install
The skill prints the status table (hook_file=no tier1_refs=0 enabled=n/a level=n/a roster=4), states the plan (copy agent-router.mjs into .claude/hooks/, write .claude/brewtools/agent-router.json with level: "fast", merge one PreToolUse entry into .claude/settings.json), asks one question (level, default fast), delegates to brewcode:hook-creator and re-prints status with hook_file=yes tier1_refs=1 enabled=true level=fast.
Workflow
- Status first
The skill checks the hook file, wiring, config and roster size, and prints a state table.
- Mode from free text
No arguments means
status. Ambiguity between install and a removal verb triggersAskUserQuestion. - Plan, then one question
The plan is stated first; the only question is the level, and only when you did not say it.
- File work delegated
One
brewcode:hook-creatorspawn copies the hook, merges or stripssettings.jsonentries and writes the config. - Refreshed status
Wiring and config changes apply to the running session;
/hooksconfirms.
Technical details #
Tier 1 decision order
It allows as early as it can; an ambiguous case becomes a nudge, never a block.
| # | Check | Result |
|---|---|---|
| 1 | Tool is not Agent | allow |
| 2 | agent_id present (a subagent spawned) | allow; only the main loop is policed |
| 3 | enabled:false, or a config that does not parse | allow |
| 4 | Picked type is a project agent | allow |
| 5 | Picked type is not on genericTypes | allow; an omitted subagent_type counts as general-purpose |
| 6 | Intent regex over the task text | deny naming the expert; a project agent for the same intent outranks the plugin specialist |
| 7 | Score the task against .claude/agents/**/*.md | clear winner: deny; several plausible: nudge with top 3; none: allow |
| 8 | Anti-loop guard | the same task is denied at most once per session |
| 9 | Any error | fail open |
Built-in intents: skill authoring -> brewcode:skill-creator, agent authoring -> brewcode:agent-creator, hooks -> brewcode:hook-creator, bash scripts -> brewcode:bash-expert. The project root is resolved by ownership, not cwd: CLAUDE_PROJECT_DIR, then the nearest ancestor holding .claude/brewtools/agent-router.json, then .git, then .claude, then cwd (up to 16 levels per step). A .claude in $HOME or the $CLAUDE_CONFIG_DIR parent is a profile, not a project marker.
Modes
| Mode | Hook file | settings.json | Config |
|---|---|---|---|
status (default) | — | — | — |
install | copied | entry merged | written |
upgrade | re-copied | re-merged | values preserved, restamped |
enable / disable | kept | kept | enabled:true / enabled:false |
uninstall | deleted | entries stripped | kept |
purge | deleted | entries stripped | deleted, plus this project’s tmp state |
level fast / level strict | kept | tier-2 + heartbeat stripped / appended | level set |
upgrade asks nothing and keeps level. Upgrading an install from brewtools 6.4.0 or older changes settings.json at level strict (the tier-2 entry loses its model key, the heartbeat appears); at level fast only the hook file changes. Foreign hook entries are never touched.
Under --unattended, upgrade skips with nothing written when the router is not installed, a custom launcher wraps its hook, settings.json is invalid or level strict is recorded without the judge wired. A config kept by uninstall is not an install: the note is not installed and the hook is not wired again. See how the flag works.
Where it installs
| What | Path |
|---|---|
| Hook | <repo>/.claude/hooks/agent-router.mjs |
| Wiring | <repo>/.claude/settings.json |
| Config | <repo>/.claude/brewtools/agent-router.json |
| State | <os.tmpdir()>/brewtools-agent-router/p-<sha1(real root)[0..16]>/<session_id>/ |
The judge prompt is inlined into settings.json, not copied; upgrade or level strict refreshes it.
Config
{
"enabled": true,
"level": "fast",
"genericTypes": ["general-purpose", "worker"],
"neverFlag": ["Explore", "Plan", "statusline-setup", "output-style-setup", "brewcode:agent-creator", "brewcode:skill-creator", "brewcode:hook-creator", "brewcode:bash-expert"],
"minScore": 3,
"margin": 2
}
| Key | Meaning |
|---|---|
enabled | Only exactly false turns it off. A config that exists but does not parse turns the feature fully off |
level | Record of what is wired; editing it by hand adds or removes nothing |
genericTypes / neverFlag | Types policed / types never flagged (every intents[].expert is added) |
minScore / margin | Minimum roster score / lead over the runner-up for a deny rather than a nudge |
intents | Optional list of {match, expert, label}. Replaces the built-in routes wholesale: copy DEFAULT_INTENTS from agent-router.mjs first |
The file also carries version, content_version, generated_by and last_updated. Staleness is judged on content_version, never version.
enabled defaults to true and only an exact false disables it, the opposite of agent-deadline-setup, where anything but true means OFF.
Status probe flags
| Flag | Purpose |
|---|---|
--probe <settings.json> | Counts tier-1, legacy, tier-2 and heartbeat entries that match the shipped shapes exactly |
--judge-health <root> | At strict: judge_expected, judge_answered, judge_overdue over about 24 h |
--purge-state <root> | Deletes this project’s tmp state only |
Limits
- Tier 2 is narrower than tier 1:
general-purposeandworkeronly, project agents only, no state, no transcript. - Tier 1 matches trigger words, not meaning; the intent regexes are English.
- No writable tmp dir means no denies, only notices.
agent-router: override(alsoallow,skip) in the task passes a spawn silently.- Everything fails open: a config that does not parse turns routing off, a route whose
matchdoes not compile is skipped, and neither blocks a spawn.
Related
Brewtools overview
Every brewtools skill and agent.
Agent Deadline Setup
Another opt-in hook for subagents: a soft wall-clock budget.
Setup Status
Dashboard across every -setup skill; upgrade brings the stale ones current.
Update: /brewtools:plugin-update, /reload-plugins, then /brewcode:setup-status upgrade - FAQ