rename_session
Add a descriptive title prefix to Claude Code conversation sessions to organize and identify them clearly by project and session.
Instructions
Rename a session by adding a title prefix to the first message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | Yes | Project folder name | |
| session_id | Yes | Session ID (filename without .jsonl) | |
| new_title | Yes | New title to add as prefix |
Implementation Reference
- src/lib/session.ts:164-191 (handler)Core implementation of renameSession: reads the session JSONL file, prepends '[newTitle]' to the content of the first message (stripping existing prefix), serializes and writes back the 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 } })
- src/mcp/index.ts:42-45 (schema)Zod input schema for the 'rename_session' tool defining parameters project_name, session_id, and new_title.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'), },
- src/mcp/index.ts:38-54 (registration)Registers the 'rename_session' MCP tool on the McpServer, including schema and thin wrapper handler that calls the core session.renameSession and formats response.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) }], } } )