You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3. (Optional, Recommended) Get your Morph API key from [Morph Dashboard](https://morphllm.com/dashboard/api-keys)
70
+
71
+
4. Set up your Morph API key for Fast Apply editing (choose one method):
72
+
73
+
**Method 1: Environment Variable**
74
+
```bash
75
+
export MORPH_API_KEY=your_morph_api_key_here
76
+
```
77
+
78
+
**Method 2: .env File**
79
+
```bash
80
+
# Add to your .env file
81
+
MORPH_API_KEY=your_morph_api_key_here
82
+
```
83
+
67
84
### Custom Base URL (Optional)
68
85
69
86
By default, the CLI uses `https://api.x.ai/v1` as the Grok API endpoint. You can configure a custom endpoint if needed (choose one method):
@@ -291,6 +308,35 @@ Follow the existing code style and patterns in this project.
291
308
292
309
Grok will automatically load and follow these instructions when working in your project directory. The custom instructions are added to Grok's system prompt and take priority over default behavior.
293
310
311
+
## Morph Fast Apply (Optional)
312
+
313
+
Grok CLI supports Morph's Fast Apply model for high-speed code editing at **4,500+ tokens/sec with 98% accuracy**. This is an optional feature that provides lightning-fast file editing capabilities.
314
+
315
+
**Setup**: Configure your Morph API key following the [setup instructions](#setup) above.
316
+
317
+
### How It Works
318
+
319
+
When `MORPH_API_KEY` is configured:
320
+
-**`edit_file` tool becomes available** alongside the standard `str_replace_editor`
321
+
-**Optimized for complex edits**: Use for multi-line changes, refactoring, and large modifications
322
+
-**Intelligent editing**: Uses abbreviated edit format with `// ... existing code ...` comments
323
+
-**Fallback support**: Standard tools remain available if Morph is unavailable
@@ -84,7 +87,7 @@ export class GrokAgent extends EventEmitter {
84
87
You have access to these tools:
85
88
- view_file: View file contents or directory listings
86
89
- create_file: Create new files with content (ONLY use this for files that don't exist yet)
87
-
- str_replace_editor: Replace text in existing files (ALWAYS use this to edit or update existing files)
90
+
- str_replace_editor: Replace text in existing files (ALWAYS use this to edit or update existing files)${this.morphEditor ? '\n- edit_file: High-speed file editing with Morph Fast Apply (4,500+ tokens/sec with 98% accuracy)' : ''}
88
91
- bash: Execute bash commands (use for searching, file discovery, navigation, and system operations)
89
92
- search: Unified search tool for finding text content or files (similar to Cursor's search functionality)
90
93
- create_todo_list: Create a visual todo list for planning and tracking tasks
@@ -618,6 +621,19 @@ Current working directory: ${process.cwd()}`,
618
621
args.replace_all
619
622
);
620
623
624
+
case"edit_file":
625
+
if(!this.morphEditor){
626
+
return{
627
+
success: false,
628
+
error: "Morph Fast Apply not available. Please set MORPH_API_KEY environment variable to use this feature.",
description: "Use this tool to make an edit to an existing file.\n\nThis will be read by a less intelligent model, which will quickly apply the edit. You should make it clear what the edit is, while also minimizing the unchanged code you write.\nWhen writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.\n\nFor example:\n\n// ... existing code ...\nFIRST_EDIT\n// ... existing code ...\nSECOND_EDIT\n// ... existing code ...\nTHIRD_EDIT\n// ... existing code ...\n\nYou should still bias towards repeating as few lines of the original file as possible to convey the change.\nBut, each edit should contain sufficient context of unchanged lines around the code you're editing to resolve ambiguity.\nDO NOT omit spans of pre-existing code (or comments) without using the // ... existing code ... comment to indicate its absence. If you omit the existing code comment, the model may inadvertently delete these lines.\nIf you plan on deleting a section, you must provide context before and after to delete it. If the initial code is ```code \\n Block 1 \\n Block 2 \\n Block 3 \\n code```, and you want to remove Block 2, you would output ```// ... existing code ... \\n Block 1 \\n Block 3 \\n // ... existing code ...```.\nMake sure it is clear what the edit should be, and where it should be applied.\nMake edits to a file in a single edit_file call instead of multiple edit_file calls to the same file. The apply model can handle many distinct edits at once.",
252
+
parameters: {
253
+
type: "object",
254
+
properties: {
255
+
target_file: {
256
+
type: "string",
257
+
description: "The target file to modify."
258
+
},
259
+
instructions: {
260
+
type: "string",
261
+
description: "A single sentence instruction describing what you are going to do for the sketched edit. This is used to assist the less intelligent model in applying the edit. Use the first person to describe what you are going to do. Use it to disambiguate uncertainty in the edit."
262
+
},
263
+
code_edit: {
264
+
type: "string",
265
+
description: "Specify ONLY the precise lines of code that you wish to edit. NEVER specify or write out unchanged code. Instead, represent all unchanged code using the comment of the language you're editing in - example: // ... existing code ..."
0 commit comments