fix(cli): use --tools to actually shrink the built-in tool schema set - #104
Open
Its-My-Work wants to merge 1 commit into
Open
Its-My-Work wants to merge 1 commit into
Its-My-Work wants to merge 1 commit into
Conversation
--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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--allowedToolsis 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 inclaude-cli.jspasses 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)
~63% reduction, no functional change: MCP tools (
mcp__server__tool) aren't part of "the built-in set"--toolsrestricts, soask_user/notify_user/set_ui_state/check_user_messagesstay governed bymcpServers+allowedToolsexactly as before — verified separately by keeping--tools ""while still routing a real MCP tool throughallowedToolssuccessfully (schema for that tool still showed up, built-ins didn't).Fix
When
allowedToolsis provided and no explicittoolsstring was already passed, derive--toolsfrom the built-in subset ofallowedTools(filtering outmcp__-prefixed names) and pass it alongside the existing--allowedTools.--allowedToolskeeps being passed unchanged, so permission behavior is identical to before.Test plan
cache_creation_input_tokensin the usage before/after this changeask_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