From session-analytics
Analyze current Claude Code session token usage via Splunk. Shows per-model, per-tool, and subagent token breakdown with cache efficiency metrics.
npx claudepluginhub jacobpevans/claude-code-plugins --plugin session-analyticsThis skill uses the workspace's default tool permissions.
Query Splunk for detailed token usage analytics of the current Claude Code session.
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Guides building MCP servers enabling LLMs to interact with external services via tools. Covers best practices, TypeScript/Node (MCP SDK), Python (FastMCP).
Generates original PNG/PDF visual art via design philosophy manifestos for posters, graphics, and static designs on user request.
Query Splunk for detailed token usage analytics of the current Claude Code session.
The Splunk MCP server must be configured in Claude Code. This is managed by nix-darwin:
splunk MCP server defined in programs.claude.mcpServersSPLUNK_MCP_ENDPOINT, SPLUNK_MCP_TOKEN)NODE_TLS_REJECT_UNAUTHORIZED=0 in the MCP server envVerify: mcp__splunk__splunk_get_info should return the Splunk version.
/token-breakdown [session-id]
Determine the current session ID and validate it has a useful name.
Step 1a — Find session ID:
If no session-id argument was provided, find the current session:
# Compute encoded project path (slashes become hyphens)
encoded_path=$(echo "$PWD" | sed 's|^/|-|; s|/|-|g')
# Find the most recently modified JSONL session file
session_file=$(ls -t "$HOME/.claude/projects/${encoded_path}/"*.jsonl 2>/dev/null | head -1)
# Validate a session file was found
if [ -z "$session_file" ]; then
echo "No active session found for current project directory: $PWD"
exit 1
fi
# Extract session ID from filename
session_id=$(basename "$session_file" .jsonl)
Step 1b — Read session metadata:
Read line 1 of the session file to extract the slug and version:
head -1 "$session_file"
Extract slug, version, and sessionId from the JSON.
Step 1c — Check session name quality:
If the slug matches the auto-generated pattern (three hyphenated words like glistening-gliding-cook):
{slug}."/rename to give it a descriptive name."Run all four queries in parallel using the Splunk MCP server tools.
MCP tool call pattern:
Each query uses mcp__splunk__splunk_run_query with the SPL query text and time range:
mcp__splunk__splunk_run_query({
"search_query": "<SPL query>",
"earliest_time": "-7d",
"latest_time": "now"
})
The MCP server handles authentication, TLS, and connection management. Results are returned as structured JSON — no manual parsing of newline-delimited export format needed.
search index=claude sourcetype="claude:code:session" sessionId="{session_id}" type="assistant"
| spath path=message.usage.input_tokens output=input_tokens
| spath path=message.usage.output_tokens output=output_tokens
| spath path=message.usage.cache_read_input_tokens output=cache_read
| spath path=message.usage.cache_creation_input_tokens output=cache_creation
| spath path=message.model output=model
| stats
sum(input_tokens) as input,
sum(output_tokens) as output,
sum(cache_read) as cache_read,
sum(cache_creation) as cache_write,
count as api_calls
by model
| eval total=input+output+cache_read+cache_write
| eval cache_pct=if((cache_read+input)>0, round(cache_read/(cache_read+input)*100, 1), 0.0)
| sort -total
| addcoltotals labelfield=model label="TOTAL"
search index=claude sourcetype="claude:code:session" sessionId="{session_id}" type="assistant"
| spath path=message.content{} output=content_items
| spath path=message.usage.output_tokens output=output_tokens
| eval tool_count=mvcount(mvfilter(match(content_items, "\"type\":\s*\"tool_use\"")))
| eval output_per_call=if(tool_count>0, output_tokens/tool_count, 0)
| mvexpand content_items
| spath input=content_items path=type output=content_type
| spath input=content_items path=name output=tool_name
| where content_type="tool_use"
| stats count as calls, sum(output_per_call) as output_tokens by tool_name
| sort -calls
search index=claude sourcetype="claude:code:subagent" sessionId="{session_id}" type="assistant"
| spath path=message.usage.input_tokens output=input_tokens
| spath path=message.usage.output_tokens output=output_tokens
| spath path=message.model output=model
| spath path=slug output=agent_slug
| stats
sum(input_tokens) as input,
sum(output_tokens) as output,
count as api_calls
by model, agent_slug
| eval total=input+output
| sort -total
search index=claude sourcetype="claude:code:session" sessionId="{session_id}" type="assistant"
| spath path=message.usage.input_tokens output=input_tokens
| spath path=message.usage.output_tokens output=output_tokens
| spath path=message.model output=model
| eval total=input_tokens+output_tokens
| bin _time span=5m
| stats sum(total) as tokens by _time, model
| sort _time
The MCP tool returns results as structured JSON directly — no newline-delimited parsing needed. Extract the result rows from each query response and display as formatted markdown tables:
## Session Token Breakdown
**Session:** {slug} (`{session_id}`)
**Period:** {first_timestamp} → {last_timestamp}
**Claude Code:** v{version}
### Model Usage
| Model | Input | Output | Cache Read | Cache Write | Total | Cache % | API Calls |
|-------|------:|-------:|-----------:|------------:|------:|--------:|----------:|
| {model} | {n} | {n} | {n} | {n} | {n} | {pct}% | {n} |
| **TOTAL** | ... | ... | ... | ... | ... | ... | ... |
### Tool Usage (by call frequency)
| Tool | Calls | Output Tokens |
|------|------:|--------------:|
| {tool} | {n} | {n} |
### Subagent Usage
| Agent | Model | Input | Output | Total | API Calls |
|-------|-------|------:|-------:|------:|----------:|
| {slug} | {model} | {n} | {n} | {n} | {n} |
### Token Burn Rate (5-min buckets)
| Time | Model | Tokens |
|------|-------|-------:|
| {time} | {model} | {n} |
Format all token counts with thousand separators for readability (e.g., 37,064).
After displaying raw data, provide a brief analysis:
Keep analysis to 3-5 bullet points max. Data speaks for itself.
| Error | Resolution |
|---|---|
| MCP tool not available | "Splunk MCP server not configured. Check nix-darwin mcpServers." |
| Auth failure | "Splunk MCP auth failed. Check SPLUNK_MCP_TOKEN in Doppler." |
| Connection refused | "Cannot reach Splunk. Check VPN/network." |
| No results | "No telemetry for session {id}. Data may not have been ingested yet." |
| Subagent query empty | Skip subagent section — not all sessions use subagents |
usage object — they are exact, not estimatesstats aggregation so results are small summary rows — well within limitsThis is a standalone analytics skill. It is useful alongside any development workflow skill that involves active Claude Code sessions.