Track your Claude Code usage and compete on the global leaderboard! This CLI automatically monitors your token usage and posts your stats to the leaderboard after each Claude Code session.
npx claude-code-leaderboardFollow the setup prompts to authenticate with Twitter and start tracking your usage automatically.
The CLI integrates with Claude Code's hook system to automatically track your usage:
- Automatic Setup: Installs a tracking hook in your Claude Code configuration
- Usage Monitoring: After each Claude Code session ends (STOP command), your token usage is collected
- Data Submission: Usage data is automatically sent to our backend service
- Leaderboard Updates: Your stats appear on the public leaderboard at claudecount.com
- Input tokens used
- Output tokens generated
- Cache creation/read tokens
- Session timestamps
- Model used (e.g., claude-sonnet-4)
Your actual prompts and responses are never collected - only usage statistics.
Claude Code hooks are user-defined shell commands that execute automatically at specific points during Claude Code's execution lifecycle. They allow you to inject deterministic, programmatic actions directly into the agent's workflow - ensuring that key tasks always occur exactly when intended, rather than relying on the AI to remember to do them.
Claude Code supports hooks at different lifecycle events:
- Start: When a Claude Code session begins
- Stop: When a Claude Code session ends
- PreTool: Before any tool or command is executed
- PostTool: After a tool or command completes
This leaderboard CLI specifically uses a Stop hook, which means:
- Every time you finish a Claude Code session (when Claude Code exits)
- The hook automatically executes with your user permissions
- No confirmation is required - it runs silently in the background
- The hook scans your Claude Code usage data and sends statistics to our backend
This provides reliable, automatic tracking without you having to remember to manually submit your usage.
When you run the setup, the following files are created on your system:
- Location:
~/.claude/count_tokens.js - Purpose: The actual script that collects and sends your usage data
- Permissions: Executes with your user permissions
- When it runs: Automatically after each Claude Code session ends
~/.claude/settings.json: Updated to register the Stop hook~/.claude/leaderboard.json: Stores your Twitter authentication and API settings
The count_tokens.js script:
- Scans Claude Code project directories for usage log files (
.jsonlfiles) - Extracts token usage statistics from the most recent session
- Sends only the statistics (not your prompts/responses) to our backend
- Updates your position on the leaderboard
# Setup or re-authenticate
npx claude-code-leaderboard
# Reset/uninstall (with optional account deletion)
npx claude-code-leaderboard reset
# View help
npx claude-code-leaderboard --help- One-command setup: Complete setup with a single command
- Automatic tracking: Seamless integration with Claude Code hooks
- Twitter authentication: Secure OAuth 1.0a authentication
- Privacy-focused: Only usage statistics are collected
- Cross-platform: Works on macOS, Linux, and Windows
- View stats online: Visit claudecount.com to see your stats and the leaderboard
- Node.js 16.0.0 or higher
- Claude Code CLI installed and configured
- Twitter account for authentication
The CLI automatically manages your configuration in ~/.claude/leaderboard.json including:
- Twitter authentication tokens
- API endpoint settings
- User preferences
- Usage statistics only: Token counts, timestamps, model names
- No content: Your actual prompts and Claude's responses are never transmitted
- Linked to Twitter: All data is associated with your Twitter handle for leaderboard display
- User permissions: The hook runs with your full user permissions
- Automatic execution: No confirmation required when the hook runs
- Trusted source: Only install hooks from sources you trust
- OAuth authentication: Uses secure OAuth 1.0a for Twitter authentication
- Hooks execute automatically after each Claude Code session
- The script only reads Claude Code's own usage log files
- You can uninstall at any time by running the reset command
- All source code is available for inspection in this repository
The reset command provides a comprehensive uninstall process:
npx claude-code-leaderboard resetThis command will:
- Remove all local CLAUDE COUNT files and settings
- Unregister the hook from Claude Code
- Optionally: Delete your account from the leaderboard database
If you're authenticated, the reset command will offer to permanently delete your account from the leaderboard. This includes:
- Your user account and all authentication data
- Complete token usage history
- Your position on the leaderboard
# Install dependencies
npm install
# Test the CLI locally
node bin/cli.js --helpFor issues or questions:
- Check that Claude Code is properly installed
- Verify your Twitter authentication
- Ensure Node.js 16+ is installed
- Check network connectivity
This is an open source project! Contributions are welcome.