The Sessions API tracks metadata for each coding session, including edit counts, corrections, and prompts. Use it to analyze productivity patterns and session quality.
export interface Session { id: string; // Session identifier (e.g., CLAUDE_SESSION_ID) project: string | null; // Project name started_at: string; // ISO 8601 timestamp ended_at: string | null; // ISO 8601 timestamp (null if active) edit_count: number; // Number of Edit/Write tool uses corrections_count: number; // Number of corrections made prompts_count: number; // Number of user prompts}
Session IDs should be unique per session. Use process.env.CLAUDE_SESSION_ID in Claude Code or generate your own UUID.
No return value. Counts are incremented atomically.
This method adds to existing counts. It does not set absolute values.
const store = createStore();const sessionId = process.env.CLAUDE_SESSION_ID;// After an editstore.updateSessionCounts(sessionId, 1, 0, 0);// After a correctionstore.updateSessionCounts(sessionId, 0, 1, 0);// After a user promptstore.updateSessionCounts(sessionId, 0, 0, 1);store.close();
Use the store API or raw SQL for custom analytics.
import { createStore } from 'pro-workflow';const store = createStore();const result = store.db.prepare(` SELECT AVG(edit_count) as avg_edits FROM sessions WHERE ended_at IS NOT NULL`).get() as { avg_edits: number };console.log(`Average edits per session: ${result.avg_edits.toFixed(1)}`);store.close();