Skip to content

fix(tools): forward request options headers in BetaToolRunner compaction calls#962

Open
Scottcjn wants to merge 1 commit intoanthropics:mainfrom
Scottcjn:fix/toolrunner-default-headers
Open

fix(tools): forward request options headers in BetaToolRunner compaction calls#962
Scottcjn wants to merge 1 commit intoanthropics:mainfrom
Scottcjn:fix/toolrunner-default-headers

Conversation

@Scottcjn
Copy link
Copy Markdown

Summary

  • Fixed BetaToolRunner.#checkAndCompact() dropping user-provided request options headers when making the compaction API call
  • The compaction call was only passing { headers: { 'x-stainless-helper': 'compaction' } }, discarding any headers from this.#options that were provided via toolRunner(params, options)
  • Now merges stored request options with the compaction header using buildHeaders(), consistent with how the main loop calls on lines 195/202 already pass this.#options

What changed

src/lib/tools/BetaToolRunner.ts (1 line change):

-        headers: { 'x-stainless-helper': 'compaction' },
+        ...this.#options,
+        headers: buildHeaders([{ 'x-stainless-helper': 'compaction' }, this.#options?.headers]),

tests/lib/tools/ToolRunner.test.ts (2 new tests):

  • forwards custom headers on every API call across tool-use turns — verifies request-level headers from toolRunner(params, { headers }) persist on follow-up calls
  • forwards defaultHeaders on every API call across tool-use turns — verifies client-level defaultHeaders persist across the tool-use loop

Test plan

  • Both new tests pass
  • All 128 existing lib tests pass (npx jest tests/lib/)
  • TypeScript compiles cleanly (npx tsc -p tsconfig.json --noEmit)

🤖 Generated with Claude Code

…n BetaToolRunner

The compaction call in BetaToolRunner's checkAndCompact() was passing only
a hardcoded x-stainless-helper header, dropping any user-provided headers
from the toolRunner request options. This merges the stored #options headers
with the compaction header using buildHeaders, ensuring custom headers
persist across all API calls in the tool-use loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Scottcjn Scottcjn requested a review from a team as a code owner March 26, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant