delete_message
Remove a specific message from a Claude Code 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/shared/session-core.ts:402-437 (handler)Core handler function that deletes a specific message from a session file by UUID (or messageId for snapshots), repairs the parent-child UUID chain by reparenting direct children to the deleted message's parent, and rewrites the session JSONL 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 Record<string, unknown>) // Find by uuid or messageId (for file-history-snapshot type) const targetIndex = messages.findIndex( (m) => m.uuid === messageUuid || m.messageId === messageUuid ) if (targetIndex === -1) { return { success: false, error: 'Message not found' } } // Get the deleted message's uuid and parentUuid const deletedMsg = messages[targetIndex] const deletedUuid = deletedMsg?.uuid ?? deletedMsg?.messageId const parentUuid = deletedMsg?.parentUuid // Find all messages that reference the deleted message as their parent // and update them to point to the deleted message's parent for (const msg of messages) { if (msg.parentUuid === deletedUuid) { msg.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)MCP tool registration for 'delete_message', including Zod input schema and thin async handler that delegates to session.deleteMessage 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 inputs for the delete_message tool: project_name, session_id, and message_uuid as strings.{ 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'), },