Files
magpie/internal
yetone e02df9e226 claude: a tool_choice none turn is offered the client's tools, and may call none (bbfatx on X)
bbfatx on X: the Claude subscription bridge spends more of the quota
than it should. Suggestion 1 was to keep a turn's tool definitions apart
from whether it may call them. bridgeTools dropped every tool for
tool_choice none. Anthropic caches a prompt as tools, then system, then
messages, so such a turn (a title or summary asked with the tools as
ever) was a prefix the cache had never seen. All of it was written
again, Claude Code's own tools and system prompt included.

Now a none turn's MCP helper offers every tool the client sent. A call
the turn makes anyway is answered at once with an error result
(mcpCall), and toolStart treats it as Claude Code's own call, as it does
magpie's web search. The client never sees it, and the reply goes on in
words. A named tool_choice still offers only that tool. The allowed set
(subscriptionRun.allowed) is set for each turn: at start, on resume, and
with tool results (a client may choose none once it has its results).
The system prompt and the turn's text are unchanged.

Measured with the real Claude Code 2.1.316 on mote, in a sandbox HOME
and CLAUDE_CONFIG_DIR, against a stand-in Anthropic that counts cache
reads and writes the way Anthropic's cache does (30 MCP tools):
- the same turn with no tools: 0 read, 7595 written;
- told whole in a new session with its tools: 15780 read (tools and
  system), only the history written.

Run (mote, go1.26.8):
- go test -tags nogui ./internal/gateway -run TestClaudeToolChoiceNoneKeepsTheTools: ok.
- go test -tags nogui ./internal/gateway -run 'Claude|Bridge|ToolChoice|Subscription' -count=1: ok (54s).

Broken by hand:
- HEAD's claude_subscription.go: red, the helper was offered [], the
  call was not refused, and the client was shown a tool_use.
- Only the refusal turned off (mcpCall and toolStart): red, the call
  was shown to the client.

Not tried: a real client's tool_choice none request through the gateway
to a real account. The measurement drove Claude Code directly.

Not taken from the suggestion: nothing of the fork's code is ported. The
fork drops a none turn's tool calls in its own runtime. Here the call is
refused where magpie already answers its web search. The only new text
upstream is that refusal, a short tool error result naming neither
magpie nor a vendor, and only when the model calls a tool anyway.
2026-11-01 16:33:06 +08:00
..
…
…
…
…
…