import { MorphClient } from '@morphllm/morphsdk';
import Anthropic from '@anthropic-ai/sdk';
import { createEditFileTool } from '@morphllm/morphsdk/tools/fastapply/anthropic';
// Initialize
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
const anthropic = new Anthropic();
// Give tool to agent
const response = await anthropic.messages.create({
model: "claude-sonnet-4-5-20250929",
tools: [createEditFileTool()],
messages: [{
role: "user",
content: "Add error handling to src/auth.ts"
}]
});
<Note>
The `instructions` parameter provides crucial context for ambiguous edits, helping the apply model make correct decisions and achieve near perfect accuracy. Have the parent model generate the instructions.
</Note>
// Or use directly
const result = await morph.fastApply.execute({
target_filepath: 'src/auth.ts',
instructions: 'I will add null check',
code_edit: '// ... existing code ...\nif (!user) throw new Error("Not found");\n// ... existing code ...'
});