Interface BetaMemoryToolHandler
-
- All Implemented Interfaces:
public interface BetaMemoryToolHandlerA memory tool handler enables Claude to store and retrieve information across conversations through a filesystem-like API. Claude can create, read, update, and delete "files" that persist between sessions, allowing it to build knowledge over time without keeping everything in the context window.
While filesystem terminology is used throughout this interface, implementations are free to use any underlying storage (filesystem, memory, database, cloud storage, etc.).
Each method of this interface corresponds to a memory tool command that may be included in a Claude message response. Each method handles the operation corresponding to one of those commands.
For more details on memory tools in general, and on the specific formats of the inputs, outputs, and error messages for each command, consult the Claude Memory tool documentation.
All functions return a string, which may be an error message to inform Claude of any problem encountered when attempting to execute a memory tool command. Where line numbers are requested or reported back, the first line is numbered 1.
-
-
Method Summary
Modifier and Type Method Description abstract Stringcreate(String path, String fileText)Creates a new file. abstract Stringview(String path, Optional<List<Long>> viewRange)Shows directory contents or file contents with optional line ranges. abstract StringstrReplace(String path, String oldStr, String newStr)Replaces text in a file. abstract Stringinsert(String path, Long insertLine, String insertText)Inserts text at a specific line. abstract Stringdelete(String path)Deletes a file or directory. abstract Stringrename(String oldPath, String newPath)Renames or moves a file or directory. -
-
Method Detail
-
create
abstract String create(String path, String fileText)
Creates a new file.
- Parameters:
path- Path to where the file should be created.fileText- Content to write to the file.- Returns:
A response indicating successful creation of the file, or an error message if no file was created. See the Claude Memory tool documentation for details on the expected format of the response.
-
view
abstract String view(String path, Optional<List<Long>> viewRange)
Shows directory contents or file contents with optional line ranges.
- Parameters:
path- Path to the directory or file to view.viewRange- Optional two-element list[startLine, endLine](1-based, inclusive) for viewing a specific range of lines.- Returns:
A response listing the directory or file contents, or an error message if a problem occurred. See the Claude Memory tool documentation for details on the expected format of the response.
-
strReplace
abstract String strReplace(String path, String oldStr, String newStr)
Replaces text in a file.
- Parameters:
path- Path to the file.oldStr- The existing text to be replaced with newStr.newStr- The text to replace instances of oldStr.- Returns:
A response confirming the successful replacement, or an error message if a problem occurred. See the Claude Memory tool documentation for details on the expected format of the response.
-
insert
abstract String insert(String path, Long insertLine, String insertText)
Inserts text at a specific line.
- Parameters:
path- Path to the file.insertLine- The number of the line after which the inserted text should appear.insertText- The text to insert at the insertLine.- Returns:
A response confirming the successful insertion, or an error message if a problem occurred. See the Claude Memory tool documentation for details on the expected format of the response.
-
delete
abstract String delete(String path)
Deletes a file or directory. If a directory, deletes the directory and all its contents recursively.
- Parameters:
path- Path to the file or directory to delete.- Returns:
A response confirming the successful deletion, or an error message if a problem occurred. See the Claude Memory tool documentation for details on the expected format of the response.
-
rename
abstract String rename(String oldPath, String newPath)
Renames or moves a file or directory.
- Parameters:
oldPath- The path to the file or directory to be renamed (or moved).newPath- The new path to that file or directory.- Returns:
A response confirming the successful renaming, or an error message if a problem occurred. See the Claude Memory tool documentation for details on the expected format of the response.
-
-
-
-