Attach: set ENABLE_TOOL_SEARCH=true so the gateway base URL doesn't force eager tool loading#288
Conversation
…orce eager tool loading Claude Code disables deferred tool loading whenever ANTHROPIC_BASE_URL is a non-first-party host, sending every tool schema up front (~50k tokens of per-session context bloat). The gateway is a pure pass-through that forwards tool_reference blocks, so attach now sets ENABLE_TOOL_SEARCH=true to keep deferred loading on. Only manage the key when it is ours: a value the user set themselves is left untouched and unrecorded, so detach never clobbers it. The core detach scopes the prev_base_url restore to ANTHROPIC_BASE_URL only and removes any other managed key, so it can't stamp the base URL onto ENABLE_TOOL_SEARCH. Documents the rationale in LLP 0045.
|
neutral review — round 1 · head Independent worker-tier review in an isolated worktree. No blocking, major, or actionable minor code findings. Tests: @ref anchors: both resolve against Correctness —
The One non-blocking design note (maintainer's call, not actionable by neutral): the PR edits Verdict: approve — mergeable ∧ green ∧ reviewed. Held for a maintainer to merge (neutral does not merge contributor PRs). |
What
When
hyp attachpoints Claude Code at the local gateway, it now also setsenv.ENABLE_TOOL_SEARCH="true".Why
Claude Code disables deferred (on-demand) tool loading whenever
ANTHROPIC_BASE_URLis a non-first-party host: it assumes the proxy can'tforward
tool_referenceblocks and sends every tool schema up front instead.That is tens of thousands of tokens of per-session context bloat (attached
sessions started ~84k vs ~30k detached). The gateway is innocent: it is a pure
pass-through that does forward
tool_reference. The switch is Claude Code's,keyed only on the base URL not being Anthropic's.
ENABLE_TOOL_SEARCH=trueisthe documented override for proxies that forward everything.
Notes
value the user set themselves (and that a prior marker did not record as ours)
is left untouched and is not recorded in
managed.env, so detach won't removeit. Same never-clobber stance the base URL takes.
the single
prev_base_url. With a second managed key that would stamp the baseURL onto
ENABLE_TOOL_SEARCHfor any user who had a prior custom base URL. Therestore is now scoped to
ANTHROPIC_BASE_URL; other managed keys are removed.#enable_tool_search-...).Testing
npm test(2144 pass), plus new attach and detach coverage.npm run smoke -- claude_attach_detachpasses (byte-for-byte restore holds).