preview_cleanup
Preview Claude Code sessions marked for cleanup to identify empty sessions and those with invalid API keys before removal.
Instructions
Preview sessions that would be cleaned (empty and invalid API key sessions)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | No | Optional: filter by project name |
Implementation Reference
- src/lib/session.ts:226-251 (handler)The core handler function implementing the preview_cleanup tool logic. It lists projects (filtered by optional projectName), lists sessions in each, identifies empty sessions (messageCount === 0) and invalid API key sessions (title includes 'Invalid API key' or 'API key'), and returns a structured preview.export const previewCleanup = (projectName?: string) => Effect.gen(function* () { const projects = yield* listProjects const targetProjects = projectName ? projects.filter((p) => p.name === projectName) : projects const results = yield* Effect.all( targetProjects.map((project) => Effect.gen(function* () { const sessions = yield* listSessions(project.name) const emptySessions = sessions.filter((s) => s.messageCount === 0) const invalidSessions = sessions.filter( (s) => s.title?.includes('Invalid API key') || s.title?.includes('API key') ) return { project: project.name, emptySessions, invalidSessions, } }) ), { concurrency: 5 } ) return results })
- src/mcp/index.ts:92-103 (registration)MCP server tool registration for 'preview_cleanup'. Defines the tool name, description, input schema (optional project_name), and handler that delegates to session.previewCleanup and formats the JSON response.server.tool( 'preview_cleanup', 'Preview sessions that would be cleaned (empty and invalid API key sessions)', { project_name: z.string().optional().describe('Optional: filter by project name'), }, async ({ project_name }) => { const result = await Effect.runPromise(session.previewCleanup(project_name)) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], } }
- src/mcp/index.ts:95-97 (schema)Zod input schema for the preview_cleanup tool, defining an optional string parameter 'project_name' for filtering by project.{ project_name: z.string().optional().describe('Optional: filter by project name'), },