> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morphllm.com/llms.txt
> Use this file to discover all available pages before exploring further.
# Quickstart
> Get started with Fast Apply and WarpGrep in 5 minutes
## Fast Apply 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](https://web.archive.org/web/20240823050616/https://www.cursor.com/blog/instant-apply).
## How to use Morph Fast Apply
Test the Apply Model with live examples in our interactive playground
Add the `edit_file` tool to your agent. Use one of the formats below.
```xml Tool Description theme={null}
Use this tool to edit existing files by showing only the changed lines.
Use "// ... existing code ..." to represent unchanged code blocks. Include just enough surrounding context to locate each edit precisely.
Example format:
// ... existing code ...
FIRST_EDIT
// ... existing code ...
SECOND_EDIT
// ... existing code ...
Rules:
- ALWAYS use "// ... existing code ..." for unchanged sections (omitting this marker will cause deletions)
- Include minimal context ONLY when needed around edits for disambiguation
- Preserve exact indentation
- For deletions: show context before and after, omit the deleted lines
- Batch multiple edits to the same file in one call
```
**Parameters:**
* `target_filepath` (string, required): Path of the file to modify
* `instructions` (string, required): Brief first-person description of what you're changing (helps disambiguate uncertainty in the edit)
* `code_edit` (string, required): Only the changed lines with `// ... existing code ...` markers for unchanged sections
```json Tool Definition theme={null}
{
"name": "edit_file",
"description": "Use this tool to edit existing files by showing only the changed lines.\n\nUse \"// ... existing code ...\" to represent unchanged code blocks. Include just enough surrounding context to locate each edit precisely.\n\nExample format:\n// ... existing code ...\nFIRST_EDIT\n// ... existing code ...\nSECOND_EDIT\n// ... existing code ...\n\nRules:\n- ALWAYS use \"// ... existing code ...\" for unchanged sections (omitting this marker will cause deletions)\n- Include minimal context around edits for disambiguation\n- Preserve exact indentation\n- For deletions: show context before and after, omit the deleted lines\n- Batch multiple edits to the same file in one call",
"input_schema": {
"type": "object",
"properties": {
"target_filepath": {
"type": "string",
"description": "Path of the file to modify."
},
"instructions": {
"type": "string",
"description": "Brief first-person description of what you're changing. Used to disambiguate uncertainty in the edit."
},
"code_edit": {
"type": "string",
"description": "Only the changed lines with \"// ... existing code ...\" markers for unchanged sections."
}
},
"required": ["target_filepath", "instructions", "code_edit"]
}
}
```
Instead of using tool calls, you can have the agent output code edits in markdown format that you can parse:
````markdown Agent Instruction theme={null}
Use this approach to edit existing files by showing only the changed lines.
Use "// ... existing code ..." to represent unchanged code blocks. Include just enough surrounding context to locate each edit precisely.
Example format:
// ... existing code ...
FIRST_EDIT
// ... existing code ...
SECOND_EDIT
// ... existing code ...
Rules:
- ALWAYS use "// ... existing code ..." for unchanged sections (omitting this marker will cause deletions)
- Include minimal context around edits for disambiguation
- Preserve exact indentation
- For deletions: show context before and after, omit the deleted lines
- Batch multiple edits to the same file in one response
Output your edits in this markdown format:
```filepath=path/to/file.js instruction=Brief description of what you're changing
// ... existing code ...
YOUR_CODE_EDIT_HERE
// ... existing code ...
```
The instruction should be a brief first-person description to help disambiguate the edit.
````
**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.
Your tool's execution should use Morph's API to merge the code. Then you should write the code to a file.
Add this to your system prompt to enable efficient code editing:
```markdown theme={null}
When editing code, use the edit_file tool to show only changed lines. Use "// ... existing code ..." markers for unchanged sections.
Example:
// ... existing code ...
{{ edit_1 }}
// ... existing code ...
{{ edit_2 }}
// ... existing code ...
Key points:
- Only rewrite entire files if explicitly requested
- ALWAYS use "// ... existing code ..." markers (omitting them causes deletions)
- Include minimal context for precise edit location
- Provide brief explanations unless user requests code only
```
```typescript TypeScript highlight={13} theme={null}
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.morphllm.com/v1",
});
const response = await openai.chat.completions.create({
model="morph-v3-fast",
messages: [
{
role: "user",
content: `${instructions}\n${initialCode}\n${codeEdit}`,
},
],
});
const mergedCode = response.choices[0].message.content;
```
```python Python highlight={14} theme={null}
import os
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.morphllm.com/v1"
)
response = client.chat.completions.create(
model="morph-v3-fast",
messages=[
{
"role": "user",
"content": f"{instructions}\n{initial_code}\n{code_edit}"
}
]
)
merged_code = response.choices[0].message.content
```
```bash cURL highlight={9} theme={null}
curl -X POST "https://api.morphllm.com/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "morph-v3-fast",
"messages": [
{
"role": "user",
"content": "INSTRUCTIONS\nINITIAL_CODE\nCODE_EDIT"
}
]
}'
```
Extract the merged code from the API response. Use your filesystem to write the code to a file.
**Response Format:**
```json theme={null}
final_code = response.choices[0].message.content
```
**Extract the Final Code:**
```typescript extract_code.ts theme={null}
const finalCode = response.choices[0].message.content;
// Write to file or return to your application
await fs.writeFile(targetFile, finalCode);
```
```python extract_code.py theme={null}
final_code = response.choices[0].message.content
# Write to file or return to your application
with open(target_file, 'w') as f:
f.write(final_code)
```
```bash cURL theme={null}
# The response contains the merged code directly
echo "$response" > output_file.js
```
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.
```typescript TypeScript theme={null}
import { createTwoFilesPatch } from 'diff';
// Generate UDiff between original and modified code
const udiff = createTwoFilesPatch(
targetFile,
targetFile,
initialCode,
mergedCode,
'',
''
);
// Send back to agent for verification
console.log("Changes applied:", udiff);
```
```python Python theme={null}
import difflib
# Generate UDiff between original and modified code
udiff = '\n'.join(difflib.unified_diff(
initial_code.splitlines(keepends=True),
merged_code.splitlines(keepends=True),
fromfile=target_file,
tofile=target_file
))
# Send back to agent for verification
print("Changes applied:", udiff)
```
```bash Bash theme={null}
# Generate diff using standard Unix tools
diff -u original_file.js modified_file.js
# Or save both versions and diff them
echo "$initial_code" > temp_original.js
echo "$merged_code" > temp_modified.js
diff -u temp_original.js temp_modified.js
rm temp_original.js temp_modified.js
```
This verification step helps catch any unexpected changes and ensures the applied edits match the agent's intentions.
***
## WarpGrep: Intelligent Code Search
Give your agent the ability to find relevant code across large codebases. 4x faster than Claude's stock grepping, with better long-horizon performance.
Test code search with live examples
```typescript theme={null}
import { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: "YOUR_API_KEY" });
const result = await morph.warpGrep.execute({
query: 'Find authentication middleware',
repoRoot: '.'
});
```
```typescript theme={null}
import { createWarpGrepTool } from '@morphllm/morphsdk/tools/warp-grep/anthropic';
const grepTool = createWarpGrepTool({
repoRoot: '.',
morphApiKey: "YOUR_API_KEY"
});
// Use with Anthropic, OpenAI, or Vercel AI SDK
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-5-20250929',
tools: [grepTool],
messages: [{ role: 'user', content: 'Find authentication middleware' }]
});
```
```typescript theme={null}
if (result.success) {
for (const ctx of result.contexts) {
console.log(`File: ${ctx.file}`);
console.log(ctx.content);
}
}
```
WarpGrep returns ranked code snippets with file paths and line numbers—ready to inject into your agent's context.
**Requires ripgrep (`rg`)** installed locally. No embeddings or index setup needed.
## Next Steps
Agent tool integration, remote execution, and advanced usage
Drop into Claude Code, Cursor, Codex instantly
AI native git with automatic code indexing
Complete API documentation