Overview
Claude Analytics is a Next.js 16 application that visualizes usage data from Claude Code’s local~/.claude/ directory. The application operates in two distinct modes:
Local Mode
Server component reads
~/.claude/ directly via Node.js fs module and passes data to client componentsUpload Mode
User exports data with
scripts/export.mjs, then uploads the JSON file. All processing happens client-side in the browserPrivacy First: No data is ever sent to external servers. There is no database. All analytics processing happens locally or in your browser.
Data Flow Architecture
Component Flow
-
Data Loading Layer (
src/app/page.tsx)- Server-side component that calls
loadAllData()fromsrc/lib/load-data.ts - Reads all necessary files from
~/.claude/directory - Passes initial data to client components
- Server-side component that calls
-
State Management Layer (
ClientPage)- Manages multi-profile state
- Handles file uploads and profile switching
- Renders either
UploadZoneorDashboard
-
Presentation Layer (
Dashboard+ child components)- Project filtering and tab navigation
- Data visualization components
- Interactive charts and tables
Key Architecture Decisions
Client-Side Rendering
All UI components use"use client" directive. The server component (page.tsx) only reads files from disk — all chart rendering and interaction happens client-side.
Benefits:
- Works as a static export with uploaded files
- Full interactivity without server round-trips
- Seamless transition between local and upload modes
src/app/page.tsx
Multi-Profile State Management
ClientPage manages an array of Profile objects, each containing:
Unique identifier for the profile
Display name (“Local” or generated from account UUID)
Complete analytics data for the profile
Profile Structure
Project Filtering Strategy
Dashboard component extracts unique project_path values from sessions and provides a dropdown filter:
- Filtered:
sessionsandhistoryarrays are filtered by selected project - Unfiltered: Stats, heatmap, and hour chart remain unfiltered because they use pre-aggregated data from
stats-cache.jsonthat can’t be split by project
Project Filtering Logic
Next.js App Router Structure
Directory Layout
Directory Layout
Root Layout
The root layout (src/app/layout.tsx) establishes:
- Font Stack: Geist Sans + Geist Mono from
next/font/google - Dark Mode:
<html className="dark">for persistent dark theme - Metadata: Title and description for SEO
src/app/layout.tsx
API Routes
Session Messages Endpoint
GET /api/session-messages
Fetches full conversation transcript for a specific session
The unique session identifier
Absolute path to the project directory
This endpoint only works in local mode — it requires filesystem access to
~/.claude/projects/src/app/api/session-messages/route.ts
Design Philosophy
Neomorphic Dark Theme
The application uses a custom neomorphic design system defined inglobals.css:
- Base Background:
#0a0a0a(near-black) - Card Background:
#1a1a1awith subtle inner shadows - Borders: White with 5-10% opacity
- Text Hierarchy: White → Gray 200 → Gray 400 → Gray 600
[data-slot="..."] selectors with consistent neomorphic shadows.
Performance Considerations
Chart Rendering
Chart Rendering
Uses Recharts library with responsive containers. All charts are client-rendered for interactivity.
Data Filtering
Data Filtering
Uses React
useMemo to prevent unnecessary recalculations during project filtering.Session Expansion
Session Expansion
Fetches message transcripts on-demand via API route only when user expands a session.
Prompt History
Prompt History
Limits display to first 200 prompts to prevent rendering slowdown.
Technology Stack
Next.js 16
App Router framework with server/client components
React 19
UI library with modern hooks
Recharts
Area, Bar, and Pie charts
Radix UI
Headless primitives (Tabs, Select, ScrollArea)
Tailwind CSS 4
Utility-first styling
TypeScript
Type-safe development
Lucide React
Icon system
date-fns
Date formatting utilities