delete_message
Remove a specific message from a Claude Code conversation session and automatically repair the conversation chain to maintain continuity.
Instructions
Delete a message from a session and repair the parentUuid chain
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | Yes | Project folder name | |
| session_id | Yes | Session ID | |
| message_uuid | Yes | UUID of the message to delete |
Implementation Reference
- src/lib/session.ts:194-223 (handler)The core handler function that implements the deletion of a specific message from a session JSONL file by its UUID. It repairs the parentUuid chain by updating the subsequent message's parentUuid to skip the deleted one, then rewrites the file.export const deleteMessage = (projectName: string, sessionId: string, messageUuid: string) => Effect.gen(function* () { const filePath = path.join(getSessionsDir(), projectName, `${sessionId}.jsonl`) const content = yield* Effect.tryPromise(() => fs.readFile(filePath, 'utf-8')) const lines = content.trim().split('\n').filter(Boolean) const messages = lines.map((line) => JSON.parse(line) as Message) const targetIndex = messages.findIndex((m) => m.uuid === messageUuid) if (targetIndex === -1) { return { success: false, error: 'Message not found' } } // Get the parent UUID of deleted message const deletedMsg = messages[targetIndex] const parentUuid = deletedMsg?.parentUuid // Update child message to point to deleted message's parent const nextMsg = messages[targetIndex + 1] if (nextMsg) { nextMsg.parentUuid = parentUuid } // Remove the message messages.splice(targetIndex, 1) const newContent = messages.map((m) => JSON.stringify(m)).join('\n') + '\n' yield* Effect.tryPromise(() => fs.writeFile(filePath, newContent, 'utf-8')) return { success: true } })
- src/mcp/index.ts:73-89 (registration)Registers the 'delete_message' tool with the MCP server, including description, input schema, and a thin handler that delegates to the core session.deleteMessage function and formats the response.server.tool( 'delete_message', 'Delete a message from a session and repair the parentUuid chain', { project_name: z.string().describe('Project folder name'), session_id: z.string().describe('Session ID'), message_uuid: z.string().describe('UUID of the message to delete'), }, async ({ project_name, session_id, message_uuid }) => { const result = await Effect.runPromise( session.deleteMessage(project_name, session_id, message_uuid) ) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], } } )
- src/mcp/index.ts:76-80 (schema)Zod schema defining the input parameters for the delete_message tool: project_name, session_id, and message_uuid.{ project_name: z.string().describe('Project folder name'), session_id: z.string().describe('Session ID'), message_uuid: z.string().describe('UUID of the message to delete'), },