feat(cc-bridge): native Anthropic Messages adapter for Claude Code - #45
Open
chaoshou-coder wants to merge 2 commits into
Open
feat(cc-bridge): native Anthropic Messages adapter for Claude Code#45chaoshou-coder wants to merge 2 commits into
chaoshou-coder wants to merge 2 commits into
Conversation
Thin protocol bridge letting Claude Code talk to a local baseRT server: /v1/messages <-> /v1/chat/completions with native SSE streaming, thinking and tool blocks, keep-alive pings, and cancellation propagation. Inbound requests require a master key; binds to 127.0.0.1 by default; the classifier-bypass short-circuit is off unless explicitly enabled. Includes pytest unit and end-to-end tests.
English docs for the adapter: setup and flags (README.md), protocol and security details (TECHNICAL.md), a Claude Code client guide, a chat-template analysis with a vendored froggeric v21.3 reference (MIT), and a root README/CHANGELOG entry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR description —
feat/anthropic-messages-adapter→ baseRTWhat / Why
Adds cc-bridge: a native Anthropic Messages API adapter that lets Claude
Code talk to a local
basert servedirectly (/v1/messages↔/v1/chat/completions), with native SSE streaming (thinking / text / tool_useblocks), keep-alive pings, and cancellation propagation.
The protocol is generated natively instead of via LiteLLM, because LiteLLM was
measured to fail in two compounding ways (see
docs/proposals/native-anthropic-adapter.mdand TECHNICAL.md §1):content(use_chat_completions_api: true drops content when provider returns reasoning_content BerriAI/litellm#27492, open).and retries non-streaming — straight into bug 1. baseRT's ~35s prefill of a
23.5k-token prompt triggers this on every heavy request.
Security posture
--master-keyis required: every inbound/v1/messagesandcount_tokensrequest must present it (x-api-keyorAuthorization: Bearer), otherwise rejected with an Anthropic-style 401 before the bodyis parsed.
0.0.0.0requires an explicit--host.--allow-classifier-bypass) is off bydefault and only matches a narrow heuristic (single user message, no
tools, non-streaming, non-
localmodel name). Disabling Claude Code'sonline harm detection is an operator decision, documented in TECHNICAL.md
§3.7.
--debug-dir) is off by default./v1/messages/count_tokensand streamingmessage_startusage report an upper-bound estimate, never a fabricated 0.What is cc-bridge?
A standalone deployment component, explicitly part of the baseRT ecosystem
(own directory, own venv, own tests). The engine-side gaps it works around are
tracked as upstream issues, not papered over in this PR:
basert serve: support loading an external chat template (--chat-template) #42--chat-template(external chat templates) — removes thesystem-merging workaround
basert serve: allow disabling or limiting thinking per request #43 per-request thinking control — removes--max-tokens-overridebasert serve: concurrent-client handling (continuous batching) #44 concurrent-client behavior — removes the timeout-based survival logicWhy issues and PR are opened together
The gaps this adapter works around (external chat templates, per-request
thinking control, single-slot queueing) are product requirements that belong
in the engine, not workarounds frozen into a bridge. Opening issues #42–#44
side-by-side with this PR is deliberate: the adapter is an honest bridge
today, and each issue tracks the engine change that would let the
corresponding workaround be removed. I would rather file a requirement and
ship the piece I can build than file a requirement alone — and I am happy to
do the engine-side work too, if maintainers point me at the right files,
knowing it will take me longer than it would take you.
Tests
cc-bridge/tests/— 38 pytest cases, all green locally:tool_result ordering, sampling passthrough)
stream via
[DONE]and abrupt close, truncation →max_tokens,classifier-bypass gating)
Run:
cd cc-bridge && python3 -m venv .venv && .venv/bin/pip install -r requirements-dev.txt && .venv/bin/python -m pytestNote: baseRT's CI is C++/Rust only; we deliberately did not add a Python job
in this PR. If the maintainers want it covered in CI, we'll add a job in a
follow-up.
Intentional deviations from the review
cc-bridge/misc/chat-template-fix.mdand the vendored froggeric v21.3template are kept as reference material for issue chore(docs): repoint repo references prabod → basecompute #1 (with a full MIT
license header), rather than deleted.
A note from the contributor
This is my first open-source contribution, and I want to be upfront about
what kind of contributor I am. I do not know C or Rust, and my Python is
basic. What I can reliably offer is careful work on the parts that do not
need deep engine knowledge: integration glue like this adapter, tests,
triage, and documentation — I plan to follow up with a Chinese translation of
the website and repository docs, and more issues and PRs after this one. I
have the time to keep contributing, and I would rather earn my place here as
someone who ships working, reviewed code than as someone who only files
requests. Any process or quality feedback is genuinely welcome — I expect to
make beginner mistakes, and I will learn from them.
Thank you for building baseRT for Apple Silicon users. That is why I am here.
Real-session evidence
A full multi-turn Claude Code tool-use session ran against this branch on
2026-08-12 (01:21–01:34, 29 requests, ~13 minutes): WebSearch-style tools,
tool_calls/tool_resultloops with context growing from 22.4k to 26.0kprompt tokens, streaming and non-streaming paths, and one client disconnect
at 01:34:19 that baseRT logged as
[disconnect] client closed connection; aborted stream after 1 token(s)— the adapter's abort propagation workingend-to-end.
The complete request/response records (raw
/v1/messagesbodies and exactSSE streams, plus the matching
basert servelog) are packaged ascc-bridge-tool-run-logs.tar.gz(560 KB) — I will attach it in a comment tothis PR. Representative basert log lines:
Changelog
CHANGELOG.md gets an
[Unreleased]entry; the root README gains a cc-bridgesection.