Skip to main content
Glama
DrumRobot
by DrumRobot

rename_session

Add a title prefix to the first message of a Claude Code conversation session to rename it for better organization and identification.

Instructions

Rename a session by adding a title prefix to the first message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_nameYesProject folder name
session_idYesSession ID (filename without .jsonl)
new_titleYesNew title to add as prefix

Implementation Reference

  • src/mcp/index.ts:38-53 (registration)
    Tool registration for 'rename_session', including input schema using Zod and the handler function that calls the core renameSession implementation.
    server.tool(
      'rename_session',
      'Rename a session by adding a title prefix to the first message',
      {
        project_name: z.string().describe('Project folder name'),
        session_id: z.string().describe('Session ID (filename without .jsonl)'),
        new_title: z.string().describe('New title to add as prefix'),
      },
      async ({ project_name, session_id, new_title }) => {
        const result = await Effect.runPromise(
          session.renameSession(project_name, session_id, new_title)
        )
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        }
      }
  • Core implementation of renameSession: reads the session JSONL file, modifies the first message's content by prepending the new title in brackets (replacing any existing prefix), and writes back the updated file.
    export const renameSession = (projectName: string, sessionId: string, newTitle: string) =>
      Effect.gen(function* () {
        const filePath = path.join(getSessionsDir(), projectName, `${sessionId}.jsonl`)
        const content = yield* Effect.tryPromise(() => fs.readFile(filePath, 'utf-8'))
        const lines = content.trim().split('\n').filter(Boolean)
    
        if (lines.length === 0) {
          return { success: false, error: 'Empty session' }
        }
    
        const messages = lines.map((line) => JSON.parse(line) as Message)
        const firstMsg = messages[0]
    
        // Add title prefix to first message
        if (firstMsg && typeof firstMsg.message === 'object' && firstMsg.message !== null) {
          const msg = firstMsg.message as { content?: string }
          if (msg.content) {
            // Remove existing title prefix if any
            const cleanContent = msg.content.replace(/^\[.*?\]\s*/, '')
            msg.content = `[${newTitle}] ${cleanContent}`
          }
        }
    
        const newContent = messages.map((m) => JSON.stringify(m)).join('\n') + '\n'
        yield* Effect.tryPromise(() => fs.writeFile(filePath, newContent, 'utf-8'))
    
        return { success: true }
      })
  • Zod schema defining input parameters for the rename_session tool.
      project_name: z.string().describe('Project folder name'),
      session_id: z.string().describe('Session ID (filename without .jsonl)'),
      new_title: z.string().describe('New title to add as prefix'),
    },

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