get_session_files
Retrieve all files modified during a Claude Code session to track changes and review project history.
Instructions
Get list of all files changed in a session (from file-history-snapshot and tool_use)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | Yes | Project folder name | |
| session_id | Yes | Session ID |
Implementation Reference
- src/lib/session.ts:371-436 (handler)Core implementation of getSessionFiles: reads session messages, extracts unique file changes from 'file-history-snapshot' (modified files) and 'tool_use' Write/Edit blocks (created/modified), returns summary with files list.export const getSessionFiles = (projectName: string, sessionId: string) => Effect.gen(function* () { const messages = yield* readSession(projectName, sessionId) const fileChanges: FileChange[] = [] const seenFiles = new Set<string>() for (const msg of messages) { // Check for file-history-snapshot type if (msg.type === 'file-history-snapshot') { const snapshot = msg as unknown as { type: string messageId?: string snapshot?: { trackedFileBackups?: Record<string, unknown> timestamp?: string } } const backups = snapshot.snapshot?.trackedFileBackups if (backups && typeof backups === 'object') { for (const filePath of Object.keys(backups)) { if (!seenFiles.has(filePath)) { seenFiles.add(filePath) fileChanges.push({ path: filePath, action: 'modified', timestamp: snapshot.snapshot?.timestamp, messageUuid: snapshot.messageId ?? msg.uuid, }) } } } } // Also check tool_use for Write/Edit operations if (msg.type === 'assistant' && msg.message) { const assistantMsg = msg.message as { content?: Array<{ type: string; name?: string; input?: { file_path?: string } }> } const content = assistantMsg.content if (Array.isArray(content)) { for (const block of content) { if (block.type === 'tool_use' && (block.name === 'Write' || block.name === 'Edit')) { const filePath = block.input?.file_path if (filePath && !seenFiles.has(filePath)) { seenFiles.add(filePath) fileChanges.push({ path: filePath, action: block.name === 'Write' ? 'created' : 'modified', timestamp: msg.timestamp, messageUuid: msg.uuid, }) } } } } } } return { sessionId, projectName, files: fileChanges, totalChanges: fileChanges.length, } satisfies SessionFilesSummary })
- src/mcp/index.ts:138-151 (registration)Registers the MCP tool 'get_session_files' with input schema (project_name, session_id) and a thin async handler that calls the core getSessionFiles function and formats response.server.tool( 'get_session_files', 'Get list of all files changed in a session (from file-history-snapshot and tool_use)', { project_name: z.string().describe('Project folder name'), session_id: z.string().describe('Session ID'), }, async ({ project_name, session_id }) => { const result = await Effect.runPromise(session.getSessionFiles(project_name, session_id)) return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], } } )
- src/lib/session.ts:355-368 (schema)TypeScript interfaces defining the structure of file changes and the overall session files summary returned by the tool.export interface FileChange { path: string action: 'created' | 'modified' | 'deleted' timestamp?: string messageUuid?: string } // Session file changes summary export interface SessionFilesSummary { sessionId: string projectName: string files: FileChange[] totalChanges: number }