Overview
Claude Code passes a JSON object via stdin to statusline scripts. This object contains session metadata, cost information, token usage, and model details. cc-statusline reads this JSON to display directory, model, costs, context usage, and other information.JSON Structure
Complete Example
Fromtester.ts:51-88, here’s the actual mock data structure used for testing:
Field Reference
Top-Level Fields
Unique identifier for the current Claude Code session.Example:
"test-session-123"Path to the JSONL file containing the conversation transcript.Example:
"/home/user/.claude/conversations/test.jsonl"Current working directory for the Claude Code session.Example:
"/home/user/projects/my-project"Used by: Directory feature (with ~ abbreviation)Claude Code version number.Example:
"1.0.80"Used by: Claude Code version displayworkspace Object
Current directory within the workspace.Example:
"/home/user/projects/my-project"Root directory of the project workspace.Example:
"/home/user/projects/my-project"model Object
Full model identifier including version date.Example:
"claude-opus-4-1-20250805"Human-readable model name.Example:
"Opus 4.1"Used by: Model feature displayModel version date in YYYYMMDD format.Example:
"20250805"output_style Object
Current output style setting in Claude Code.Example:
"default", "compact", "verbose"Used by: Output style feature (if enabled)cost Object
Total cost in US dollars for the current session.Example:
0.42Used by: Cost tracking feature (usage.ts:43)Total session duration in milliseconds.Example:
180000 (3 minutes)Used by: Burn rate calculation (usage.ts:47-49)Formula: burn_rate = (cost_usd * 3600000) / duration_msTotal time spent in API calls in milliseconds.Example:
2300Total lines of code added during the session.Example:
156Total lines of code removed during the session.Example:
23context_window Object
Total input tokens consumed in the session.Example:
15234Used by: Token statistics (usage.ts:52-53)Total output tokens generated in the session.Example:
4521Used by: Token statistics (usage.ts:52-53)Maximum context window size for the current model.Example:
200000Used by: Context percentage calculationDetailed breakdown of current token usage including cache tokens.
Input tokens in the current request.Example:
8500Output tokens in the current response.Example:
1200Tokens used for cache creation.Example:
5000Tokens read from cache.Example:
2000Parsing Methods
With jq (Recommended)
Fromusage.ts:42-64, cc-statusline uses jq for reliable JSON parsing:
- Robust and reliable
- Handles edge cases (nulls, missing fields)
- Supports complex queries with fallbacks (
//operator) - Fast execution (<10ms)
Bash Fallback (No jq)
Fromusage.ts:66-88, if jq is unavailable:
- Less reliable with malformed JSON
- No handling of null values
- Harder to maintain
- Slower than jq (grep + sed pipeline)
Usage in Scripts
Reading stdin
All statusline scripts should read JSON from stdin:Calculations
Burn Rate (fromusage.ts:47-49):
usage.ts:59-64):
Testing with Mock Data
cc-statusline includes test utilities for mock data generation:Generate Test Input
Fromtester.ts:51-88:
Test Your Statusline
Error Handling
Missing Fields
Always check for empty/null values:Invalid JSON
Handle parsing errors gracefully:Zero Values
Distinguish between “no data” and “zero”:Related Documentation
- ccusage Integration - External ccusage data format
- Manual Setup - Configuring statusline to receive this JSON
- Installation - Quick setup guide