## Description
Closes#4248. The OpenCode 2.x plugin routes models through Headroom by
rewriting model `baseURL`s in `ctx.model.transform`, but it recognized
only the OpenAI wires (`openai-compatible`, `*/chat`, `*/responses`).
Copilot's Claude models use `@opencode/ai/providers/anthropic` (Messages
wire), so they were skipped and their requests never reached the proxy,
while Copilot GPT models kept working.
`modelWireSuffix` now also maps `anthropic`, `anthropic-compatible` and
model-level `*/messages` packages to `/messages`, reusing the existing
rewrite. The config-level `headroom wrap opencode` path cannot cover
Copilot because OpenCode creates that provider dynamically.
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)
## Changes Made
<details>
<summary>changes details</summary>
- `plugins/opencode/src/plugin.ts`: rename `openAiWireSuffix` to
`modelWireSuffix`, map the Anthropic Messages wires to `/messages`.
- `plugins/opencode/README.md`: document that Anthropic Messages models
are rewritten too.
- `plugins/opencode/src/plugin.test.ts`: three new cases plus a narrowed
negative case.
- `headroom/providers/opencode/_dist/index.js`: rebuilt so the wheel
bundle stays byte-identical (CI `cmp` gate).
</details>
## Testing
<details>
<summary>testing details</summary>
- [x] Unit tests pass (`npm test -- --maxWorkers=2`: 66 passed at
current head)
- [x] Type checking passes (`npm run typecheck`)
- [x] Linting: repo lint is Python-only; plugin gates are typecheck,
build, test, bundle `cmp`, all run
- [x] New tests added
- [x] Manual testing performed — actual OpenCode CLI plus real proxy and
controlled upstream; live Copilot not tested
### Test Output
<!-- Paste relevant command output or artifact links here -->
<details><summary>commands and output</summary>
```text
npm test -- --maxWorkers=2 -> 4 files, 66 passed at 95ef917320 | npm run typecheck -> exit 0 | cmp dist-standalone/index.js headroom/providers/opencode/_dist/index.js -> BUNDLE_MATCH
```
The earlier red/green check recorded three new rewrite cases failing
before the fix (`3 failed | 61 passed`). Fresh current-head validation
is 66/66 plugin tests plus a successful no-emit typecheck;
full-repository Python pytest/Ruff were not run for this transport-only
verification.
</details>
</details>
## Real Behavior Proof
- Environment: Current head `95ef9173`, macOS arm64, official OpenCode
2.2.5, Python 3.12.8, Node 26.13.0; real plugin, Anthropic adapter and
Headroom proxy; local SSE upstream; Python-only transport mode.
- Exact command / steps: Build both plugin bundles, then run the runtime
harness with the official CLI in four scenarios. Exact commands, macOS
fixture adaptation, and the committed Linux reproduction are in the
details below.
- Observed result: All four actual CLI scenarios passed; auth retained,
internal headers stripped, streamed text and `step_finish` returned.
Current-head plugin tests 66/66, typecheck and byte-for-byte wheel
bundle comparison pass.
- Not tested: Live Copilot account/discovery or endpoint compatibility,
live z.ai, Rust/compression/cache, TLS, retries, latency, production
rollout, and other OpenCode versions. Full limits are below.
| Actual OpenCode scenario | Plugin | Proxy POSTs | Upstream POSTs |
Observed upstream path |
| --- | --- | --- | --- | --- |
| Baseline | disabled | 0 | 2 | `/messages` |
| Copilot-shaped root URL | enabled | 2 | 2 | `/v1/messages` |
| `/v1` gateway | enabled | 2 | 2 | `/v1/messages` |
| Prefixed gateway | enabled | 0 | 2 | `/api/coding/paas/v4/messages` |
<details>
<summary>Current-head transport evidence and platform-specific harness
setup</summary>
- Environment: Fresh run on 2026-11-04 at 22:10 UTC, PR head
`95ef9173200eb3b0f047e8fe661e1d9924d41c82`; macOS 27.3 arm64, Python
3.12.8, Node 26.13.0, npm 11.20.0, official installed **OpenCode 2.2.5**
CLI, source Headroom 0.42.1-dev, headroom-opencode 0.42.0. OpenCode
loaded the built standalone plugin itself and used its real
`@opencode/ai/providers/anthropic` adapter. Only the upstream API was a
strict-path local SSE fixture. The proxy explicitly ran in **Python-only
degraded mode**, with `HEADROOM_REQUIRE_RUST_CORE=false`, `--no-optimize
--no-cache`; Rust/compression is outside this proof.
- Exact command / steps: Install proxy dependencies with `uv sync
--frozen --extra proxy --no-default-groups --no-install-project --python
<CPython-3.12.8>`. In `plugins/opencode`, run `npm ci --ignore-scripts
--no-audit --no-fund --fetch-timeout=45000`, `npm run build`, and `npm
run build:standalone`. Run `.venv/bin/python
.cache/runtime-proof-macos.py --opencode
/Applications/OpenCode.app/Contents/Resources/opencode-cli --output
.cache/runtime-proof-macos`. This local copy of the checked-in [runtime
harness](https://github.com/headroomlabs-ai/headroom/blob/95ef9173200eb3b0f047e8fe661e1d9924d41c82/plugins/opencode/scripts/runtime-proof.py)
adapts its Linux loopback fixture to macOS as detailed below. For each
scenario the harness starts a real Headroom proxy and upstream, then
executes `opencode-cli run --standalone --print-logs --log-level debug
--format json 'Reply with HEADROOM_RUNTIME_OK.'` with isolated config,
synthetic auth, model-catalog fetching/updates disabled and a 60-second
timeout. It never invokes `headroomSetup` manually or replaces the model
request with `fetch`.
- Observed result: **All four actual CLI scenarios passed in 40.05
seconds.** Both title and user-turn requests traversed the expected
route, preserved the exact synthetic bearer/API-key values, and sent no
internal `x-headroom-*` headers upstream. Every user turn produced the
text event `HEADROOM_RUNTIME_OK` and a completed `step_finish` after
individual SSE events were flushed by the fixture. The rebuilt
standalone bundle matched the checked-in wheel bundle byte-for-byte,
SHA-256
`78fae6e51ef5d1c534a3299216ba3b467131c17594de34f0fe8bb7b5be4b7533`. No
tracked files or lockfiles changed during this run; all eight
proxy/upstream listening ports were closed afterward and no owned
CLI/proxy process remained.
- Not tested: Live GitHub Copilot discovery, subscription auth/token
refresh, Copilot-specific headers, actual model inference, or whether
the live Copilot origin accepts `/v1/messages`. This is a configured
Copilot-shaped provider, **not** native Copilot discovery. The prefix
control uses the real Anthropic adapter, not a live z.ai account or its
specific adapter. Rust core, optimization/compression/cache,
HTTPS/HTTP2, latency/backpressure, retry/rate-limit behavior, production
rollout, and OpenCode versions other than 2.2.5 were not exercised.
The proxied root-URL run recorded the actual OpenCode user agent and
original path at Headroom:
```text
proxy inbound: POST /v1/messages
user-agent: opencode/latest/2.2.5/cli
x-headroom-original-path: /messages
proxy outbound: POST http://[::ffff:7f00:1]:<fixture-port>/v1/messages
upstream: model=claude-sonnet-4-6, stream=true
upstream: authorization and x-api-key exactly matched synthetic fixtures
upstream: anthropic-version=2023-06-01; no x-headroom-* headers
client: text=HEADROOM_RUNTIME_OK; step_finish present
```
The root origin deliberately distinguishes direct `/messages` from
proxied `/v1/messages`. The fixture rejects an unexpected endpoint
rather than answering every path. These observations establish the
plugin/proxy transport boundary; they do **not** establish live Copilot
endpoint compatibility. The `/v1` origin remains `/v1/messages`, and the
prefixed origin remains `/api/coding/paas/v4/messages` with zero model
POSTs reaching Headroom.
The committed harness originally binds `127.0.0.2`, unavailable on this
macOS host (`Errno 49`). The ignored local copy uses an IPv4-mapped
loopback address with an IPv6 HTTP server and WHATWG-normalized fixture
URLs. It also fixes its checkout-relative path after copying, explicitly
allowlists only that fixture origin, sets supported offline/update
flags, creates its isolated proxy cache, accepts an existing isolated
home directory, and bounds each CLI run to 60 seconds. It does not
change production code or the expected endpoint/auth/SSE assertions. No
network interfaces or account settings were changed. All server
processes are scoped to the harness and terminated/waited in cleanup.
For the original independently recorded Linux run, reproducible
commands, and committed machine-readable results, see
[RUNTIME_PROOF.md](https://github.com/headroomlabs-ai/headroom/blob/95ef9173200eb3b0f047e8fe661e1d9924d41c82/plugins/opencode/RUNTIME_PROOF.md)
and
[runtime-proof-result.json](https://github.com/headroomlabs-ai/headroom/blob/95ef9173200eb3b0f047e8fe661e1d9924d41c82/plugins/opencode/scripts/runtime-proof-result.json).
Those artifacts explicitly identify their earlier source revision and
environment; the current-head macOS build hash above is from this fresh
run. Both proofs execute an actual OpenCode 2.x process. The earlier
PR-body experiment that manually supplied a minimal plugin context and
Node `fetch` has been superseded here.
</details>
## Runtime Rollout Safety
- Rollout-managed feature(s): none.
- Minimum rollout channel: n/a.
- Stable/default behavior changed: only previously skipped Anthropic
Messages models are rewritten; the negative test pins the rest.
- Kill switch / disable path: disable the plugin.
- Unsafe override required: no.
- Qualification impact: none expected.
- Rollback path: revert the commit; no state changes.
## Review Readiness
- [x] I have performed a self-review
- [x] This PR is ready for human review
## Checklist
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md`
## Screenshots (if applicable)
N/A — no UI change.
## Additional Notes
The rebuilt `_dist` bundle is part of the diff because CI enforces byte
equality with `dist-standalone`. Actual OpenCode transport is now
verified with a controlled upstream. Live provider/account behavior and
the additional limits listed above remain unverified.
<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4594"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
---------
Co-authored-by: JD Davis <mxjerrett@gmail.com>