PLUGIN brewtools / Skills

Agent Router Setup — spawn the right agent, not the habitual one

sonnet project only opt-in experimental

View 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

FieldValue
Command/brewtools:agent-router-setup
Arguments[prompt] [status|install|upgrade|enable|disable|uninstall|purge] [level fast|strict] [--unattended]
Modelsonnet
ScopeProject only
Defaultstatus with no argument

Two tiers

TierWiringCost
1, level fast (default)Deterministic Node command hook, PreToolUse matcher Agent0 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 entryOne 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

SituationInvocation
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

  1. Status first

    The skill checks the hook file, wiring, config and roster size, and prints a state table.

  2. Mode from free text

    No arguments means status. Ambiguity between install and a removal verb triggers AskUserQuestion.

  3. Plan, then one question

    The plan is stated first; the only question is the level, and only when you did not say it.

  4. File work delegated

    One brewcode:hook-creator spawn copies the hook, merges or strips settings.json entries and writes the config.

  5. Refreshed status

    Wiring and config changes apply to the running session; /hooks confirms.

Technical details #

Tier 1 decision order

It allows as early as it can; an ambiguous case becomes a nudge, never a block.

#CheckResult
1Tool is not Agentallow
2agent_id present (a subagent spawned)allow; only the main loop is policed
3enabled:false, or a config that does not parseallow
4Picked type is a project agentallow
5Picked type is not on genericTypesallow; an omitted subagent_type counts as general-purpose
6Intent regex over the task textdeny naming the expert; a project agent for the same intent outranks the plugin specialist
7Score the task against .claude/agents/**/*.mdclear winner: deny; several plausible: nudge with top 3; none: allow
8Anti-loop guardthe same task is denied at most once per session
9Any errorfail 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

ModeHook filesettings.jsonConfig
status (default)———
installcopiedentry mergedwritten
upgradere-copiedre-mergedvalues preserved, restamped
enable / disablekeptkeptenabled:true / enabled:false
uninstalldeletedentries strippedkept
purgedeletedentries strippeddeleted, plus this project’s tmp state
level fast / level strictkepttier-2 + heartbeat stripped / appendedlevel 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

WhatPath
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
}
KeyMeaning
enabledOnly exactly false turns it off. A config that exists but does not parse turns the feature fully off
levelRecord of what is wired; editing it by hand adds or removes nothing
genericTypes / neverFlagTypes policed / types never flagged (every intents[].expert is added)
minScore / marginMinimum roster score / lead over the runner-up for a deny rather than a nudge
intentsOptional 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

FlagPurpose
--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-purpose and worker only, 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 (also allow, skip) in the task passes a spawn silently.
  • Everything fails open: a config that does not parse turns routing off, a route whose match does not compile is skipped, and neither blocks a spawn.

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