A command-line tool to quickly check your Claude Code usage statistics.
This Python script launches Claude Code in a PTY, sends the /usage command, captures the output, and displays your usage statistics in a clean format. It supports both human-readable text output and JSON format for scripting.
- Python 3.6+
- pexpect library
- Claude Code CLI installed and authenticated
pip install pexpect-
Clone this repository:
git clone https://github.com/yourusername/claude-usage.git cd claude-usage -
Make the script executable:
chmod +x claude-usage
-
Optionally, add to your PATH or create a symlink:
ln -s $(pwd)/claude-usage /usr/local/bin/claude-usage
./claude-usageOutput:
Current session
42% used
Resets 7:59pm (America/Los_Angeles)
Current week (all models)
15% used
Resets Dec 1 at 11:59am (America/Los_Angeles)
Current week (Sonnet only)
8% used
Resets Dec 1 at 11:59am (America/Los_Angeles)
./claude-usage --jsonOutput:
{
"timestamp": "2024-11-29T14:30:00.123456",
"session": {
"percent_used": 42,
"resets_at": "2024-11-29T19:59:00",
"timezone": "America/Los_Angeles"
},
"week_all_models": {
"percent_used": 15,
"resets_at": "2024-12-01T11:59:00",
"timezone": "America/Los_Angeles"
},
"week_sonnet_only": {
"percent_used": 8,
"resets_at": "2024-12-01T11:59:00",
"timezone": "America/Los_Angeles"
}
}./claude-usage --debugThis prints detailed debug information to stderr while running.
./claude-usage --json --debug- Spawns Claude Code in a pseudo-terminal (PTY) using pexpect
- Waits for the CLI to initialize
- Sends the
/usagecommand - Waits for the usage screen to load
- Captures and parses the screen output
- Cleans up ANSI escape sequences
- Extracts usage percentages and reset times
- Outputs in the requested format (text or JSON)
- Quick status check: See your usage at a glance
- Scripting: Use
--jsonoutput to integrate with other tools - Monitoring: Schedule periodic checks to track usage patterns
- Automation: Trigger alerts when usage exceeds thresholds
MIT License