Skip to main content
Glama

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
NameRequiredDescriptionDefault
project_nameYesProject folder name
session_idYesSession 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) }], } } )
  • 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 } })
  • 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'), },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DrumRobot/claude-sessions-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server