fix(tools): handle the memory tool commands Claude actually sends - #1597
Open
Rikinshah787 wants to merge 1 commit into
Open
fix(tools): handle the memory tool commands Claude actually sends#1597Rikinshah787 wants to merge 1 commit into
Rikinshah787 wants to merge 1 commit into
Conversation
Three places where ClaudeMemoryTool diverges from the documented memory_20250818 wire format: - rename sends old_path/new_path, not path. handleCommand validated command.path, so every rename coming from a real model died with "Cannot read properties of undefined (reading 'startsWith')". path is still accepted as the source for existing callers. - insert_line means "insert after this line" (0 = top of file), but we spliced at insertLine - 1 and rejected 0, so every insert landed one line above where Claude asked and inserting at the top was impossible. - str_replace with new_str omitted is a deletion per the spec; we rejected it. The new tests mock the supermemory client so they run without an API key. Also fixed the rename example in the docs, which showed the same path shape the code expected.
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.
Read ClaudeMemoryTool against Anthropic's memory tool docs (https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool) and found three places where the handler doesn't match what the model actually sends.
The big one is rename: Claude sends
old_path/new_path, nopathat all.handleCommandvalidatescommand.pathfirst, so every rename coming from a real model fails with "Cannot read properties of undefined (reading 'startsWith')". The existing tests only exercise apath+new_pathshape, which is why they pass.The other two:
insert_lineis documented as "insert after this line", with 0 meaning the top of the file and n_lines appending. The code spliced atinsertLine - 1and rejected 0, so every insert landed one line above where Claude asked, the top of the file was unreachable, and the success message gave the model no hint anything shifted. This one quietly corrupts memory files over repeated edits.str_replacewithnew_stromitted is how the model deletes text; we returned an error for it.Changes: rename resolves its source from
old_path ?? pathso anyone calling with the old shape keeps working, insert validates [0, n_lines] and splices atinsert_line, missingnew_strdefaults to "". The rename example in the docs page showed the samepathshape the code expected, fixed that too.Tests: added
test/claude-memory-commands.test.tswith the supermemory client mocked so it runs without an API key. 8 pass on this branch; 7 of 8 fail on main (the passing one is the backwards-compat case). Left the existing integration tests alone since they need a live key and currently don't typecheck anyway (#1545).Not related to #1547 / #1586 - those are about customId normalization, this is about the command shapes themselves.