Skip to content

Attach: set ENABLE_TOOL_SEARCH=true so the gateway base URL doesn't force eager tool loading#288

Merged
platypii merged 1 commit into
masterfrom
fix/attach-enable-tool-search
Jul 8, 2026
Merged

Attach: set ENABLE_TOOL_SEARCH=true so the gateway base URL doesn't force eager tool loading#288
platypii merged 1 commit into
masterfrom
fix/attach-enable-tool-search

Conversation

@platypii

@platypii platypii commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What

When hyp attach points Claude Code at the local gateway, it now also sets
env.ENABLE_TOOL_SEARCH="true".

Why

Claude Code disables deferred (on-demand) tool loading whenever
ANTHROPIC_BASE_URL is a non-first-party host: it assumes the proxy can't
forward tool_reference blocks 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=true is
the documented override for proxies that forward everything.

Notes

  • Never clobbers a user value. Attach only manages the key when it is ours: a
    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 remove
    it. Same never-clobber stance the base URL takes.
  • Detach fix. The core undo previously restored every managed env key to
    the single prev_base_url. With a second managed key that would stamp the base
    URL onto ENABLE_TOOL_SEARCH for any user who had a prior custom base URL. The
    restore is now scoped to ANTHROPIC_BASE_URL; other managed keys are removed.
  • Rationale documented in LLP 0045 (#enable_tool_search-...).

Testing

  • npm test (2144 pass), plus new attach and detach coverage.
  • npm run smoke -- claude_attach_detach passes (byte-for-byte restore holds).

…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.
@philcunliffe philcunliffe added neutral:adopt Foreign PR adopted into neutral's reconcile scope neutral:approved neutral reviewed this adopted PR and approves; held for maintainer merge (LLP 0025) labels Jul 8, 2026
@philcunliffe

Copy link
Copy Markdown
Contributor

neutral review — round 1 · head e6390d4 · verdict: APPROVE (clean)

Independent worker-tier review in an isolated worktree. No blocking, major, or actionable minor code findings.

Tests: npm test2144 pass / 0 fail / 1 skipped (pre-existing unrelated skip). All four new attach/detach tests pass.

@ref anchors: both resolve against llp/0045-client-attach.design.md#enable_tool_search-keep-deferred-tool-loading-on-through-the-gateway (new heading) and #part-3--reverse-runs-from-disk-... (pre-existing). No broken references.

Correctness — manageToolSearch + detach symmetry, all four cases:

  • (a) fresh attach, key absent → managed, sets 'true', records in managed.env; detach deletes it. ✓
  • (b) re-attach we ownweOwnToolSearch keeps managing (mirrors base-URL "once ours, ours"). ✓ (tested)
  • (c) user pre-set the key → not managed, not recorded, left byte-for-byte untouched. ✓ (tested)
  • (d) detach round-tripprev_base_url restores ANTHROPIC_BASE_URL only; every other managed key is deleted, never stamped with the base URL. Externally-overridden keys hit the never-clobber branch. No asymmetry between what attach records and what detach removes. ✓

The removed reporting var being gated to ANTHROPIC_BASE_URL is display-only, no control-flow impact.

One non-blocking design note (maintainer's call, not actionable by neutral): the PR edits llp/0045-client-attach.design.md (Status: Active) in place, adding a new #### ENABLE_TOOL_SEARCH subsection. The global LLP house rule treats Active docs as immutable records (new intent → new request + Extended-by:), while this repo's own CLAUDE.md "Living docs" rule permits landing the doc edit in the same commit as the code. The addition is purely additive. Leans acceptable under project rules; flagging only for a maintainer's eye if strict immutability is being enforced.

Verdict: approve — mergeable ∧ green ∧ reviewed. Held for a maintainer to merge (neutral does not merge contributor PRs).

@platypii platypii merged commit f68c793 into master Jul 8, 2026
4 checks passed
@platypii platypii deleted the fix/attach-enable-tool-search branch July 8, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

neutral:adopt Foreign PR adopted into neutral's reconcile scope neutral:approved neutral reviewed this adopted PR and approves; held for maintainer merge (LLP 0025)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants