Open
Conversation
Add two scripts for analyzing Claude Code session traces: - analyze-traces.sh: queries Langfuse's ClickHouse directly for instant full-dataset analytics (self-hosted only, zero deps beyond curl) - analyze-traces-sdk.py: uses the official Langfuse Python SDK with REST API pagination (works with Cloud and self-hosted) Both produce five analyses: tool usage distribution, session turn distribution, productivity by session length (the efficiency cliff), and read-before-edit behavioral patterns. Includes docs/trace-analysis.md with methodology, ClickHouse schema reference, interpretation guide, and a query cookbook for custom analytics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scripts/analyze-traces.sh— ClickHouse-direct shell script for instant full-dataset analytics on self-hosted Langfuse. Zero deps beyondcurland Docker. Supports--jsonand--tagflags.scripts/analyze-traces-sdk.py— Official Langfuse SDK alternative using REST API pagination. Works with both Cloud and self-hosted deployments.docs/trace-analysis.md— Full methodology guide with ClickHouse schema reference, query cookbook, and interpretation guide for five analyses.Why two scripts?
The Langfuse Metrics API v2 (which supports server-side aggregations) is Cloud-only. On self-hosted, calling it returns
"v2 APIs are currently in beta and only available on Langfuse Cloud". The REST API v1 paginates at 100 items/page with no aggregation support.For self-hosted deployments with thousands of traces, querying ClickHouse directly (port 8124) is the only practical path for full-dataset analytics.
The five analyses
Test plan
./scripts/analyze-traces.shagainst a running Langfuse stack--jsonoutput parses correctly withjq--tagfiltering workspython3 scripts/analyze-traces-sdk.pywith valid credentialsdocs/trace-analysis.mdcustom query examples execute correctly🤖 Generated with Claude Code