Skip to main content
Glama
es6kr
by es6kr

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)'),
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the destructive action ('Delete') but lacks details on permissions needed, whether deletions are reversible, rate limits, or what constitutes 'empty' or 'invalid' sessions. For a destructive tool with zero annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It front-loads the core action and target resources without unnecessary elaboration, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive tool with no annotations and no output schema, the description is incomplete. It lacks critical behavioral context (e.g., safety warnings, response format, error handling) and doesn't compensate for the absence of structured metadata, leaving significant gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 4 parameters. The description doesn't add any parameter-specific details beyond what's in the schema, such as clarifying the scope of 'project_name' filtering or interactions between boolean flags. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Delete') and the target resources ('all empty sessions and invalid API key sessions'), distinguishing it from siblings like 'delete_session' (singular) and 'preview_cleanup' (preview only). It uses precise verbs and resource types.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for cleanup of specific session types but doesn't explicitly state when to use this tool versus alternatives like 'preview_cleanup' (for previewing) or 'delete_session' (for targeted deletion). No explicit exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/es6kr/claude-sessions-mcp'

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