Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(models): map Claude aliases to GPT backends
Co-Authored-By: Claude <noreply@anthropic.com>
  • Loading branch information
wangcansunking and claude committed Aug 5, 2026
commit afbaa3d1b4d6ecc46eebbde37f23d35688d8b8cb
6 changes: 6 additions & 0 deletions .changes/1785899682931-claude-model-map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: minor
---
feat(models): add an opt-in `/claude-map` compatibility mode for GPT-only Copilot accounts.

When enabled, Anthropic discovery exposes native Claude model identities backed by exact live GPT 5.x targets, and routes requests through the target model's real endpoint, reasoning support, and context window. Missing backends are hidden, original GPT entries remain available, OpenAI/Codex discovery is unchanged, and the feature defaults off.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Prefer commands? Type `/` to see them all. The essentials:
| Command | What it does |
|---|---|
| `/setup-claude` · `/setup-codex` | Point Claude Code / Codex at copilot-reverse |
| `/model` | Switch the chat model (1M-context models marked) |
| `/model` | Switch the chat model (1M-context models marked; active Claude→GPT mappings shown) |
| `/claude-map [on\|off]` | Opt in/out of native Claude model names backed by available GPT 5.x models |
| `/network` | Choose access mode: localhost (private) or LAN (shared, key required) |
| `/status` · `/doctor` | Is everything healthy? (`/status` shows each client's scope + model) |
| `/logs` · `/metrics` | What ran, what failed, and why |
Expand Down Expand Up @@ -111,6 +112,13 @@ you don't trade fidelity for a free backend.
- **🪟 True 1M-context models.** 1M-window models show up in Claude Code's native picker with the right
badge, and copilot-reverse writes the correct context-window hint so the client sizes its context bar
and auto-compaction to the *real* window — no more "context 100%" at 15%.
- **🔀 Optional Claude names for GPT-only accounts.** If Copilot currently offers GPT 5.x but no usable
Claude models, run `/claude-map on`. Anthropic discovery keeps the original GPT rows and adds native
Claude identities only when their exact backend is live: Haiku 4.5→gpt-5.4, Sonnet 4.6→gpt-5.5,
Opus 4.8→gpt-5.6-luna, Opus 5→gpt-5.6-sol, Sonnet 5→gpt-5.6-terra. Claude Code/Desktop still see
native Claude names; the proxy's `/model` shows the arrows for transparency. Context, reasoning, and
endpoint routing follow the real GPT backend. The feature defaults **off**; `/claude-map off` restores
the previous behavior. Reopen Claude's `/model` picker after a toggle (restart the client if cached).
- **🛠 Tool use, vision, web search — both directions.** Function/tool calls translate faithfully each
way (even models that emit tool calls as inline XML are recovered), images round-trip, and
`web_search` runs server-side through the gateway and comes back as a grounded answer — no tool leaks
Expand Down
108 changes: 108 additions & 0 deletions docs/superpowers/specs/2026-08-05-claude-model-map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Claude Model Map Specification

## Problem

Some Copilot accounts advertise GPT 5.x models but no usable Claude models. Claude Code and Claude Desktop still work best when the Anthropic gateway advertises canonical Claude model IDs: their native model picker, context sizing, thinking UI, and tool protocol all key off those IDs.

copilot-reverse needs an opt-in compatibility mode that presents native Claude identities to Anthropic clients while executing each request on a known GPT backend. The existing behavior must remain unchanged unless the user explicitly enables the mode.

## User interface

The copilot-reverse TUI exposes one command:

- `/claude-map` — show the current `on`/`off` state and the complete preset map.
- `/claude-map on` — persist enabled state and restart the worker.
- `/claude-map off` — persist disabled state and restart the worker.

The command is listed by `/help` and slash autocomplete. Repeating the current state is idempotent. Any other argument returns `usage: /claude-map [on|off]`, does not change preferences, and does not restart the worker.

A successful state change tells the user to reopen Claude's `/model` picker and to restart Claude Code or Claude Desktop if their discovery cache remains stale. The command never deletes or rewrites a client's private discovery cache.

If persistence succeeds but the worker restart fails, the TUI reports both facts: the preference was saved, but activation is incomplete until `/restart` succeeds. It must not claim that the new routing behavior is already active.

## Preset mapping

| Claude client model | Copilot backend |
|---|---|
| `claude-haiku-4-5` | `gpt-5.4` |
| `claude-sonnet-4-6` | `gpt-5.5` |
| `claude-opus-4-8` | `gpt-5.6-luna` |
| `claude-opus-5` | `gpt-5.6-sol` |
| `claude-sonnet-5` | `gpt-5.6-terra` |

`[1m]` is a Claude Code client suffix, not part of a map key. Resolution strips it before consulting the map.

## Default and persistence

The feature defaults to `off` for a missing, unreadable, corrupt, or non-boolean preference. Upgrading copilot-reverse therefore changes no discovery or routing behavior.

The state is persisted in the existing `prefs.json` store. Writing it preserves chat-model and change-banner preferences.

The worker snapshots the state at startup. A TUI toggle restarts the worker through the existing supervisor control API so the saved state takes effect atomically for new requests.

## Discovery behavior

### Disabled

Both discovery endpoints and request resolution behave exactly as before this feature:

- Anthropic `/anthropic/v1/models` canonicalizes real Copilot Claude IDs and passes non-Claude IDs through.
- OpenAI `/openai/models` lists real Copilot model IDs.
- No preset alias is synthesized or resolved.

### Enabled

OpenAI discovery remains unchanged and lists only real Copilot model IDs.

Anthropic discovery retains every real Copilot model entry and appends a Claude alias only when its mapped GPT target is present in the live Copilot model list. A missing target hides its alias; there is no silent fallback to a different GPT model.

Synthesized entries use canonical Claude IDs and native display names (`Opus 5`, `Sonnet 5`, and so on). Claude Code and Desktop must therefore look native: the mapping arrow is not included in Anthropic `display_name`.

The copilot-reverse TUI model picker is intentionally more diagnostic. It retains original GPT rows and labels available aliases as `claude-opus-5 → gpt-5.6-sol`, without changing the submitted model value.

## Routing behavior

When enabled, request resolution follows this order:

1. strip the optional `[1m]` suffix;
2. resolve an exact preset Claude alias whose backend is live;
3. apply the existing user `modelMap` exact entry;
4. use existing fuzzy matching;
5. apply the existing `*` fallback or pass through.

When disabled, step 2 is absent.

Unavailable aliases are not resolved even if a caller manually submits one. This preserves the discovery invariant: the compatibility layer never promises a backend that discovery did not confirm.

The resolved GPT ID is placed in the canonical request before provider selection. Consequently endpoint selection (`/chat/completions` versus `/responses`), reasoning support, metrics, and upstream errors all use the real GPT backend ID.

## Capability and context semantics

A synthesized alias inherits its backend GPT model's live context limit. That limit determines:

- whether the canonical Claude ID carries `[1m]`;
- the context window displayed by the copilot-reverse picker;
- `CLAUDE_CODE_AUTO_COMPACT_WINDOW` written by Claude setup;
- local and LAN setup context sizing.

The Claude alias's historical/default window must not override the real GPT backend. If no live limit is available, the alias is still routable but no fabricated numeric setup limit is written; canonical fallback behavior remains available for the ID itself.

## Non-goals

- No arbitrary user-edited mapping table in this version.
- No changes to OpenAI/Codex model names or routing.
- No interception of Claude Code's own slash commands.
- No automatic Claude cache deletion.
- No claim that a GPT backend has Claude model quality or identical model-specific behavior; only the Anthropic client protocol and UI remain native.

## Acceptance criteria

1. With no preference, the full existing discovery and routing suites remain unchanged.
2. Enabling the mode persists across restart and disabling restores old behavior.
3. Anthropic discovery includes only aliases whose exact GPT targets are live, while retaining original GPT entries.
4. OpenAI discovery never contains synthesized aliases.
5. A real Anthropic request using a published alias reaches the provider as the mapped GPT ID and follows that backend's endpoint/reasoning capabilities.
6. Alias context metadata comes from the backend GPT limit.
7. `/claude-map` status/toggle/usage and `/model` arrow labels are covered by TUI interaction tests.
8. Hermetic E2E covers discovery-to-provider routing in both feature states.
9. Real CLI E2E drives `claude -p` through one available alias and records `SKIP`, never failure, if none of the preset GPT targets is available.
14 changes: 14 additions & 0 deletions e2e/RESULTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
Latest run of the end-to-end suite. Regenerate after every code change with `npm run test:e2e`
and update this file (paste the summary).

- **2026-08-05 (opt-in Claude model map for GPT-only Copilot accounts)** — `/claude-map on|off`
persists an explicit default-off compatibility mode. When enabled, Anthropic discovery retains the
real GPT rows and adds only native Claude aliases whose exact GPT targets are live; alias requests
resolve before provider selection, so endpoint/reasoning/context capabilities and metrics use the
actual GPT backend. Missing targets are hidden and OpenAI/Codex discovery is unchanged. Verification:
**742/742 full Vitest tests**, **55/55 Vitest E2E**, TypeScript build clean; Docker HTTP edge E2E
**76/76 passed**; real Docker CLI E2E against live Copilot **0 FAIL (`✅ ALL PASSED`)**, including
Claude Code 2.1.220 discovery of `claude-opus-5[1m]`, a real `claude -p` turn through
`gpt-5.6-sol`, multi-turn resume, tools, effort, image transport, and Codex regressions (**34/34 recorded checks passed**). Optional OCR
and latest-image colour-quality assertions record SKIP under mapped GPT vision; request validity and
no-413 guards remain hard PASS gates. Follow-up setup regression coverage proves `/setup-claude`
renders the same `Claude → GPT` labels and writes the native Claude alias (not the backend id), while
enabling the map heals an unavailable persisted TUI model to the first live alias.

- **2026-07-03 (context editing DYNAMIC budget + reactive 413 retry — issue #52 follow-up)** — issue #52
showed the 413 returns when a screenshot-heavy session ALSO carries a large conversation. The 413 is on
the whole request body, but context editing budgeted only image bytes against a fixed 3.5MB cap — so a
Expand Down
12 changes: 12 additions & 0 deletions e2e/cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ provider, no network. Spec: `responses.e2e.test.ts`, `describe("E2E: Codex /resp
| EP-42 | tools carried in an `additional_tools` input item (Codex 0.145+ / gpt-5.6) | the tools reach the provider (not dropped); the `additional_tools` item never leaks as a message (#4231) |
| EP-43 | prior `custom_tool_call` + `custom_tool_call_output` in `input` | round-trip to the provider as `tool_use` (raw-string input wrapped as `{input}`) + `tool_result` (#4231) |

### Claude model compatibility map (EP-44 … EP-47)

The map is opt-in and snapshots the persisted preference at worker startup. Hermetic tests inject a live
model list and fake provider so discovery and resolved routing are proven without Copilot quota.

| ID | Scenario | Expected result |
|----|----------|-----------------|
| EP-44 | map disabled, Anthropic + OpenAI discovery | existing real-model lists are unchanged; no preset Claude alias is synthesized |
| EP-45 | map enabled with only some preset GPT targets live | Anthropic discovery retains real models and adds only aliases whose exact targets are live; OpenAI discovery adds none |
| EP-46 | Anthropic request using a published `[1m]` Claude alias | provider receives the mapped GPT ID, not the alias; metrics also record the GPT backend |
| EP-47 | mapped backend advertises a ~1.1M window | alias discovery/setup metadata uses that backend window and carries the canonical `[1m]` suffix |

### Multi-turn continuity (EP-39 … EP-41)

The Anthropic/OpenAI wire is **stateless** — the client (Claude Code on `--resume`, or an interactive
Expand Down
Loading
Loading