Skip to main content
Glama
es6kr
by es6kr

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

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

With no annotations, the description carries the full burden. It discloses that deletion moves sessions to a .bak folder for recovery, which is a key behavioral trait beyond basic deletion. However, it doesn't cover other aspects like permissions needed, error handling, or whether this is reversible beyond the .bak mechanism.

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 a parenthetical that adds crucial information. It's front-loaded with the core action and resource, with no wasted words, making it highly concise and well-structured.

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

Completeness3/5

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

Given no annotations and no output schema, the description is adequate for a deletion tool with recovery context, but it lacks details on output format, error cases, or integration with sibling tools. It covers the basic behavior but leaves gaps in full operational understanding.

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 already documents both parameters ('project_name' and 'session_id'). The description doesn't add any additional meaning or context about these parameters beyond what the schema provides, meeting the baseline for high coverage.

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

Purpose4/5

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

The description clearly states the action ('Delete') and resource ('a session'), and the parenthetical adds important context about recovery. However, it doesn't explicitly differentiate from sibling tools like 'clear_sessions' or 'preview_cleanup', which might have overlapping functionality.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'clear_sessions' or 'delete_message'. The description lacks context about prerequisites, recovery implications, or scenarios where this tool is preferred over others.

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