Skip to main content
Glama

clear_sessions

Remove empty sessions, invalid API key sessions, and orphan agent files to clean up Claude Code conversation storage.

Instructions

Delete all empty sessions and invalid API key sessions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_nameNoOptional: filter by project name
clear_emptyNoClear empty sessions (default: true)
clear_invalidNoClear invalid API key sessions (default: true)
clear_orphan_agentsNoClear orphan agent files whose session no longer exists (default: true)

Implementation Reference

  • Core handler function that executes the clear_sessions logic: identifies empty/invalid sessions via previewCleanup, deletes them selectively, and removes orphan agent files.
    export const clearSessions = (options: { projectName?: string clearEmpty?: boolean clearInvalid?: boolean clearOrphanAgents?: boolean }) => Effect.gen(function* () { const { projectName, clearEmpty = true, clearInvalid = true, clearOrphanAgents = true, } = options const cleanupPreview = yield* previewCleanup(projectName) let deletedCount = 0 let deletedAgentCount = 0 for (const result of cleanupPreview) { const toDelete = [ ...(clearEmpty ? result.emptySessions : []), ...(clearInvalid ? result.invalidSessions : []), ] for (const session of toDelete) { const deleteResult = yield* deleteSession(result.project, session.id) deletedCount++ deletedAgentCount += deleteResult.deletedAgents.length } // Clean up orphan agents after deleting sessions if (clearOrphanAgents) { const orphanResult = yield* deleteOrphanAgents(result.project) deletedAgentCount += orphanResult.count } } return { success: true, deletedCount, deletedAgentCount } })
  • MCP tool registration for 'clear_sessions', defining input schema with Zod and a thin async handler that delegates to session.clearSessions from src/lib/session.ts.
    server.tool( 'clear_sessions', 'Delete all empty sessions and invalid API key sessions', { project_name: z.string().optional().describe('Optional: filter by project name'), clear_empty: z.boolean().default(true).describe('Clear empty sessions (default: true)'), clear_invalid: z .boolean() .default(true) .describe('Clear invalid API key sessions (default: true)'), clear_orphan_agents: z .boolean() .default(true) .describe('Clear orphan agent files whose session no longer exists (default: true)'), }, async ({ project_name, clear_empty, clear_invalid, clear_orphan_agents }) => { const result = await Effect.runPromise( session.clearSessions({ projectName: project_name, clearEmpty: clear_empty, clearInvalid: clear_invalid, clearOrphanAgents: clear_orphan_agents, }) ) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], } } )
  • Input schema definition for the clear_sessions tool using Zod validators with descriptions and defaults.
    project_name: z.string().optional().describe('Optional: filter by project name'), clear_empty: z.boolean().default(true).describe('Clear empty sessions (default: true)'), clear_invalid: z .boolean() .default(true) .describe('Clear invalid API key sessions (default: true)'), clear_orphan_agents: z .boolean() .default(true) .describe('Clear orphan agent files whose session no longer exists (default: true)'), },

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