-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(claude-code): workaround reserved tool name collision (read_file) #10868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(claude-code): workaround reserved tool name collision (read_file) #10868
Conversation
Review CompletedNo new issues found. The latest commit (cb99814) improves the previous fix by:
The workaround for the Claude Code OAuth reserved tool name collision ( Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Overall Assessment: ✅ Approved with suggested improvements
This PR provides a solid workaround for the Claude Code OAuth API reserved tool name collision issue. The implementation is clean and well-documented. I've identified a few improvements and have pushed fixes along with comprehensive test coverage.
Issues Identified & Fixed
1. Type Safety Issue (Fixed)
The original code had an unsafe type assertion on line 282:
name: unpatchToolName(chunk.name as string, reverseNameMap),The chunk.name can be undefined for continuation chunks in tool call streaming (as documented in StreamToolCallPartialChunk). The as string cast masked this, which could lead to unexpected runtime behavior.
Fix applied:
- Updated
unpatchToolName()to acceptstring | undefinedand returnstring | undefined - Removed the unsafe type assertion
2. Missing Unit Tests (Added)
The PR description noted that testing was not complete. I've added comprehensive unit tests for:
patchReservedAnthropicToolNames()- 5 test cases covering reserved/non-reserved names, empty arrays, and property preservationunpatchToolName()- 4 test cases including undefined handling- Integration tests for tool name handling in streaming
All 35 tests now pass ✅
3. Exported Functions for Testability
The helper functions and constants are now exported so they can be properly tested:
RESERVED_ANTHROPIC_TOOL_NAMESRESERVED_ANTHROPIC_TOOL_PREFIXpatchReservedAnthropicToolNames()unpatchToolName()
Suggested Follow-up (Not blocking)
The tool_use blocks in conversation history messages are not currently patched. When a follow-up request is sent with previous assistant messages containing tool_use blocks:
- The tool definitions will have the prefixed name (
_read_file) - The
tool_useblocks in history may have the original name (read_file)
This could potentially cause mismatches. If issues arise in multi-turn conversations with the read_file tool, consider also patching tool_use block names in the messages array before sending.
Changes Made in This Review
- Fixed type signature of
unpatchToolName()to handle undefined - Removed unsafe
as stringcast - Exported functions/constants for testability
- Added 13 new unit tests for the patching functionality
Great work on this fix! 🎉
…ching - Fix unpatchToolName() to properly handle undefined tool names - Remove unsafe 'as string' type assertion - Export patching functions and constants for testability - Add comprehensive unit tests (13 new tests)
Suggested ChangesI've pushed the review fixes to a branch that you can cherry-pick or merge: Branch: Summary of Changes
To Apply These ChangesYou can fetch and cherry-pick my commit: git fetch https://github.com/RooCodeInc/Roo-Code.git fix/claude-code-read-file-tool-name
git cherry-pick cb99814e7Or view the diff: 9abd227...cb99814 |
Related GitHub Issue
Closes: #10867
Roo Code Task Context (Optional)
Description
Claude Code OAuth API requests fail when a tool is named
read_file.This PR adds a small workaround by renaming the tool before sending it to Claude Code (e.g.
read_file→_read_file).Notes for reviewers:
Test Procedure
read_filetool (e.g. ask Roo Code to read a file from the workspace).Pre-Submission Checklist
Screenshots / Videos
Documentation Updates
Additional Notes
If the Claude Code OAuth gateway treats
read_fileas a reserved/system tool name, this workaround prevents collisions while keeping Roo Code behavior unchanged for users.Get in Touch
Discord: loject
Important
Fixes tool name collision in Claude Code OAuth by renaming
read_fileto_read_fileinclaude-code.ts.patchReservedAnthropicToolNames()andunpatchToolName()functions inclaude-code.tsto renameread_filetool to_read_filebefore sending requests.createMessage()inClaudeCodeHandlerto apply the renaming workaround for reserved tool names.RESERVED_ANTHROPIC_TOOL_NAMESandRESERVED_ANTHROPIC_TOOL_PREFIXinclaude-code.tsfor managing reserved tool names.This description was created by
for 9abd227. You can customize this summary. It will automatically update as commits are pushed.