fix(hosts): expand PreToolUse matcher to cover Read, Grep, Glob, Agent, Task#86
Merged
claudioemmanuel merged 1 commit intomainfrom Apr 22, 2026
Merged
Conversation
…t, Task The Claude Code adapter registered the PreToolUse hook with matcher "Bash", which meant Claude Code only invoked pretooluse.sh for Bash tool calls. The hook already handled Read, Grep, and Glob by calling `squeez budget-params` and injecting caps (read_max_lines, grep_max_results) into tool_input — but that branch was dead code because the hook never fired for those tools. This fix changes the registered matcher from "Bash" to the regex "Bash|Read|Grep|Glob|Agent|Task", which Claude Code evaluates via re.match against the tool name. This activates the existing Read/Grep/Glob budget enforcement that was already implemented but unreachable. The patch script now handles upgrades in place: it searches for an existing squeez pretooluse.sh entry in PreToolUse and updates its matcher field if it differs from the new value, rather than appending a duplicate. Users who already ran `squeez setup` with the old narrow matcher get the correct matcher on the next `squeez setup` call without acquiring a duplicate hook entry. A new test file tests/test_hosts_claude_code.rs verifies: - capabilities include BUDGET_HARD - install writes the expanded matcher to settings.json - install is idempotent (no duplicate pretooluse.sh entries) - install upgrades an old "Bash"-only entry in place
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
"matcher": "Bash", so Claude Code never invoked it for Read, Grep, or Glob tool calls.squeez budget-paramsto enforceread_max_lines/grep_max_results— but it was dead code because the matcher prevented the hook from firing."Bash|Read|Grep|Glob|Agent|Task"(a regex, per Claude Code'sre.matchevaluation), activating the existing budget enforcement for all relevant tools.The bug this fixes
src/hosts/claude_code.rs:71—PATCH_SCRIPTappended"matcher": "Bash"for the PreToolUse hook entry.hooks/pretooluse.sh:45-66— the Read/Grep/Glob branch that callssqueez budget-params <tool>and injects caps intotool_inputwas already implemented but unreachable.src/config.rs:95-96—read_max_lines=300andgrep_max_results=100defaults were effectively ignored on Claude Code despite README claiming "Budget inject (Read/Grep): ✅ native".Idempotency
The patch script now iterates existing PreToolUse entries and finds any whose
hooks[0].commandcontainspretooluse.sh. If found, it updates thematcherfield in place instead of appending a new entry. Users with the oldmatcher: "Bash"entry from a prior install get upgraded on their nextsqueez setupcall — no duplicate entries.Test plan
cargo test— all tests pass including 4 new tests intests/test_hosts_claude_code.rsclaude_code_capabilities_include_budget_hard— verifies adapter capability flagsclaude_code_install_pretooluse_matcher_covers_read_grep_glob_agent_task— verifies the expanded matcher appears in settings.jsonclaude_code_install_is_idempotent_no_duplicate_pretooluse— verifies second install does not create duplicate entryclaude_code_install_upgrades_old_bash_only_matcher_in_place— verifies a pre-existing old-style entry is upgraded, not duplicatedsqueez setupagainst a real~/.claude/settings.jsonand verify the PreToolUse entry has matcher"Bash|Read|Grep|Glob|Agent|Task"