
Overview
What is Morph for? Morph Fast Apply looks like a new edit_file tool you give your agent access to. That’s it. Claude will output lazily into this tool when it wants to make an edit. In the tools execution, the Morph API will merge the lazy edit output by Claude/Gemini/etc. into the file. If you like using Cursor - you already like the Fast Apply UX. Fast Apply is a concept used in Cursor.How to use Morph Fast Apply
Try the API Playground
Test the Apply Model with live examples in our interactive playground
1
1. Add an edit_file tool to your agent
Add the Parameters:
edit_file
tool to your agent. Use one of the formats below.- General Prompt
- JSON Tool (Claude)
- Output Parsing (No Tool)
Tool Description
target_filepath
(string, required): The path of the target file to modifyinstructions
(string, required): A single sentence written in the first person describing what the agent is changing. Used to help disambiguate uncertainty in the edit.code_edit
(string, required): Specify ONLY the precise lines of code that you wish to edit. Use// ... existing code ...
for unchanged sections.
IMPORTANT: The
instructions
param should be generated by the model not hardcoded.
Example: “I am adding error handling to the user auth and removing the old auth functions”Why do I need the instructions to be generated by the model?The
instructions
parameter provides crucial context for ambiguous edits, helping the apply model make correct decisions and achieve near 100% accuracy even in edge cases.2
Merge with Morph Fast Apply
Your tool’s execution should use Morph’s API to merge the code. Then you should write the code to a file.
What to add to your System Prompt
What to add to your System Prompt
Add this to your system prompt to enable proper code editing with Morph:
3
Handle the Response
Extract the merged code from the API response. Use your filesystem to write the code to a file.Response Format:Extract the Final Code:
4
Verifying Edits (Optional but Recommended)
We recommend passing the code changes back to the agent in UDiff format. This allows the agent to verify that the changes match its intent and make any necessary corrections.
To save on tokens, another option is to check for linting errors and only pass the calculated udiff back when there are linting errors.This verification step helps catch any unexpected changes and ensures the applied edits match the agent’s intentions.
Next Steps
Ready to start building with Morph? Here’s what to do next:Explore the Apply API
Learn about the Apply API endpoints for production use
Build Agentic Tools
Create edit_file tools for AI agents and development environments