fix: sanitize tool names in hook decorator filters#5342
Merged
greysonlalonde merged 2 commits intomainfrom Apr 8, 2026
Merged
Conversation
The tools parameter in before_tool_call/after_tool_call decorators now auto-sanitizes names via sanitize_tool_name(), so users can pass BaseTool.name directly without knowing the internal normalization. Also fixes tool_utils.py to pass the sanitized name to ToolCallHookContext for consistency with crew_agent_executor.py. Closes #5335
iris-clawd
approved these changes
Apr 8, 2026
Contributor
iris-clawd
left a comment
There was a problem hiding this comment.
Review: Sanitize tool names in hook decorator filters
Clean bugfix. Small, focused, correct.
✅ All good
- Decorator sanitization — sanitizes at decoration time (once), not on every hook invocation. Right call for performance.
- tool_utils.py fix —
ToolCallHookContextnow getssanitized_tool_nameinstead oftool_calling.tool_name, making both sides consistent. This was the actual bug — the decorator side could sanitize all it wants, but if the context still passes the unsanitized name, the filter comparison fails. - Test — covers the exact user scenario (pass
"Delete File", match against"delete_file"in context). Also verifies non-matching tools are still filtered.
No issues. LGTM 🚀 💬 188
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4163547. Configure here.
iris-clawd
approved these changes
Apr 8, 2026
Contributor
iris-clawd
left a comment
There was a problem hiding this comment.
14b3934 applies the same sanitized_tool_name fix to the sync code path — good catch, the first commit only covered async. Both before/after hooks in the sync path now consistent. Still LGTM 🚀 💬 189
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
toolsparameter inbefore_tool_call/after_tool_calldecorators viasanitize_tool_name(), so users can passBaseTool.namedirectly without knowing the internal normalizationtool_utils.pyto pass the sanitized name toToolCallHookContext, matching the behavior increw_agent_executor.pyCloses #5335
Test plan
test_before_tool_call_tool_filter_sanitizes_namesverifies unsanitized names like"Delete File"match sanitized context names like"delete_file"Note
Medium Risk
Changes the
ToolCallHookContext.tool_namevalue passed to hooks and normalizes decoratortoolsfilters, which can alter which hooks run for projects relying on unsanitized names.Overview
Tool hook decorators now auto-sanitize the
toolsfilter list viasanitize_tool_name(), allowing users to pass human-readableBaseTool.namevalues while still matching internal normalized tool names.Tool execution in
tool_utils.pynow populatesToolCallHookContext.tool_namewith the sanitized name (for both before/after hooks, sync and async), aligning hook filtering and logging behavior. Adds a regression test ensuring unsanitized filter names like"Delete File"match contexts like"delete_file".Reviewed by Cursor Bugbot for commit 14b3934. Bugbot is set up for automated code reviews on this repo. Configure here.
Addresses #5335