Extracting Claude Code /insights from the Leaked Source — Install & Usage Guide
Claude Code’s /insights is one of the most useful built-in commands — it analyzes your last 30 days of conversation history, generating an interactive HTML report covering usage patterns, friction points, and even ready-to-paste CLAUDE.md suggestions.
The problem is, it’s a black box sealed inside the CLI. You can’t customize analysis dimensions, scope to a specific project, or adjust the time window.
Now that the source code has leaked, I got the complete 3,200-line TypeScript implementation, extracted it, redesigned the architecture, and repackaged it as two versions. This article documents the extraction approach and how to install it.
For the full story on the leak, see News: Claude Code’s Full Source Code Leaked.
What Does /insights Actually Do?
Understanding the original pipeline is essential before we can extract it. The source code reveals four phases:
Phase 1 — Lite Scan: Scans all .jsonl session files under ~/.claude/projects/, reading only filesystem metadata for quick filtering.
Phase 2 — Build SessionMeta: Extracts quantitative stats from each session — duration, tool usage counts, programming languages, token consumption, git activity, response times, even multi-clauding timestamps (when you’re running multiple Claude instances simultaneously).
Phase 3 — Facet Extraction: Uses an LLM to perform semantic analysis on each session, extracting structured JSON for goals, friction, satisfaction, and more. The original uses Opus, requiring 50-60 API calls per full run.
Phase 4 — Insights Generation: Calls the LLM in parallel to produce 6-9 insight sections, then assembles everything into an interactive HTML report at ~/.claude/usage-data/report.html.
The report includes these sections:
| Section | Content |
|---|---|
| At a Glance | What’s working, what’s blocking you, quick wins |
| Session Stats | Total sessions, messages, hours, commits — with charts |
| Work Content | Per-project session distribution and summaries |
| Friction Points | All friction points categorized and ranked, with actual conversation examples |
| CLAUDE.md Suggestions | Copy-paste-ready rules based on instructions you’ve repeated |
| Skill & Hook Suggestions | Converts repetitive multi-step operations into custom Skills or Hooks |
The Extraction Approach
Step 1 — Get the Complete Source
The leaked source on GitHub gets truncated or summarized by WebFetch. Ended up using curl to download the full insights.ts (3,200 lines), then reading it in segments.
Step 2 — Analyze Dependencies and Reusability
Not everything needs to change. After analysis:
- ~60% directly reusable — Pure logic functions:
extractToolStats,aggregateData,detectMultiClauding,generateHtmlReport, etc. - ~40% needs replacement — Internal dependencies:
queryWithModel(LLM call wrapper), session file reading, various internal utilities
Step 3 — The Key Architecture Decision: Who’s the LLM?
This is the most important step in the entire extraction. Phases 3 and 4 make heavy LLM API calls. Building a standalone script means paying for API calls yourself (50-60 Opus calls per run — not cheap).
The solution: Package as Skill + Sub-agent, letting Claude Code itself be the LLM.
| Standalone Script | Skill + Sub-agent | |
|---|---|---|
| Who’s the LLM | You call APIs yourself | Claude Code itself |
| API Key | Need separate setup | Not needed |
| Extra cost | Yes (50-60 API calls) | Zero |
Final architecture:
- Pure computation (scanning, statistics, HTML rendering) → Node.js scripts, executed via the
Bashtool - Semantic analysis (facet extraction, insight generation) → Claude Code Sub-agents handle it
Step 4 — Add Two Dimensions
The original only analyzes “all projects, last 30 days.” I added two filtering dimensions:
- Project dimension —
--project <name>with fuzzy directory name matching - Time dimension —
--days <N>to specify the window
This lets reports focus on a specific project during a specific period, instead of drowning in noise from all conversations.
Step 5 — Split Into Two Versions
Split into two versions based on use case:
| Command Version | Skill Version | |
|---|---|---|
| Install scope | Global (~/.claude/commands/) | Per-project (.claude/skills/) |
| Project dimension | Yes (cross-project) | No (auto-detects current project) |
| Time dimension | Yes | Yes |
| Usage | /insights emilwu-tw-site 7d | /insights 7d |
Installation
Both versions are packaged as Claude Code Plugins, published in a unified Plugin Marketplace.
Step 1: Add the Marketplace (once per machine)
/plugin marketplace add emilwu/emilwu-plugins
Step 2: Install your preferred version
# Command version — cross-project analysis
/plugin install claude-insights-command@emilwu-plugins
# Skill version — current project analysis
/plugin install claude-insights-skill@emilwu-plugins
Step 3: Use it
# Command version: specify project + days
/claude-insights-command:insights emilwu-tw-site 7d
# Skill version: current project, specify days
/claude-insights-skill:insights 7d
On first run, the SessionStart hook automatically runs npm install and tsc to compile TypeScript. Subsequent runs skip this step.
For the full story on packaging this into a Plugin — including Plugin structure design, verification workflow, and pitfalls — see: Practical Tips 2: Packaging Skills as Plugins for Distribution.
Why Use the Extracted Version?
The original /insights is great, but it’s a closed system. The extracted version’s value lies in:
- Project focus — Analyze just one project without noise from others
- Time control — 7 days, 14 days, 30 days — you decide
- Zero extra cost — Semantic analysis handled by Claude Code itself, no additional API calls
- Educational — See the complete implementation, understand how Anthropic designs session analysis pipelines
Perhaps the most valuable thing isn’t the tool itself, but what you learn during the extraction process — seeing how a top-tier AI team designs an analysis system, then using a Skill + Sub-agent architecture to make it zero-cost. That’s Context Engineering in practice.
Related resources:
- News: Claude Code’s Full Source Code Leaked — Full coverage of the leak
- Practical Tips 2: Packaging Skills as Plugins for Distribution — Plugin packaging workflow and pitfalls
- GitHub: emilwu-plugins — Unified Plugin Marketplace
- Claude Code usage analytics — Official docs
Support This Series
If these articles have been helpful, consider buying me a coffee