Skip to content

About

๐Ÿ‘€ Local-first analytics and statusline for Claude Code - capture sessions, tool calls, costs, and performance into SQLite for fast, actionable insights.

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

94 Commits

Folders and files

Repository files navigation

Claude Code Analytics

This is Claude Code Analytics! It uses ClaudeCode statusline and Claude Code hooks to store information about your Claude Code sessions in a local SQLite database.

Hook-Driven Architecture

Why use hooks instead of just reading statusline data?

The statusline updates every 300ms, so we could do all analytics calculations in real-time. But this marvellous monstrosity explores a different approach:

  • Hooks do heavy lifting during natural Claude Code pauses (PostToolUse, UserPromptSubmit)
  • Statusline stays responsive with sub-millisecond lookups of pre-computed data
  • True zero-impact analytics - expensive queries happen when Claude Code is already waiting
  • Separation of concerns - data processing vs. display logic

The result? A statusline that can show complex productivity insights, cache efficiency metrics, and sparkline visualizations without ever slowing down your workflow.

Sometimes the best solution is the most over-engineered one! ๐Ÿ˜‚

There's a CLI for reports and analytics, for example Cost Analytics...

โ—‡  How many days to analyze?
โ”‚  7

Cost Trend (Last 7 Days)

   $21.47    โ”ค                           โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
   $19.55    โ”ค                         โ•ญโ”€โ•ฏ                โ•ฐโ”€โ”€โ•ฎ
   $17.63    โ”ค                       โ•ญโ”€โ•ฏ                     โ•ฐโ”€โ”€โ•ฎ
   $15.71    โ”ค                     โ•ญโ”€โ•ฏ                          โ•ฐโ”€โ”€โ•ฎ
   $13.78    โ”ค                  โ•ญโ”€โ”€โ•ฏ                               โ•ฐโ”€โ”€โ”€โ•ฎ
   $11.86    โ”ค                โ•ญโ”€โ•ฏ                                      โ•ฐโ”€
    $9.94    โ”ค             โ•ญโ”€โ”€โ•ฏ
    $8.02    โ”ค   โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
    $6.10    โ”ผโ”€โ”€โ”€โ•ฏ

Total Cost        โ”‚$68.11
Total Sessions    โ”‚87
Avg Cost/Session  โ”‚$0.78
Daily Average     โ”‚$9.73

Activity patterns...

โ—‡  How many days to analyze?
โ”‚  7

Activity Heatmap (Last 7 Days)

Total: 88 sessions across 5 days
Peak: 13 sessions on 2025-08-27 at 20:00

    00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Sun โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘
Mon โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘
Tue โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–“โ–“ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘
Wed โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–ˆโ–ˆ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘
Thu โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–ˆโ–ˆ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–“โ–“ โ–“โ–“ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘
Fri โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–“โ–“ โ–“โ–“ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘
Sat โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–‘โ–‘ โ–“โ–“ โ–‘โ–‘ โ–“โ–“ โ–“โ–“ โ–“โ–“ โ–‘โ–‘ โ–‘โ–‘

โ–ˆโ–ˆ High (9+)  โ–“โ–“ Medium (5-9)  โ–‘โ–‘ Low (0-5)

Top Activity Hours:
  1. Wed 20:00 (2025-08-27): 13 sessions
  2. Thu 09:00 (2025-08-28): 9 sessions
  3. Tue 10:00 (2025-08-26): 8 sessions
  4. Thu 18:00 (2025-08-28): 7 sessions
  5. Thu 16:00 (2025-08-28): 6 sessions

Installation

Install globally with your preferred package manager:

# npm
npm install -g claude-code-analytics

# pnpm
pnpm add -g claude-code-analytics

# bun
bun add -g claude-code-analytics

# volta
volta install claude-code-analytics

First Run (Onboarding)

Run interactive setup to install the statusline and hooks:

claude-code-analytics config

This lets you:

  • Install the statusline and/or lightweight hooks in ~/.claude/settings.json.
  • Enable or disable local data collection in ~/.claude/claude-code-analytics.json.

Note: Running claude-code-analytics with no arguments is intended for Claude Code statusline integration and isnโ€™t useful on its own in a terminal. Use subcommands like config, analytics, or quick-stats.

Tip: To confirm the CLI is available on your PATH, try:

claude-code-analytics -h

This should print the help text.

Commands

  • claude-code-analytics config: Interactive configuration (statusline, hooks, settings).
  • claude-code-analytics analytics: Interactive analytics dashboard (tables and ASCII charts).
  • claude-code-analytics quick-stats: One-shot 7โ€‘day summary.
  • claude-code-analytics install | uninstall: Install/remove statusline and hooks without prompts.
  • claude-code-analytics --help | --version: Show help/version.

Default behaviour: When invoked without arguments (or by Claude Code), the binary runs in statusline mode.

Usage

  • Use Claude Code normally. The statusline and hooks record session metadata locally for analytics.
  • View analytics anytime with claude-code-analytics analytics or a quick summary with claude-code-analytics quick-stats.

Data & Privacy

  • Database: ~/.claude/claude-code-analytics.db (SQLite, local-only).
  • Config: ~/.claude/claude-code-analytics.json.
  • Claude integration: ~/.claude/settings.json (non-destructive; only our entries).
  • No telemetry or network calls.

To disable collection, set data_collection: false in ~/.claude/claude-code-analytics.json.

Perโ€‘Project Configuration

You can override settings per project with a local config file at:

  • <project>/.claude/claude-code-analytics.json

Example (this repo): claude-code-analytics/.claude/claude-code-analytics.json

Project config deepโ€‘merges over the global config. Useful for:

  • Disabling collection in a specific repo
  • Customizing the statusline layout per project

Example:

{
	"data_collection": true,
	"display": {
		"layout": [
			["git", "model"],
			["cost", "duration", "lines_changed"]
		]
	}
}

Theming & Display

You can customize the statuslineโ€™s look globally or perโ€‘project.

  • Config files:
    • Global: ~/.claude/claude-code-analytics.json
    • Project: <project>/.claude/claude-code-analytics.json (overrides global)

Display keys

  • display.theme: minimal (default), ascii, or emoji
  • display.icons: enable/disable icons globally (default: true)
  • display.powerline: boolean (autoโ€‘detect when omitted)
  • display.icon_overrides: map of symbol name โ†’ string
  • display.layout: string[][] to control segment order and lines

Examples

Minimal (default) with Powerline forced:

{
	"display": {
		"theme": "minimal",
		"powerline": true
	}
}

Pure ASCII:

{
	"display": {
		"theme": "ascii",
		"icons": true
	}
}

Emoji (optโ€‘in) with simple overrides:

{
	"display": {
		"theme": "emoji",
		"icon_overrides": {
			"branch": " ๎‚ ",
			"ahead": "โ†‘",
			"behind": "โ†“"
		}
	}
}

Notes

  • No environment variables are used for theming. Configure via JSON only.
  • Project config deepโ€‘merges over global config.

Terminal Visuals

The CLI uses color and layout for readability without relying on heavy emoji.

  • chalk for subtle, meaningful color (headings, axes, legends)
  • cli-table3 for clean, aligned tables
  • asciichart for compact line charts with scaled yโ€‘axis labels
  • Powerline glyphs when the terminal supports them (autoโ€‘detected)

Upcoming improvements

  • Color cues for session rank, cache efficiency, and tool success
  • Theme presets that bundle layout + color choices (e.g., Minimal, Dense)
  • Optional ASCIIโ€‘only mode across all views for maximal portability

Statusline Segments

Add segments to display.layout (each inner array is a row). Available segments:

  • Core: git, model, cost, duration, lines_changed, tool_performance, cache_efficiency, working_directory
  • Gauges: tool_gauge (tool success %), cache_gauge (cache efficiency %), context_gauge (context tokens vs limit)
  • Bars: lines_bar (added vs removed)
  • Sparklines: cost_sparkline (recent session costs), cache_reads_sparkline (cache read tokens per session)
  • Activity: activity_strip (last 24h hourly activity), streak_bar (last 7 days usage)
  • Mix: model_mix (top 3 models compact bands)
  • Ambient: ambient_wave, ambient_bounce, ambient_marquee, ambient_spinner, ambient_twinkle, ambient_wave_sine

Segment options (under display)

  • colors: boolean โ€” enable color cues (default: true)
  • bar_width: number โ€” width for gauges/bars (default: 10โ€“12)
  • sparkline: { width, height, points } โ€” size and history length for sparklines
  • context: { token_limit, mode, recent_n } โ€” context gauge configuration
    • token_limit: default 200000 (200k tokens)
    • mode: latest | session_total | recent_n (default latest)
    • recent_n: number of assistant turns when mode = recent_n

Example multiโ€‘row layout

{
	"display": {
		"theme": "minimal",
		"colors": true,
		"bar_width": 12,
		"sparkline": { "width": 20, "height": 2, "points": 20 },
		"context": {
			"token_limit": 200000,
			"mode": "latest",
			"recent_n": 5
		},
		"layout": [
			["working_directory"],
			["git", "model"],
			["cost", "duration"],
			["tool_gauge", "cache_gauge"],
			["context_gauge"],
			["activity_strip"],
			["streak_bar"],
			["model_mix"],
			["cache_reads_sparkline"],
			["ambient_wave"],
			["ambient_bounce"],
			["ambient_marquee"],
			["ambient_spinner"],
			["ambient_twinkle"],
			["ambient_wave_sine"],
			["cost_sparkline"]
		]
	}
}

About

๐Ÿ‘€ Local-first analytics and statusline for Claude Code - capture sessions, tool calls, costs, and performance into SQLite for fast, actionable insights.

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages