Breaking the 200-Session Ceiling: Reverse-Engineering Claude Code’s Analytics
Hook
Claude Code’s built-in /insights command caps at 200 sessions and 500-token summaries. For heavy users with extensive usage history, that’s like analyzing a book by reading only the first chapter.
Context
If you’re using Claude Code as your primary AI assistant, your ~/.claude/projects/ directory is accumulating session transcripts—stored as JSONL files containing your prompts, Claude’s responses, tool usage, and outcomes. Claude Code’s built-in /insights command surfaces patterns from this data, but it imposes strict limits: 200 sessions maximum, 500-token summaries per session, and only 50 extracted facets sent to report generation.
For developers working across multiple machines or accumulating extensive session history, these constraints mean you’re only seeing a fraction of your usage patterns. The dmaynor/claude_enhanced_insights repository addresses this by reimplementing the insights pipeline with dramatically higher limits: 9,999 sessions, 2,048-token summaries, 200 facets for report generation, and support for merging sessions from multiple workstations into unified analytics.
Technical Insight
The architecture is straightforward but clever: instead of calling an API endpoint, it reads Claude Code’s internal storage directly. Session transcripts live in ~/.claude/projects/*.jsonl, with each line representing a conversation turn. Authentication uses the existing OAuth token from ~/.claude/.credentials.json, eliminating separate API key management. The pipeline has four stages: extraction, facet analysis, aggregation, and rendering.
Extraction walks the projects directory and parses JSONL files to compute local metrics—which tools were invoked (bash, edit_file, search_files), programming languages detected from file extensions, token counts, git operations, and timestamps. This happens entirely locally with no API calls. The code then truncates messages aggressively: 2,000 characters for user prompts, 1,000 for assistant responses, compared to the built-in insights’ 500 and 300 respectively.
Facet extraction is where costs accumulate. For each session, the tool sends the truncated transcript to Claude with a structured prompt requesting high-level categorization: primary goal (debugging, feature development, refactoring, learning), outcome (success, partial, failure), user satisfaction (1-5), helpfulness (1-5), friction points, and workflow effectiveness. Here’s the caching strategy that makes repeated runs practical:
# Facets are cached per-session in ~/.claude/usage-data/facets/
# Cache key is hash of project path + session timestamp
facet_cache_path = os.path.expanduser(
f"~/.claude/usage-data/facets/{project_hash}_{session_id}.json"
)
if os.path.exists(facet_cache_path):
with open(facet_cache_path) as f:
return json.load(f)
# Otherwise call Claude API with prompt caching enabled
response = client.messages.create(
model="claude-opus-4-6",
max_tokens=8192, # Built-in insights uses 4096
messages=[...],
system=[{
"type": "text",
"text": facet_extraction_prompt,
"cache_control": {"type": "ephemeral"}
}]
)
This per-session caching means the first run is expensive (one API call per session), but subsequent runs only analyze new sessions. Anthropic’s prompt caching reduces costs further since the facet extraction prompt stays constant across sessions.
Aggregation collects facets from all sessions and computes distributions: how many debugging vs. feature development sessions, which tools saw the most errors, time-of-day activity patterns, satisfaction trends over time. The JSON output includes the first 200 characters of each user prompt alongside metadata—useful for tracing patterns back to specific conversations, but a potential information leak.
Report generation is parallelized. Rather than sequentially generating eight sections (At a Glance, What You Work On, How You Use Claude Code, Impressive Things You Did, Where Things Go Wrong, Charts, Suggestions, On the Horizon), the tool spawns eight concurrent Claude API calls with different prompts. Each receives the aggregated facet data (capped at 200 facets vs. the built-in insights’ 50) and generates its section independently. The model can use up to 16,384 tokens per section instead of 8,192:
# Example CLI usage showing the raised limits in action
python3 enhanced_insights.py \
--model claude-opus-4-6 \
--project "*backend-api*" \
--after 2026-01-01
# Output:
# Processing 847 sessions (built-in insights would cap at 200)
# Extracted 847 facets (would send 50 to report generation)
# Generated report with 2048-token summaries (vs 500)
The multi-machine workflow is elegant. The insights_sync.sh script uses SSH and rsync to pull ~/.claude/projects/*.jsonl files from remote hosts into a local staging directory. Sessions are deduplicated by hashing project paths—if you work on /home/user/code/myapp on both your laptop and desktop, those sessions merge automatically. This means you can generate a single report spanning all your work environments without manual consolidation. The script respects SSH key authentication and supports dry-run mode to preview what would transfer.
Gotcha
This tool is fundamentally fragile because it reverse-engineers a commercial product’s internal storage format. Anthropic makes no guarantees about ~/.claude/projects/*.jsonl structure or .credentials.json format—they could change field names, encryption schemes, or file layouts in any update. When that happens, enhanced_insights.py will break until someone updates the parsing logic. You’re trading stability for capability.
The security posture is also worth scrutinizing. While output files are written with 0600 permissions (owner-only), the reports and cache files embed the first 200 characters of every user prompt. If you’ve discussed proprietary algorithms, API keys, or sensitive business logic in Claude Code sessions, snippets of those conversations now live in plaintext JSON and HTML files in your home directory. The README acknowledges this but doesn’t offer filtering options—it’s all-or-nothing. For teams subject to data retention policies or working with customer data, this could be disqualifying. Additionally, the multi-machine sync pulls session data over SSH, so ensure your remote hosts are trusted and your SSH keys are secured.
Verdict
Use if you’re a power user with hundreds of Claude Code sessions accumulated across multiple machines, you want detailed usage analytics, or you want to analyze your usage patterns with AI assistants and need complete historical data. The ability to process 9,999 sessions with 2048-token summaries is genuinely valuable for understanding long-term trends that the built-in insights obscure. The multi-machine sync is a killer feature if you regularly switch between a laptop and workstation. Skip if you’re casually using Claude Code (the built-in /insights is sufficient for under 200 sessions), you handle sensitive data in prompts and can’t risk 200-character snippets leaking into reports, or you need tooling with stability guarantees (Claude Code updates could potentially break this). Also skip if you’re uncomfortable with reverse-engineering—you’re depending on implementation details Anthropic has not documented as a stable API.