edit_code
Modifies existing code according to specific instructions, enabling developers to adapt and refine scripts efficiently. Use this tool to implement changes directly based on clear, actionable guidance.
Instructions
Edits the given code based on instructions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Code to edit | |
| instructions | Yes | Editing instructions |
Implementation Reference
- claude-code-server/src/index.ts:560-570 (handler)The main handler function for the 'edit_code' tool. It destructures the input arguments (code and instructions), encodes the code to base64 using a helper, truncates if too long, constructs a specific prompt for Claude to edit the code, calls the shared runClaudeCommand helper to execute Claude CLI, and returns the generated output as text content.case 'edit_code': { const { code, instructions } = args; logger.debug(`Processing edit_code request, code length: ${code.length}`); const encodedCode = encodeText(truncateIfNeeded(code)); logger.debug(`Code encoded to base64, length: ${encodedCode.length}`); const prompt = `You are super professional engineer. Please edit the following Base64 encoded code according to the instructions provided:\n\nCode:\n${encodedCode}\n\nInstructions:\n${instructions ?? 'No specific instructions provided.'}`; logger.debug('Calling Claude CLI with prompt'); const output = await runClaudeCommand(['--print'], prompt); logger.debug(`Received response from Claude, length: ${output.length}`); return { content: [{ type: 'text', text: output }] }; }
- claude-code-server/src/index.ts:359-370 (registration)Registration of the 'edit_code' tool in the ListTools response, including its name, description, and input schema definition.{ name: 'edit_code', description: 'Edits the given code based on instructions.', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Code to edit' }, instructions: { type: 'string', description: 'Editing instructions' } }, required: ['code', 'instructions'] } },
- Input schema for the 'edit_code' tool, defining the expected parameters: code (string) and instructions (string), both required.inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Code to edit' }, instructions: { type: 'string', description: 'Editing instructions' } }, required: ['code', 'instructions'] } },
- Helper functions for base64 encoding/decoding of text, used in the edit_code handler to encode the input code before passing to Claude.function encodeText(text: string): string { return Buffer.from(text, 'utf8').toString('base64'); } function decodeText(encoded: string): string { return Buffer.from(encoded, 'base64').toString('utf8'); }