claude-session-insights 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # claude-session-insights
2
+
3
+ A lightweight CLI tool that analyzes your Claude Code sessions locally, computes an efficiency score, and surfaces actionable insights to help you use Claude more effectively.
4
+
5
+ Think "Spotify Wrapped" for your Claude Code usage — scores, summaries, badges, cost breakdowns, AI-powered analysis, and a local dashboard. All data stays on your machine.
6
+
7
+ ## Features
8
+
9
+ - **Efficiency Score (0-100)** — weighted composite across 5 dimensions: tool call ratio, cache hit rate, context management, model fit, and prompt specificity
10
+ - **Overall Summary** — natural-language assessment of your prompting habits with specific recommendations
11
+ - **Per-Session Summary** — each session gets a plain-English breakdown of what happened, what went well, and what could improve
12
+ - **Session Drill-down** — click any session to see the full conversation timeline with per-turn token counts, costs, tool calls, and prompt previews
13
+ - **AI Insights** — on-demand deeper analysis powered by the Claude CLI, with model picker (Sonnet, Opus, Haiku) and streaming output
14
+ - **Heaviest Sessions** — top sessions ranked by cost for quick identification of expensive outliers
15
+ - **Daily Score Chart** — trend visualization of your efficiency score, session count, tokens, and cost over time
16
+ - **Badges** — positive achievements (Surgical Prompter, Cache Whisperer, etc.) and negative anti-patterns (Opus Addict, Token Furnace, etc.)
17
+ - **Light/Dark Theme** — toggleable with automatic system preference detection
18
+ - **Auto-Refresh** — optional 15-second polling to keep the dashboard current while you work
19
+ - **Account Info** — displays your subscription type, org, and email from `claude auth status`
20
+
21
+ ## Quick Start
22
+
23
+ ```bash
24
+ npx claude-session-insights
25
+ ```
26
+
27
+ That's it. Opens a dashboard at `http://localhost:6543` showing all your Claude Code sessions.
28
+
29
+ ## Commands
30
+
31
+ ```bash
32
+ npx claude-session-insights # open the dashboard
33
+ npx claude-session-insights export # generate team-export.json
34
+ npx claude-session-insights --port 8080 # custom port (default: 6543)
35
+ npx claude-session-insights --no-open # don't auto-launch browser
36
+ npx claude-session-insights --help # show help
37
+ ```
38
+
39
+ ## What It Reads
40
+
41
+ Claude Code stores session data in `~/.claude/projects/`. This tool reads those JSONL files to extract:
42
+
43
+ - Token counts (input, output, cache creation, cache read)
44
+ - Models used per turn
45
+ - Tool calls (Read, Edit, Bash, etc.)
46
+ - Timestamps and session structure
47
+ - Prompt text (displayed locally only, never exported)
48
+
49
+ Works with sessions from the terminal CLI, VS Code extension, and Claude Desktop (Code tab) — they all write to the same `~/.claude/` directory.
50
+
51
+ ## Efficiency Score
52
+
53
+ Each session is scored 0-100 across five dimensions:
54
+
55
+ | Dimension | Weight | What it measures |
56
+ |---|---|---|
57
+ | Tool Call Ratio | 30% | Fewer tool calls per message = more specific prompts |
58
+ | Cache Hit Rate | 25% | Higher cache reuse = better session structure |
59
+ | Context Management | 20% | Using /clear near cost inflection points |
60
+ | Model Fit | 15% | Right model for the task complexity |
61
+ | Prompt Specificity | 10% | Short vague prompts that cause token blowups |
62
+
63
+ Your overall score is the weighted average across sessions from the last 7 days.
64
+
65
+ ## Summaries
66
+
67
+ The dashboard generates rule-based summaries at two levels:
68
+
69
+ **Overall** — analyzes patterns across all your sessions: session length habits, prompt specificity, cache efficiency, model selection, and cost distribution. Surfaces 2-3 key findings and concrete recommendations.
70
+
71
+ **Per-session** — classifies each session (quick fix, focused task, long refactor), identifies the main cost driver, and highlights strengths. Displayed at the top of the session detail view.
72
+
73
+ ## AI Insights
74
+
75
+ Click "Generate AI Insights" to run a deeper analysis using the Claude CLI. This streams a response via SSE that covers:
76
+
77
+ - **Key Patterns** — non-obvious trends the static rules miss (time-of-day patterns, project-specific habits, cost trajectories)
78
+ - **Biggest Opportunities** — specific workflow changes with quantified potential savings
79
+ - **What's Working Well** — habits worth keeping
80
+ - **Standout Session** — the most interesting session and what can be learned from it
81
+
82
+ You can pick which model to use (Sonnet, Opus, or Haiku) from the model picker. Results are cached for the session. Requires the `claude` CLI to be installed and in your PATH.
83
+
84
+ ## Badges
85
+
86
+ ### Positive
87
+
88
+ | Badge | Criteria |
89
+ |---|---|
90
+ | Surgical Prompter | Tool call ratio < 2x across 5+ sessions |
91
+ | Cache Whisperer | Cache hit rate > 75% across 5+ sessions |
92
+ | Clean Slate | Uses /clear near cost inflection in 3+ sessions |
93
+ | Model Sniper | Appropriate model selection > 90% of sessions |
94
+ | Efficiency Diamond | Overall score > 85 sustained over 7 days |
95
+
96
+ ### Negative
97
+
98
+ | Badge | Criteria |
99
+ |---|---|
100
+ | Opus Addict | >70% of sessions use Opus when Sonnet would suffice |
101
+ | Token Furnace | Average cost per user message > $0.50 across 5+ sessions |
102
+ | Context Hoarder | Cost inflection without /clear in 50%+ of long sessions |
103
+ | Vague Commander | >30% of prompts are vague and trigger expensive responses |
104
+
105
+ ## Team Export *(experimental — not yet tested)*
106
+
107
+ > **Note:** This feature is experimental and has not been thoroughly tested. Use at your own risk — the output format may change in future versions.
108
+
109
+ Generate a privacy-safe snapshot to share with your team lead:
110
+
111
+ ```bash
112
+ npx claude-session-insights export
113
+ ```
114
+
115
+ The export contains scores, token counts, cost breakdowns, badge status, and summary categories — **never prompt text**. Team leads can aggregate these to identify coaching opportunities across the team.
116
+
117
+ ## Supported Models
118
+
119
+ Pricing is built in for:
120
+
121
+ - Claude Opus 4.5 / 4.6
122
+ - Claude Sonnet 4.5 / 4.6
123
+ - Claude Haiku 4.5
124
+
125
+ Unknown models fall back to Sonnet-tier pricing.
126
+
127
+ ## Development
128
+
129
+ ```bash
130
+ npm run dev # starts server with --watch on src/ and public/, live reloads on changes
131
+ ```
132
+
133
+ ## Dependencies
134
+
135
+ **Zero runtime dependencies.** Uses only Node.js built-in modules (`http`, `fs`, `readline`, `crypto`, `os`, `path`). The `open` package is optionally used to launch the browser but is not required — if unavailable, the URL is printed instead.
136
+
137
+ AI Insights requires the [`claude` CLI](https://docs.anthropic.com/en/docs/claude-code) to be installed.
138
+
139
+ ## Privacy
140
+
141
+ - All data processing happens locally on your machine
142
+ - The dashboard runs on localhost only
143
+ - Prompt text is displayed in the local dashboard but never included in exports
144
+ - Team exports contain only aggregate scores, counts, and pattern categories
145
+ - AI Insights sends a data snapshot (scores, token counts, costs — no prompt text) to the Claude CLI for analysis
146
+
147
+ ## Inspiration
148
+
149
+ Built from scratch, inspired by [claude-spend](https://github.com/writetoaniketparihar-collab/claude-spend) by Aniket Parihar (MIT). We share the same data source but take a different approach: efficiency scoring, team workflows, and behavioral gamification.
150
+
151
+ ## License
152
+
153
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { startServer } from "../src/server.js";
4
+ import { generateExport } from "../src/export.js";
5
+
6
+ const args = process.argv.slice(2);
7
+
8
+ if (args.includes("--help") || args.includes("-h")) {
9
+ console.log(`claude-session-insights — Claude Code efficiency insights
10
+
11
+ Usage:
12
+ claude-session-insights Open the dashboard
13
+ claude-session-insights export Generate team-export.json
14
+ claude-session-insights --port 8080 Custom port (default: 6543)
15
+ claude-session-insights --no-open Don't auto-launch browser
16
+ claude-session-insights --help Show this help`);
17
+ process.exit(0);
18
+ }
19
+
20
+ if (args[0] === "export") {
21
+ const output = args[1] || "team-export.json";
22
+ console.log("Parsing sessions...");
23
+ const data = await generateExport(output);
24
+ console.log(`Export saved to ${output}`);
25
+ console.log(` Score: ${data.summary.efficiencyScore}`);
26
+ console.log(` Sessions: ${data.summary.totalSessions}`);
27
+ console.log(` Tokens: ${data.summary.totalTokens.toLocaleString()}`);
28
+ console.log(` Badges: ${data.badges.join(", ") || "none yet"}`);
29
+ process.exit(0);
30
+ }
31
+
32
+ // Dashboard mode
33
+ const portIdx = args.indexOf("--port");
34
+ const port = portIdx !== -1 ? parseInt(args[portIdx + 1], 10) : 6543;
35
+ const noOpen = args.includes("--no-open");
36
+
37
+ startServer(port);
38
+
39
+ if (!noOpen) {
40
+ const url = `http://localhost:${port}`;
41
+ const { exec } = await import("node:child_process");
42
+ const cmd =
43
+ process.platform === "darwin"
44
+ ? `open "${url}"`
45
+ : process.platform === "win32"
46
+ ? `start "${url}"`
47
+ : `xdg-open "${url}"`;
48
+ exec(cmd);
49
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "claude-session-insights",
3
+ "version": "0.3.0",
4
+ "description": "Analyze Claude Code sessions for efficiency insights, scores, and team metrics",
5
+ "type": "module",
6
+ "bin": {
7
+ "claude-session-insights": "./bin/cli.js"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "src/",
12
+ "public/"
13
+ ],
14
+ "keywords": [
15
+ "claude",
16
+ "claude-code",
17
+ "efficiency",
18
+ "tokens",
19
+ "usage",
20
+ "insights"
21
+ ],
22
+ "scripts": {
23
+ "dev": "node --watch-path=src --watch-path=public bin/cli.js --no-open"
24
+ },
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/auaustria/claude-session-insights"
29
+ }
30
+ }