Claude can use an Anthropic-defined text editor tool to view and modify text files, helping you debug, fix, and improve your code or other text documents. This allows Claude to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
| Model | Tool Version |
|---|---|
| Claude 4.x models | text_editor_20250728 |
| Claude Sonnet 3.7 (deprecated) | text_editor_20250124 |
The text_editor_20250728 tool for Claude 4 models does not include the undo_edit command. If you require this functionality, you'll need to use Claude Sonnet 3.7 (deprecated).
Older tool versions are not guaranteed to be backwards-compatible with newer models. Always use the tool version that corresponds to your model version.
Some examples of when to use the text editor tool are:
The text editor tool can be used in the following way:
The text editor tool supports several commands for viewing and modifying files:
The view command allows Claude to examine the contents of a file or list the contents of a directory. It can read the entire file or a specific range of lines.
Parameters:
command: Must be "view"path: The path to the file or directory to viewview_range (optional): An array of two integers specifying the start and end line numbers to view. Line numbers are 1-indexed, and -1 for the end line means read to the end of the file. This parameter only applies when viewing files, not directories.The str_replace command allows Claude to replace a specific string in a file with a new string. This is used for making precise edits.
Parameters:
command: Must be "str_replace"path: The path to the file to modifyold_str: The text to replace (must match exactly, including whitespace and indentation)new_str: The new text to insert in place of the old textThe create command allows Claude to create a new file with specified content.
Parameters:
command: Must be "create"path: The path where the new file should be createdfile_text: The content to write to the new fileThe insert command allows Claude to insert text at a specific location in a file.
Parameters:
command: Must be "insert"path: The path to the file to modifyinsert_line: The line number after which to insert the text (0 for beginning of file)new_str: The text to insertThe undo_edit command allows Claude to revert the last edit made to a file.
This command is only available in Claude Sonnet 3.7 (deprecated). It is not supported in Claude 4 models using the text_editor_20250728.
Parameters:
command: Must be "undo_edit"path: The path to the file whose last edit should be undoneThe text editor tool is implemented as a schema-less tool. When using this tool, you don't need to provide an input schema as with other tools; the schema is built into Claude's model and can't be modified.
The tool type depends on the model version:
type: "text_editor_20250728"type: "text_editor_20250124"When implementing the text editor tool, keep in mind:
When using the text editor tool, various errors may occur. Here is guidance on how to handle them:
The text editor tool uses the same pricing structure as other tools used with Claude. It follows the standard input and output token pricing based on the Claude model you're using.
In addition to the base tokens, the following additional input tokens are needed for the text editor tool:
| Tool | Additional input tokens |
|---|---|
text_editor_20250429 (Claude 4.x) | 700 tokens |
text_editor_20250124 (Claude Sonnet 3.7 (deprecated)) | 700 tokens |
For more detailed information about tool pricing, see Tool use pricing.
The text editor tool can be used alongside other Claude tools. When combining tools, ensure you:
| Date | Version | Changes |
|---|---|---|
| July 28, 2025 | text_editor_20250728 | Release of an updated text editor Tool that fixes some issues and adds an optional max_characters parameter. It is otherwise identical to text_editor_20250429. |
| April 29, 2025 | text_editor_20250429 | Release of the text editor Tool for Claude 4. This version removes the undo_edit command but maintains all other capabilities. The tool name has been updated to reflect its str_replace-based architecture. |
| March 13, 2025 | text_editor_20250124 | Introduction of standalone text editor Tool documentation. This version is optimized for Claude Sonnet 3.7 but has identical capabilities to the previous version. |
| October 22, 2024 | text_editor_20241022 | Initial release of the text editor Tool with Claude Sonnet 3.5 (). Provides capabilities for viewing, creating, and editing files through the , , , , and commands. |
Here are some ideas for how to use the text editor tool in more convenient and powerful ways:
As you build applications with the text editor tool, we're excited to see how you leverage Claude's capabilities to enhance your development workflow and productivity.
Provide Claude with the text editor tool and a user prompt
Claude uses the tool to examine files or directories
view command to examine file contents or list directory contentstool_use content block with the view commandExecute the view command and return results
max_characters parameter was specified in the tool configuration, truncate the file contents to that lengthuser message containing a tool_result content blockClaude uses the tool to modify files
str_replace to make changes or insert to add text at a specific line number.str_replace command, Claude constructs a properly formatted tool use request with the old text and new text to replace it withExecute the edit and return results
Claude provides its analysis and explanation
Initialize your editor implementation
Create helper functions to handle file operations like reading, writing, and modifying files. Consider implementing backup functionality to recover from mistakes.
Handle editor tool calls
Create a function that processes tool calls from Claude based on the command type:
def handle_editor_tool(tool_call, model_version):
input_params = tool_call.input
command = input_params.get('command', '')
file_path = input_params.get('path', '')
if command == 'view':
# Read and return file contents
pass
elif command == 'str_replace':
# Replace text in file
pass
elif command == 'create':
# Create new file
pass
elif command == 'insert':
# Insert text at location
pass
elif command == 'undo_edit':
# Check if it's a Claude 4 model
if 'str_replace_based_edit_tool' in model_version:
return {"error": "undo_edit command is not supported in Claude 4"}
# Restore from backup for Claude 3.7
passImplement security measures
Add validation and security checks:
Process Claude's responses
Extract and handle tool calls from Claude's responses:
# Process tool use in Claude's response
for content in response.content:
if content.type == "tool_use":
# Execute the tool based on command
result = handle_editor_tool(content)
# Return result to Claude
tool_result = {
"type": "tool_result",
"tool_use_id": content.id,
"content": result
}viewcreatestr_replaceinsertundo_editExecute shell commands with Claude.