Skip to content

samuelleecong/learn_and_vibe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Learn and Vibe

Analytics and insights for vibe-based learning sessions

This repository contains the Learn and Vibe project, starting with Claude Code Chat Analytics.


πŸ“ Repository Structure

learn_and_vibe/                    ← You are here (repository root)
β”œβ”€β”€ chat-analytics/                ← The Next.js application
β”‚   β”œβ”€β”€ app/                       ← Next.js pages and API routes
β”‚   β”œβ”€β”€ lib/                       ← Core business logic
β”‚   β”œβ”€β”€ components/                ← React components
β”‚   └── docs/                      ← Technical documentation
β”œβ”€β”€ PRD.md                         ← Product requirements
β”œβ”€β”€ sdk_docs.md                    ← Claude SDK reference
└── README.md                      ← This file

⚠️ Important: The actual application is in the chat-analytics/ directory. Unless otherwise noted, all commands in this documentation assume you're working from chat-analytics/.


Claude Code Chat Analytics

Transform your Claude Code chat histories into actionable insights

A Next.js 15 progressive web application that automatically discovers, analyzes, and extracts value from your Claude Code conversations. Built with TypeScript and modern React patterns.

🎯 What This Does

Claude Code Chat Analytics automatically:

  • Discovers all your Claude Code projects from ~/.claude/projects/
  • Analyzes conversation patterns using Claude's own AI via Agent SDK
  • Extracts reusable code snippets and identifies time sinks
  • Provides actionable recommendations to improve your workflow
  • Stores everything locally in SQLite for instant access

Think of it as retrospective analytics for your AI-assisted development.

✨ Key Features

πŸ” Automatic Discovery

  • Scans ~/.claude/projects/ to find all chat histories
  • Extracts actual project paths from session metadata
  • Organizes sessions chronologically with modification dates

🧠 AI-Powered Analysis

  • Uses Claude Agent SDK to analyze conversations
  • Detects repetitive patterns and time sinks
  • Identifies "quick wins" - solutions that worked efficiently
  • Extracts code snippets with language detection and tagging

πŸ“Š Insightful Metrics

  • Time spent estimates per project
  • Turn counts and session durations
  • Tool usage statistics (Read, Write, Edit, Bash, etc.)
  • Session timelines with date range filtering

πŸ’Ύ Local Storage

  • SQLite database with WAL mode for concurrency
  • Persistent analysis cache to avoid re-analysis
  • Project starring/bookmarking
  • Full-text storage of original sessions

🎨 Modern UI

  • shadcn/ui components with Radix primitives
  • Tailwind CSS for responsive design
  • Server and Client Components architecture
  • Date range picker for targeted analysis

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Next.js 15 App                          β”‚
β”‚                    (App Router + RSC)                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                    β”‚                    β”‚
         β–Ό                    β–Ό                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   File Scanner  β”‚  β”‚  JSONL Parser   β”‚  β”‚  Claude Agent   β”‚
β”‚   (scanner.ts)  β”‚  β”‚ (jsonl-parser)  β”‚  β”‚  (analyzer.ts)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                    β”‚                    β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  SQLite DB      β”‚
                    β”‚  (better-sqlite3)β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                    β”‚                    β”‚
         β–Ό                    β–Ό                    β–Ό
    [projects]          [sessions]          [analyses]
    [patterns]          [code_snippets]     [settings]

πŸš€ Quick Start

Prerequisites

Required:

  • Node.js 18+ (tested with Node 24.4.0)
  • Claude Code CLI (must be installed and authenticated)

Install Claude Code:

npm install -g @anthropic-ai/claude-code

Authenticate (opens Claude Console):

claude

You'll need:

πŸ“š Full Claude Code installation guide

Installation

πŸ“ Starting location: Repository root (learn_and_vibe/)

  1. Navigate to the application directory:

    cd chat-analytics
  2. Install dependencies:

    # From: learn_and_vibe/chat-analytics/
    npm install
  3. Configure environment (optional):

    # From: learn_and_vibe/chat-analytics/
    cp .env.example .env.local

    Available options in .env.local:

    # Claude model to use for analysis (default: claude-sonnet-4-5-20250929)
    CLAUDE_MODEL=claude-sonnet-4-5-20250929
  4. Run the development server:

    # From: learn_and_vibe/chat-analytics/
    npm run dev
  5. Open your browser: Navigate to http://localhost:3000

πŸ’‘ Tip: All subsequent commands in this guide assume you're in the chat-analytics/ directory unless explicitly stated otherwise.


πŸš€ Quick Launch with cca Alias (Optional)

For instant access from anywhere, create a global cca command that launches the app.

⚠️ Run this from chat-analytics/ directory:

# 1. Navigate to the app directory (if not already there)
cd learn_and_vibe/chat-analytics

# 2. Verify you're in the right place
pwd
# βœ… Should end with: /learn_and_vibe/chat-analytics

# 3. Create the alias
# For Zsh (macOS default):
echo "alias cca=\"$(pwd)/launch-cca.sh\"" >> ~/.zshrc
source ~/.zshrc

# For Bash (Linux/older macOS):
echo "alias cca=\"$(pwd)/launch-cca.sh\"" >> ~/.bashrc
source ~/.bashrc

# 4. Verify it worked
type cca
# Should show: cca is an alias for /full/path/to/learn_and_vibe/chat-analytics/launch-cca.sh

What this does:

  1. Cleans up old processes on port 3000
  2. Starts the server in the background
  3. Monitors output for "Ready in" message
  4. Opens browser only when server is actually ready (no more waiting!)
  5. Shows server logs in foreground (Ctrl+C to stop)

Now launch from anywhere:

cca  # Cleans up old processes, opens browser, starts server

To stop the server:

# Press Ctrl+C in the terminal, or:
lsof -ti:3000 | xargs kill -9

πŸ“– See chat-analytics/CCA_SETUP.md for detailed setup instructions and troubleshooting.


πŸ’» Installing as a Desktop App (PWA)

You can install this as a Progressive Web App on your laptop for a native app-like experience!

Quick Install

  1. Start the server:

    cd chat-analytics
    npm run dev
  2. Open in Chrome/Edge/Brave: Navigate to http://localhost:3000

  3. Install:

    • Look for the install icon (βŠ•) in the address bar
    • Or click Menu β†’ "Install Claude Code Chat Analytics..."
    • Click "Install" in the confirmation dialog
  4. Done! The app will:

    • Open in its own window (no browser UI)
    • Be added to your Applications folder
    • Appear in Spotlight search (macOS) or Start Menu (Windows)
    • Launch like a native app

⚠️ Important: The PWA creates a desktop shortcut, but you still need to run npm run dev each time before using the app (e.g., after restarting your computer). The installed app connects to your local server.

πŸ’‘ Solutions:

  • Auto-start: See Auto-Start Solutions for LaunchAgent (macOS), Task Scheduler (Windows), or systemd (Linux) setup to automatically start the server on boot

⚠️ Note: This app cannot be deployed to cloud platforms (Vercel, Netlify, etc.) because it requires local file access to ~/.claude/projects/ and your local Claude CLI. It must run on your machine.

See PWA Installation Guide for detailed instructions, troubleshooting, and platform-specific steps.

πŸ“– Usage Guide

1. First-Time Setup

When you first open the app:

  1. Click "Scan Projects" on the dashboard
  2. Wait for the scan to complete (usually 2-10 seconds)
  3. All discovered projects will appear as cards

2. Analyzing a Project

  1. Select a project by clicking its card
  2. Choose a date range using the date picker (defaults to last 7 days)
  3. Click "Analyze Sessions"
  4. Wait for analysis to complete (30s - 2min depending on session count)
  5. View results in tabs:
    • Overview: Summary and metrics
    • Patterns: Repetitive prompts, time sinks, quick wins
    • Code Snippets: Extracted code with language/tags
    • Recommendations: Actionable suggestions

3. Starring Projects

Click the star icon ⭐ on any project card to bookmark it. Starred projects appear at the top of your dashboard.

4. Settings

Navigate to /settings to:

  • Check Claude CLI status
  • View CLI installation path
  • See authentication status
  • Configure analysis preferences (future)

πŸ—„οΈ Database Schema

The app uses SQLite with the following tables:

Table Purpose
projects Discovered Claude Code projects
sessions Individual chat sessions (JSONL files)
analyses Analysis results with summaries
patterns Detected patterns (repetitive, time_sink, quick_win)
code_snippets Extracted code with metadata
settings User preferences and configuration

See DATABASE.md for full schema details.

πŸ› οΈ Tech Stack

Core

  • Next.js 15 - App Router, Server Components, Server Actions
  • React 19 - Latest React features
  • TypeScript 5 - Full type safety
  • SQLite - Local database via better-sqlite3

AI/Analysis

  • Claude Agent SDK v0.1.5 - AI-powered analysis
  • Claude Code CLI - Local authentication

UI/Styling

  • shadcn/ui - Pre-built component library
  • Radix UI - Accessible primitives
  • Tailwind CSS 4 - Utility-first styling
  • Lucide React - Icon library

Data Handling

  • date-fns - Date manipulation
  • react-hook-form - Form state management
  • zod - Schema validation

πŸ“ Detailed Project Structure

Understanding the Two-Level Structure:

This repository (learn_and_vibe/) is organized as a container for multiple learning analytics projects. Currently, it contains the Claude Code Chat Analytics application.

learn_and_vibe/                     ← Repository root
β”œβ”€β”€ README.md                       ← This file (overview of all projects)
β”œβ”€β”€ PRD.md                          ← Product Requirements Document
β”œβ”€β”€ sdk_docs.md                     ← Claude SDK reference documentation
β”œβ”€β”€ CLAUDE.md                       ← Project-wide Claude Code instructions
β”‚
└── chat-analytics/                 ← πŸ“¦ Application root (Next.js app)
    β”‚
    β”œβ”€β”€ README.md                   ← App-specific installation guide
    β”œβ”€β”€ package.json                ← Dependencies and scripts
    β”œβ”€β”€ tsconfig.json               ← TypeScript config (defines @/* alias)
    β”œβ”€β”€ next.config.ts              ← Next.js configuration
    β”œβ”€β”€ tailwind.config.ts          ← Tailwind CSS config
    β”‚
    β”œβ”€β”€ app/                        ← Next.js App Router (pages & APIs)
    β”‚   β”œβ”€β”€ page.tsx                  # Dashboard (project list)
    β”‚   β”œβ”€β”€ layout.tsx                # Root layout with CLI status banner
    β”‚   β”œβ”€β”€ projects/[projectId]/     # Dynamic project detail pages
    β”‚   β”œβ”€β”€ settings/                 # Settings page
    β”‚   └── api/                      # API route handlers
    β”‚       β”œβ”€β”€ scan/route.ts           # POST: Discover Claude projects
    β”‚       β”œβ”€β”€ analyze/route.ts        # POST: Run AI analysis
    β”‚       β”œβ”€β”€ projects/route.ts       # GET: Fetch projects
    β”‚       └── claude-status/route.ts  # GET: Check CLI installation
    β”‚
    β”œβ”€β”€ lib/                        ← Core business logic
    β”‚   β”œβ”€β”€ db.ts                     # SQLite database helpers
    β”‚   β”œβ”€β”€ scanner.ts                # Filesystem scanner
    β”‚   β”œβ”€β”€ jsonl-parser.ts           # Parse Claude session files
    β”‚   β”œβ”€β”€ analyzer.ts               # Claude Agent SDK integration
    β”‚   β”œβ”€β”€ cache-builder.ts          # Analysis caching
    β”‚   β”œβ”€β”€ date-utils.ts             # Date utilities
    β”‚   └── utils.ts                  # General utilities
    β”‚
    β”œβ”€β”€ components/                 ← React components
    β”‚   β”œβ”€β”€ project-card.tsx          # Project cards on dashboard
    β”‚   β”œβ”€β”€ session-timeline.tsx      # Session visualization
    β”‚   β”œβ”€β”€ nav-bar.tsx               # Navigation
    β”‚   └── ui/                       # shadcn/ui components
    β”‚
    β”œβ”€β”€ docs/                       ← Technical documentation
    β”‚   β”œβ”€β”€ ARCHITECTURE.md           # System design deep-dive
    β”‚   β”œβ”€β”€ DATABASE.md               # Schema documentation
    β”‚   β”œβ”€β”€ API.md                    # API reference
    β”‚   └── DEVELOPMENT.md            # Developer guide
    β”‚
    β”œβ”€β”€ public/                     ← Static assets
    β”œβ”€β”€ analysis-cache/             ← Cached results (gitignored)
    └── chat-analytics.db           ← SQLite database (gitignored)

Path Alias Explanation:

The TypeScript compiler is configured in chat-analytics/tsconfig.json with:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./*"]
    }
  }
}

This means @/ resolves to chat-analytics/ (the app root), so:

  • @/lib/db β†’ chat-analytics/lib/db.ts
  • @/components/ui/button β†’ chat-analytics/components/ui/button.tsx

Where to Run Commands:

Unless explicitly stated, all npm commands and scripts should be run from chat-analytics/:

cd chat-analytics/    # Navigate to app root
npm install           # Install dependencies
npm run dev           # Start dev server

πŸ”Œ API Endpoints

POST /api/scan

Scans ~/.claude/projects/ and saves to database.

Response:

{
  "success": true,
  "projectsFound": 12,
  "totalSessions": 247
}

POST /api/analyze

Runs Claude Agent analysis on project sessions.

Request:

{
  "projectId": 1,
  "dateFrom": "2025-01-01",
  "dateTo": "2025-01-31",
  "customPrompts": ["What authentication patterns were used?"]
}

Response:

{
  "success": true,
  "analysisId": 42,
  "analysis": {
    "projectSummary": "...",
    "timeSpentMinutes": 180,
    "patterns": [...],
    "codeSnippets": [...],
    "recommendations": [...]
  }
}

GET /api/projects

Fetches all projects with session counts.

Response:

[
  {
    "id": 1,
    "name": "my-awesome-app",
    "path": "/Users/you/projects/my-awesome-app",
    "total_sessions": 23,
    "last_analyzed": "2025-01-15T10:30:00.000Z",
    "is_starred": 1
  }
]

POST /api/projects/star

Toggles project star status.

Request:

{
  "projectId": 1
}

GET /api/claude-status

Checks if Claude CLI is installed and working.

Response (success):

{
  "available": true,
  "path": "/Users/you/.claude/local/claude",
  "message": "Claude CLI is ready to use"
}

Response (not found):

{
  "available": false,
  "error": "CLAUDE_CLI_NOT_FOUND",
  "message": "Claude CLI not found. Install: npm install -g @anthropic-ai/claude-code"
}

See API.md for detailed endpoint documentation.

πŸ§ͺ Testing

The app includes comprehensive testing documentation:

  • Manual Testing: Step-by-step scenarios in TESTING_STRATEGY.md
  • Unit Tests: (Coming soon) Test database helpers and parsers
  • Integration Tests: (Coming soon) Test API routes
  • E2E Tests: (Coming soon) Playwright tests for critical flows

Quick Test

# Check Claude CLI status
curl http://localhost:3000/api/claude-status | jq

# Scan projects
curl -X POST http://localhost:3000/api/scan | jq

# Verify Claude CLI works
claude --version

🚧 Troubleshooting

"Claude CLI not found" error

Symptoms: Red banner appears, analysis fails

Solutions:

  1. Install Claude Code: npm install -g @anthropic-ai/claude-code
  2. Authenticate: claude (opens browser)
  3. Verify installation: which claude
  4. Restart the app: npm run dev

Common causes:

  • Claude Code not in PATH
  • Installed with --prefix flag to non-standard location
  • Using NVM and Claude installed in different Node version

See the Settings page for detailed installation instructions.

Analysis takes too long

Symptoms: Analysis running for 5+ minutes

Solutions:

  1. Reduce date range to analyze fewer sessions
  2. Check Claude CLI works: claude --version
  3. Check network connection (Claude needs internet)
  4. View console logs: npm run dev shows analysis progress

Database locked error

Symptoms: SQLITE_BUSY errors in console

Solutions:

  1. Stop any duplicate dev servers
  2. Delete chat-analytics.db-wal and chat-analytics.db-shm
  3. Restart: npm run dev

The database uses WAL mode which should prevent this, but multiple processes accessing the DB can cause conflicts.

Sessions not appearing

Symptoms: Scan completes but shows 0 sessions

Solutions:

  1. Verify Claude Code projects exist: ls ~/.claude/projects/
  2. Check JSONL files exist: ls ~/.claude/projects/*/
  3. Check file permissions: ensure files are readable
  4. Try manual path in Settings (future feature)

πŸ—ΊοΈ Roadmap

v1.0 (Current)

  • Project discovery from ~/.claude/projects/
  • JSONL parsing
  • Claude Agent SDK analysis
  • Pattern detection
  • Code snippet extraction
  • SQLite storage
  • Project starring
  • Date range filtering

v1.1 (Next)

  • Custom analysis prompts UI
  • Export analysis to Markdown/PDF
  • Search across all sessions
  • Session-level analysis (not just project-wide)
  • Better caching with TTL
  • Comparison view (compare two date ranges)

v2.0 (Future)

  • Tag-based organization
  • Multi-project analysis
  • Trend charts (time spent over time)
  • Code snippet favorites/collections
  • Manual session upload (for non-Claude Code histories)
  • Dark mode
  • Desktop app (Electron/Tauri)

🀝 Contributing

Contributions welcome! See DEVELOPMENT.md for:

  • Development setup
  • Code style guidelines
  • Testing requirements
  • PR process

πŸ“„ License

MIT License - see LICENSE for details

πŸ™ Acknowledgments

  • Anthropic for Claude Code and the Agent SDK
  • Vercel for Next.js 15
  • shadcn for the beautiful UI component library
  • The open source community for all the amazing tools

πŸ“š Additional Resources


Last updated: 2025-10-05

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages