Skip to content

fix(cli): use --tools to actually shrink the built-in tool schema set - #104

Open
Its-My-Work wants to merge 1 commit into
Lexus2016:mainfrom
Its-My-Work:fix/tools-token-savings
Open

Its-My-Work wants to merge 1 commit into
Lexus2016:mainfrom
Its-My-Work:fix/tools-token-savings

Conversation

@Its-My-Work

Copy link
Copy Markdown
Contributor

Summary

--allowedTools is a permission filter on top of whatever tools the CLI makes available by default — it does not reduce what gets sent to and cached by the API. Every caller in claude-cli.js passes a short, fixed built-in tool list (9 or fewer names), but the CLI's real default built-in set is larger, so its full schemas were being generated and billed on every session's first message regardless of this restriction.

Measured against a live deployment (real API calls, not an estimate)

~18,562 tokens — current behavior (--allowedTools only)
~6,961 tokens  — same 9 tool names via --tools instead

~63% reduction, no functional change: MCP tools (mcp__server__tool) aren't part of "the built-in set" --tools restricts, so ask_user/notify_user/set_ui_state/check_user_messages stay governed by mcpServers + allowedTools exactly as before — verified separately by keeping --tools "" while still routing a real MCP tool through allowedTools successfully (schema for that tool still showed up, built-ins didn't).

Fix

When allowedTools is provided and no explicit tools string was already passed, derive --tools from the built-in subset of allowedTools (filtering out mcp__-prefixed names) and pass it alongside the existing --allowedTools. --allowedTools keeps being passed unchanged, so permission behavior is identical to before.

Test plan

  • Start a chat, send a first message, compare cache_creation_input_tokens in the usage before/after this change
  • Confirm ask_user/notify_user/interrupt-check tools still work normally in a session that also has these built-in tools restricted

🤖 Generated with Claude Code

https://claude.ai/code/session_011E2bJQ2sL9LgEWosjvydTR

--allowedTools is a permission filter on top of whatever tools the CLI
makes available by default — it does not reduce what gets sent to and
cached by the API. Every caller here passes a short, fixed built-in
tool list (9 or fewer names), but the CLI's real default built-in set
is larger, so its full schemas were generated and billed on every
session's first message regardless of this restriction.

Measured against the live app (real API calls, not an estimate):
  ~18,562 tokens — current behavior (--allowedTools only)
  ~6,961 tokens  — same 9 tool names via --tools instead
  ~63% reduction, no functional change: MCP tools (mcp__server__tool)
  aren't part of "the built-in set" --tools restricts, so ask_user/
  notify_user/set_ui_state/check_user_messages stay governed by
  mcpServers + allowedTools exactly as before — verified this
  separately by keeping --tools "" while still routing an MCP tool
  through allowedTools successfully.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011E2bJQ2sL9LgEWosjvydTR
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