Skip to main content
Glama

delete_session

Remove a Claude Code conversation session by moving it to a backup folder for recovery, using project name and session ID.

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

  • Core handler function that implements the deletion logic by moving the session file and linked agent files to a .bak backup folder.
    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) } // Move session file to backup const backupPath = path.join(backupDir, `${sessionId}.jsonl`) yield* Effect.tryPromise(() => fs.rename(filePath, backupPath)) return { success: true, backupPath, deletedAgents } })
  • src/mcp/index.ts:57-70 (registration)
    MCP tool registration for 'delete_session', including input schema and thin handler that delegates to the core deleteSession function.
    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) }], } } )
  • Helper function to find agent files linked to a specific session, used in deleteSession.
    export const findLinkedAgents = (projectName: string, sessionId: string) => Effect.gen(function* () { const projectPath = path.join(getSessionsDir(), projectName) const files = yield* Effect.tryPromise(() => fs.readdir(projectPath)) const agentFiles = files.filter((f) => f.startsWith('agent-') && f.endsWith('.jsonl')) const linkedAgents: string[] = [] for (const agentFile of agentFiles) { const filePath = path.join(projectPath, agentFile) const content = yield* Effect.tryPromise(() => fs.readFile(filePath, 'utf-8')) const firstLine = content.split('\n')[0] if (firstLine) { try { const parsed = JSON.parse(firstLine) as { sessionId?: string } if (parsed.sessionId === sessionId) { linkedAgents.push(agentFile.replace('.jsonl', '')) } } catch { // Skip invalid JSON } } } return linkedAgents })

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