Skip to content

fix: Route headless Claude prompts before launch under smart routing - #1098

Merged
lilly-luo merged 1 commit into
mainfrom
max-rozen-oss-db/stack/claude-headless-routing
Oct 13, 2026
Merged

lilly-luo merged 1 commit into
mainfrom
max-rozen-oss-db/stack/claude-headless-routing

Conversation

@max-rozen-oss-db

Copy link
Copy Markdown
Collaborator

Summary

Replaces #1096, which GitHub closed as merged when the stack was reordered. #1074 (Terminal Bench) is stacked on this PR and verifies it.

With smart routing on, ug claude -- -p lost its prompt on Linux and macOS. ug always launched Claude inside its PTY first-prompt router. In print mode the PTY swallowed the piped prompt, and Claude exited with "Input must be provided either through stdin or as a prompt argument when using --print". Terminal Bench found it: every Claude task failed on Linux with routing on, in run 38002405792.

v2.launch_claude now handles print mode (-p/--print) without the PTY:

  • It takes the prompt from the args after --, the argument right after -p, or piped stdin.
  • It routes that prompt with _route_claude_prompt, pins the model with --model, and launches Claude directly. When ug read stdin, it writes the same bytes to Claude's stdin.
  • Subagent routing stays on. The first-prompt hook and socket aren't installed.
  • An explicit --model or a ug-pinned model skips routing. A router failure prints a warning and launches on Claude's default.

Windows headless launches now get first-prompt routing too, since this path doesn't need the PTY. Interactive launches are unchanged.

Verification

  • New TestV2HeadlessClaude tests cover a stdin prompt, a prompt argument, an explicit --model, and a router failure.
  • just lint passes. The unit suite has the same 13 local failures with and without this change. They need local sockets or network, and CI runs them.
  • Terminal Bench with routing on, run 38016091564: all six jobs pass. Harbor Claude went from 0/14 to 13/14 on ug tasks. The log shows ug's routing notice ("Routed to Medium ...") and Claude running on the pinned routed model.

This pull request and its description were written by the Isaac LLM tool (Claude Code, session 35c1ab71-d945-4de6-97b9-b35d5758edb4).

With first-prompt routing on, ug always ran Claude inside its PTY router.
In print mode the PTY swallowed the piped prompt, so `ug claude -- -p`
exited with "Input must be provided". Print mode now takes the prompt from
the -p argument, the args after --, or stdin, routes it, pins the model,
and launches Claude directly. Subagent routing stays on. This also gives
Windows headless launches first-prompt routing.

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

@lilly-luo lilly-luo 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.

thank you

@lilly-luo
lilly-luo added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit 07b829b Oct 13, 2026
104 of 107 checks passed
@lilly-luo
lilly-luo deleted the max-rozen-oss-db/stack/claude-headless-routing branch October 13, 2026 13:48
luisscabral pushed a commit to luisscabral/unity-gateway that referenced this pull request Oct 13, 2026
Resolve the conflict in tests/test_claude_smart_routing_v2.py: keep the
Ctrl-U prefix assertion in test_direct_switch_restore_and_replay and the
new TestV2HeadlessClaude tests from databricks#1098.

Co-authored-by: Isaac <no-reply@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants