Skip to content

Render subagent routing using claude code mod - #979

Merged
lilly-luo merged 21 commits into
mainfrom
claude-mods-subagent-routing
Oct 16, 2026
Merged

lilly-luo merged 21 commits into
mainfrom
claude-mods-subagent-routing

Conversation

@lilly-luo

@lilly-luo lilly-luo commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Introduce the ENABLE_CLAUDE_CODE_MODS environment variable, a shared
TRUTHY_ENV_VALUES set ("1"/"true", case-insensitive), and a general
claude_code_mods_enabled() reader in constants. Harness-general and not tied
to smart routing; nothing is gated on it in this change.

Co-authored-by: Isaac <no-reply@databricks.com>
Introduce ucode.mods: a reusable home for shipping Claude Code mods outside
smart routing. Each mod's source is real TypeScript under typescript/claude-mods/
(shipped with the wheel). Claude Code loads one hooks module per plugin, so a
mod is a register.ts entry that imports its concern modules; a ClaudeMod(
source="register.ts", extra=(...)) plus write_mod(plugin_dir, mod) copies the
entry and the files it imports into a launch-scoped plugin's hooks/. The
mods-wide Claude version floor (2.1.287) lives here too.

The first mod draws a band above the prompt (AbovePrompt) via register.ts ->
smart-routing-status.ts, showing whether smart routing is on and which prompts
it routes; the "on" pill uses a bright background with black text so it reads in
both light and dark terminals. Visualization only; ug's Python hooks still
route, and state is read via the mods API (env + the live session-env file),
mirroring v2.smart_routing_enabled / first_prompt_routing_enabled and accepting
"true" as well as "1".

Co-authored-by: Isaac <no-reply@databricks.com>
@lilly-luo
lilly-luo force-pushed the claude-mods-subagent-routing branch 2 times, most recently from 1810b77 to 4c88828 Compare October 3, 2026 19:47
@lilly-luo
lilly-luo added this pull request to stack #978 October 3, 2026 20:00
…notice

Add the subagent-routing concern to the smart-routing UI mod: register.ts now
also composes subagent-routing.ts, which renders a compact line under each Agent
row showing where it was routed, e.g.

  ↳ claude-sonnet-5  ●○○ low · an explicit target, localized scope

The routed model comes off the Agent row's result (resolvedModel); the tier and
reason come from the router rationale ("Routed to Low because …", regex-parsed).
Model text uses Claude Code's built-in `primary` theme color.

Under ENABLE_CLAUDE_CODE_MODS, the Python subagent hook now:
- drops its plain-text ASCII routing notice (no systemMessage / reason) — the mod
  renders instead — while keeping the model rewrite;
- writes the model + rationale, keyed by task, to a per-session mod-routing.json
  next to the session env file for the mod to read; and
- the launch propagates ENABLE_CLAUDE_CODE_MODS into the hook environment and
  omits the "Routing subagent model" spinner label (the mod is the feedback).

Without the flag, the plain-text notice and spinner are unchanged.

Co-authored-by: Isaac <no-reply@databricks.com>
@lilly-luo
lilly-luo force-pushed the claude-mods-subagent-routing branch from 4c88828 to 7d23b05 Compare October 3, 2026 20:08
@lilly-luo lilly-luo changed the title Render subagent routing as a compact pet-themed line (mod) Render subagent routing using claude code mod Oct 4, 2026
@lilly-luo
lilly-luo removed this pull request from stack #978 October 13, 2026 23:40
@lilly-luo
lilly-luo added this pull request to stack #1123 October 14, 2026 02:50
Base automatically changed from claude-mods-render-status to main October 14, 2026 15:16
lilly-luo and others added 6 commits October 16, 2026 16:20
Co-authored-by: Isaac <no-reply@databricks.com>
Hooks that earlier UG versions persisted still call route-subagent and expect a
PreToolUse response. Return main's full response for that event, including the
notice naming the dispatched agent, while route-subagent-mod keeps the mod's
plain routing details.

Co-authored-by: Isaac <no-reply@databricks.com>
Prefix each routed Agent row's routing line with a lightning bolt so it reads as
Smart Router's, omit ug-smart-router agent names that only repeat the model, and
keep [orchestrator on] as its own suffix after the model.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…nt rows

Each routed Agent row now always shows the selected model in the status band's
green, with the reason aligned beneath it. While the router answers, the row
shows a spinner with the elapsed seconds, then notes how long routing took.
Both timers use $.clock and are omitted when it is unavailable, so they never
block routing. The orchestrator tag and the unused orchestrator field in the
mod's routing reply are removed; the legacy hook notice keeps its tag.

Co-authored-by: Isaac <no-reply@databricks.com>
The parent model writes the Agent row's description, so the task marker may
appear only in the prompt. Match a Selected Model row after the tagged prompt
and before the next one instead of requiring the marker above the row.

Co-authored-by: Isaac <no-reply@databricks.com>
…gent routing

Drop the leftover truthy routing-flag parsing (flags take only 0 and 1), the
Codex comment churn, a test that repeated the plugin file check, four redundant
assertions, and doc paragraphs that restated each other. Share one helper for
the routing timer's elapsed seconds.

Co-authored-by: Isaac <no-reply@databricks.com>
@lilly-luo lilly-luo added the ug-review Run the automated UG review label Oct 16, 2026
Comment thread src/ucode/agents/claude_mods/subagent-routing.ts Outdated
Comment thread src/ucode/smart_routing/claude_hooks.py Outdated
Comment thread src/ucode/smart_routing/v2.py
Comment thread src/ucode/smart_routing/v2.py
lilly-luo and others added 3 commits October 16, 2026 21:02
Co-authored-by: Isaac <no-reply@databricks.com>
… branch

Derive the routing spinner frame from the clock so parallel subagents no
longer speed it up. Split route_claude_subagent's two reply shapes into the
mod's function and a route_claude_pre_tool_use wrapper for persisted legacy
hooks, sharing one routing helper. routing_hook_argv now adds router options
only for the mod event, since nothing builds a Claude route-subagent argv.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@lilly-luo
lilly-luo requested a review from xsh310 October 16, 2026 21:15

@xsh310 xsh310 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the video recording looks great. The reason text seems to be difficult to understand tho, we might want to make that more human understandable given that this is rendered to the users?

@lilly-luo
lilly-luo added this pull request to the merge queue Oct 16, 2026
Merged via the queue into main with commit 27186eb Oct 16, 2026
99 of 102 checks passed
@lilly-luo
lilly-luo deleted the claude-mods-subagent-routing branch October 16, 2026 22:42
nachill-databricks pushed a commit to nachill-databricks/ucode that referenced this pull request Oct 17, 2026
## What did you change, and why?

Translate existing task profiles into short routing explanations,
addressing [this review
feedback](databricks#979 (review)).
For example, `Routed to Low because its task-only profile is low: ...`
becomes `This task has a clear target and limited scope.` Preserve
availability and fallback explanations, custom gateway notices, and
unrecognized responses. Diagnostic records keep the displayed
explanation in `rationale` and the original gateway text in
`raw_rationale`.

## How do you know it works?

Two direct formatter tests cover readable wording and preservation of
unknown responses. All 217 focused routing and integration-contract
tests pass. A direct filesystem check verifies both diagnostic fields
for summarized, unchanged, and empty reasons. Ruff lint, formatting, and
type checks pass. The live integration checks will rerun in CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ug-review Run the automated UG review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants