Skip to content

fix(mitm): route Claude Code standalone MITM traffic - #7574

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.49from
dongwook-chan:feat/claude-code-mitm-routing
Jul 19, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.49from
dongwook-chan:feat/claude-code-mitm-routing

Conversation

@dongwook-chan

@dongwook-chan dongwook-chan commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add per-agent route config to the standalone MITM server
  • route Claude Code and Kiro /v1/messages traffic to OmniRoute /v1/messages
  • read model aliases from each agent's own mitmAlias namespace instead of always using antigravity
  • preserve existing Antigravity CloudCode routing

Closes #7572

Tests

  • node --import tsx/esm --test tests/unit/mitm-server-claude-code-routing.test.ts
  • node --import tsx/esm --test tests/unit/mitm-handler-claudeCode.test.ts tests/unit/mitm-handler-antigravity.test.ts tests/unit/antigravity-mitm-model-resolution.test.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces agent-specific routing configurations in the MITM server to support Claude Code and Kiro alongside Antigravity, mapping models dynamically using their respective alias keys and forwarding their traffic to an Anthropic-compatible messages endpoint. Unit tests have also been added to verify this routing behavior. The review feedback suggests a great improvement to avoid hardcoding specific agent IDs in the interception logic by leveraging the newly introduced route configuration's routerPath property, and updating the unit tests accordingly to prevent fragile string matching.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/mitm/server.cjs Outdated
Comment on lines +500 to +503
const forward =
agentId === "claude-code" || agentId === "kiro"
? { format: "anthropic", url: ROUTER_MESSAGES_URL }
: forwardShim.resolveForwardTarget(ROUTER_BASE_URL, body);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Instead of hardcoding specific agent IDs (claude-code and kiro) in the intercept function, you should leverage the newly introduced AGENT_ROUTE_CONFIG and check the configured routerPath. This makes the routing logic much more maintainable and extensible when new agents are added in the future.

    const config = getAgentRouteConfig(agentId);
    const forward =
      config.routerPath === "/v1/messages"
        ? { format: "anthropic", url: ROUTER_MESSAGES_URL }
        : forwardShim.resolveForwardTarget(ROUTER_BASE_URL, body);

Comment on lines +15 to +19
test("standalone MITM server forwards Claude Code traffic to the Anthropic-compatible route", () => {
assert.match(src, /const ROUTER_MESSAGES_URL = `\$\{ROUTER_BASE_URL\}\/v1\/messages`/);
assert.match(src, /agentId === "claude-code" \|\| agentId === "kiro"/);
assert.match(src, /url: ROUTER_MESSAGES_URL/);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Asserting on exact source code string matches (like /agentId === "claude-code" \|\| agentId === "kiro"/) makes the tests highly fragile and prevents refactoring. Since we refactored the routing logic to use the AGENT_ROUTE_CONFIG's routerPath property, we should update this test assertion accordingly.

Suggested change
test("standalone MITM server forwards Claude Code traffic to the Anthropic-compatible route", () => {
assert.match(src, /const ROUTER_MESSAGES_URL = `\$\{ROUTER_BASE_URL\}\/v1\/messages`/);
assert.match(src, /agentId === "claude-code" \|\| agentId === "kiro"/);
assert.match(src, /url: ROUTER_MESSAGES_URL/);
});
test("standalone MITM server forwards Claude Code traffic to the Anthropic-compatible route", () => {
assert.match(src, /const ROUTER_MESSAGES_URL = `\$\{ROUTER_BASE_URL\}\/v1\/messages`/);
assert.match(src, /config\.routerPath === "\/v1\/messages"/);
assert.match(src, /url: ROUTER_MESSAGES_URL/);
});

@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks for tackling #7572 — the standalone MITM server genuinely has no Claude Code/Kiro routing today, and the per-agent AGENT_ROUTE_CONFIG shape you introduced is a clean fit with the existing AgentId naming (targets/claudeCode.ts, targets/kiro.ts).

This PR is opened against main, which is currently ~9 commits behind release/v3.8.49 in exactly the file you touched. In particular, PR #7228 (already on release) renamed getMappedModel(model) to getMappedOverride(model) and changed its return shape to a normalized {model?, reasoningEffort?} object to support Antigravity reasoning-effort overrides. A merge probe against the current release tip produces a real content conflict in that exact function, so this can't merge as-is without losing the reasoning-effort override behavior.

Could you: (1) retarget/rebase this PR onto release/v3.8.49 and reconcile with getMappedOverride's structured-override return shape (adding the aliasKey selection on top of it rather than replacing it), and (2) wire the forward-target decision to actually read AGENT_ROUTE_CONFIG[...].routerPath instead of the agentId === "claude-code" || agentId === "kiro" string check (per the gemini-code-assist bot's review comment on this PR)? Also worth noting: your added test asserts via regex against the raw source file text rather than exercising the routing function's actual behavior — once rebased it'll need updating anyway, so it'd help to make it call the real function with a mocked DB/host instead.

Separately, heads up: PR #7582 touches the same function for a related but different fix (route-alias fallback) and is also branched slightly before #7228 landed — whichever of the two lands first, the other will need a follow-up rebase.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.49 July 17, 2026 19:59
@dongwook-chan
dongwook-chan force-pushed the feat/claude-code-mitm-routing branch from 9d6aedf to c390cb3 Compare July 18, 2026 05:22
@dongwook-chan

dongwook-chan commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Review feedback addressed.

  • Rebased/retargeted this PR onto release/v3.8.49.
  • Preserved the newer getMappedOverride(model) structured override semantics, including { model?, reasoningEffort? }, while adding per-agent alias namespace selection.
  • Replaced hardcoded Claude/Kiro forward-target checks with route config via AGENT_ROUTE_CONFIG[agentId].routerPath.
  • Replaced fragile source-regex coverage with behavior tests for route config, forward-target resolution, SQLite alias resolution, and legacy JSON fallback alias resolution.

Verification run locally:

node --import tsx/esm --test tests/unit/mitm-server-claude-code-routing.test.ts tests/unit/mitm-alias-config-shim.test.ts tests/unit/mitm-forward-target.test.ts

Result: 14 tests passed.

Current PR state: mergeable, Semgrep passed.

Sync with the current release tip (9 commits ahead of this PR's fork
point; none touch src/mitm/ or the standaloneRouting shim, so no
conflict resolution was needed here).

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
@diegosouzapw
diegosouzapw merged commit 60bcf6e into diegosouzapw:release/v3.8.49 Jul 19, 2026
3 checks passed
@diegosouzapw

Copy link
Copy Markdown
Owner

Merged into release/v3.8.49 — thank you for the contribution, @dongwook-chan! 🎉 Validated in today's full-suite merge-train (33 PRs, 19k+ tests green) before landing.

@diegosouzapw diegosouzapw mentioned this pull request Jul 23, 2026
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.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.

fix(backend): Standalone MITM should route Claude Code /v1/messages through per-agent aliases

2 participants