A statusline hook for Claude Code that displays usage costs and session information.
brew tap safx/tap
brew install ccr
# Build release binary
cargo build --release
# Copy to your bin directory
cp target/release/ccr ~/bin/
Add to ~/.claude/settings.json
:
{
"statusLine": {
"type": "command",
"command": "ccr"
}
}
Note: If you installed via Homebrew, ccr
will be in your PATH. If you built from source and installed to ~/bin/
, you may need to use the full path $HOME/bin/ccr
.
The statusline shows:
- Current session cost
- Hourly burn rate
- Remaining time at current rate
- Context usage percentage
- Active session blocks
- Code changes (lines added/removed)
- Current directory
- Git branch (when in a git repository)
- Model name
- Output style (when not default)
Example output:
ccr main π€ Opus 4.1 [Learning] β° 1h 18m left π° $63.87 today, $11.58 session, $62.35 block π₯ $21.13/hr βοΈ 70% (108,887 / 155,000) βοΈ +23 -17
ccr reads Claude Code usage data from ~/.config/claude_code/projects/**/*.jsonl
files and:
- Parses JSONL entries containing API usage information
- Deduplicates entries using message_id:request_id pairs
- Groups activity into 5-hour session blocks
- Calculates costs based on token usage and model pricing
- Outputs formatted statusline string to stdout
Claude Code sends JSON via stdin:
{
"session_id": "3680e2cb-6c42-4c66-8545-973e66227c1d",
"cwd": "/Users/someone/src/mydev/ccr",
"transcript_path": "/Users/someone/.claude/projects/-Users-someone-src-mydev-ccr/3680e2cb-6c42-4c66-8545-973e66227c1d.jsonl",
"model": {
"id": "claude-opus-4-1-20250805",
"display_name": "Opus 4.1"
},
"workspace": {
"current_dir": "/Users/someone/src/mydev/ccr",
"project_dir": "/Users/someone/src/mydev/ccr"
},
"version": "1.0.85",
"output_style": {
"name": "Standard"
},
"cost": {
"total_cost_usd": 5.14,
"total_duration_ms": 1234567,
"total_api_duration_ms": 456789,
"total_lines_added": 23,
"total_lines_removed": 17
}
}
Two binaries are included for performance analysis:
# Basic profiling
./target/release/profile
# Detailed breakdown
./target/release/profile_deep
src/
βββ lib.rs # Library exports
βββ constants.rs # Shared constants
βββ error.rs # Error types and handling
βββ types/ # Data structures and domain logic
β βββ mod.rs # Module exports
β βββ ids.rs # ID types (SessionId, MessageId, etc.)
β βββ input.rs # Input data structures
β βββ pricing.rs # Pricing models and calculations
β βββ session.rs # Session blocks and snapshots
β βββ usage.rs # Usage entry structures
β βββ burn_rate.rs # Burn rate calculation (NewType)
β βββ context_tokens.rs # Context token handling (NewType)
β βββ cost.rs # Cost calculation and formatting (NewType)
β βββ remaining_time.rs # Remaining time calculation (NewType)
βββ utils/ # Utility functions
β βββ mod.rs # Module exports
β βββ data_loader.rs # Parallel JSONL file loading
β βββ transcript_loader.rs # Transcript file parsing
β βββ git.rs # Git branch detection
β βββ paths.rs # Claude Code path discovery
βββ bin/
βββ ccr.rs # Main statusline hook
βββ filter_stats.rs # Statistics filtering tool
βββ profile.rs # Performance profiling
βββ profile_deep.rs # Detailed profiling
βββ profile_loader.rs # Data loader profiling
βββ profile_micro.rs # Micro-benchmarking tool
βββ bench_sessionid.rs # SessionId benchmarking
# Development
cargo build
# Release (with optimizations)
cargo build --release
# Run tests
cargo test
# Run with cargo-nextest (if installed)
cargo nextest run
# Run all tests
cargo test
# Run with cargo-nextest (recommended)
cargo nextest run
# Test with sample input
echo '{"session_id":"test","cwd":"/tmp","transcript_path":"/dev/null","model":{"display_name":"claude-3-5-sonnet-20241022","max_output_tokens":8192}}' | ./target/release/ccr
- Started with ccusage by ryoppippi
- Converted ccusage to
other_langage/ccr_deno.ts
(standalone Deno TypeScript version) - Developed this Rust version based on ccr_deno.ts
- Refactored to use NewType pattern and clean architecture principles
The core algorithms - session block identification, cost calculation, and deduplication logic - originate from the ccusage implementation.
This implementation is heavily based on ccusage by ryoppippi. I'm grateful for the well-designed original implementation and for making it open source. The clear architecture and algorithms in ccusage made this Rust port possible. Thank you!