delete_session
Remove a Claude Code conversation session by moving it to a backup folder for potential recovery.
Instructions
Delete a session (moves to .bak folder for recovery)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | Yes | Project folder name | |
| session_id | Yes | Session ID to delete |
Implementation Reference
- src/mcp/index.ts:57-70 (registration)Registration of the MCP 'delete_session' tool, including input schema with project_name and session_id parameters, description, and an inline handler that delegates to session.deleteSession and formats the response.server.tool( 'delete_session', 'Delete a session (moves to .bak folder for recovery)', { project_name: z.string().describe('Project folder name'), session_id: z.string().describe('Session ID to delete'), }, async ({ project_name, session_id }) => { const result = await Effect.runPromise(session.deleteSession(project_name, session_id)) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], } } )
- src/lib/session.ts:113-142 (handler)Core handler function for deleting a session: creates .bak dir, moves linked agent files and session file to backup, deletes linked todos, returns success with paths and counts.export const deleteSession = (projectName: string, sessionId: string) => Effect.gen(function* () { const sessionsDir = getSessionsDir() const projectPath = path.join(sessionsDir, projectName) const filePath = path.join(projectPath, `${sessionId}.jsonl`) // Create backup directory const backupDir = path.join(projectPath, '.bak') yield* Effect.tryPromise(() => fs.mkdir(backupDir, { recursive: true })) // Find and delete linked agent files const linkedAgents = yield* findLinkedAgents(projectName, sessionId) const deletedAgents: string[] = [] for (const agentId of linkedAgents) { const agentPath = path.join(projectPath, `${agentId}.jsonl`) const agentBackupPath = path.join(backupDir, `${agentId}.jsonl`) yield* Effect.tryPromise(() => fs.rename(agentPath, agentBackupPath)) deletedAgents.push(agentId) } // Delete linked todo files const todosResult = yield* deleteLinkedTodos(sessionId, linkedAgents) // Move session file to backup const backupPath = path.join(backupDir, `${sessionId}.jsonl`) yield* Effect.tryPromise(() => fs.rename(filePath, backupPath)) return { success: true, backupPath, deletedAgents, deletedTodos: todosResult.deletedCount } })
- src/mcp/index.ts:60-63 (schema)Zod input schema for the delete_session tool defining required string parameters project_name and session_id with descriptions.{ project_name: z.string().describe('Project folder name'), session_id: z.string().describe('Session ID to delete'), },