Skip to content

prabuddha34/Claude-Code-Usage-Monitor

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ Claude Code Usage Monitor

Python Version License: MIT PRs Welcome

A beautiful real-time terminal monitoring tool for Claude AI token usage. Track your token consumption, burn rate, and get predictions about when you'll run out of tokens.

Claude Token Monitor Screenshot


๐Ÿ“‘ Table of Contents


โœจ Features

  • ๐Ÿ”„ Real-time monitoring - Updates every 3 seconds with smooth refresh
  • ๐Ÿ“Š Visual progress bars - Beautiful color-coded token and time progress bars
  • ๐Ÿ”ฎ Smart predictions - Calculates when tokens will run out based on current burn rate
  • ๐Ÿค– Auto-detection - Automatically switches to custom max when Pro limit is exceeded
  • ๐Ÿ“‹ Multiple plan support - Works with Pro, Max5, Max20, and auto-detect plans
  • โš ๏ธ Warning system - Alerts when tokens exceed limits or will deplete before session reset
  • ๐Ÿ’ผ Professional UI - Clean, colorful terminal interface with emojis
  • โœจ No screen flicker - Smooth updates without clearing the entire screen
  • โฐ Customizable reset times - Set your own token reset schedule

๐Ÿš€ Installation

Prerequisites

  1. Python 3.6+ installed on your system
  2. pytz Python package:
    pip install pytz
  3. ccusage CLI tool installed globally:
    npm install -g ccusage

Quick Setup

# Clone the repository
git clone https://github.com/Maciek-roboblog/Claude-Code-Usage-Monitor.git
cd Claude-Code-Usage-Monitor

# Make the script executable
chmod +x ccusage_monitor.py

# Run the monitor
./ccusage_monitor.py

๐Ÿ“– Usage

Basic Usage

Run with default settings (Pro plan - 7,000 tokens):

./ccusage_monitor.py

๐Ÿ’ก Smart Detection: When tokens exceed the Pro limit, the monitor automatically switches to custom_max mode and displays a notification.

Specify Your Plan

# Pro plan (~7,000 tokens) - Default
./ccusage_monitor.py --plan pro

# Max5 plan (~35,000 tokens)
./ccusage_monitor.py --plan max5

# Max20 plan (~140,000 tokens)
./ccusage_monitor.py --plan max20

# Auto-detect from highest previous session
./ccusage_monitor.py --plan custom_max

Custom Reset Times

Set a custom daily reset hour (0-23):

# Reset at 3 AM
./ccusage_monitor.py --reset-hour 3

# Reset at 10 PM
./ccusage_monitor.py --reset-hour 22

Timezone Configuration

The default timezone is Europe/Warsaw. You can change it to any valid timezone:

# Use US Eastern Time
./ccusage_monitor.py --timezone US/Eastern

# Use Tokyo time
./ccusage_monitor.py --timezone Asia/Tokyo

# Use UTC
./ccusage_monitor.py --timezone UTC

# Use London time
./ccusage_monitor.py --timezone Europe/London

Exit the Monitor

Press Ctrl+C to gracefully exit the monitoring tool.


๐Ÿ“Š Understanding Claude Sessions

How Sessions Work

Claude Code operates on a 5-hour rolling session window system:

  • Sessions start with your first message to Claude
  • Sessions last for exactly 5 hours from that first message
  • Token limits apply within each 5-hour session window
  • Multiple sessions can be active simultaneously

Token Reset Schedule

Default reset times (in your configured timezone, default: Europe/Warsaw):

  • 04:00, 09:00, 14:00, 18:00, 23:00

โš ๏ธ Important: These are reference times. Your actual token refresh happens 5 hours after YOUR first message in each session.

๐ŸŒ Timezone Note: The default timezone is Europe/Warsaw. You can change it using the --timezone parameter with any valid timezone name.

Burn Rate Calculation

The monitor calculates burn rate based on all sessions from the last hour:

  • Analyzes token consumption across overlapping sessions
  • Provides accurate recent usage patterns
  • Updates predictions in real-time

๐Ÿ› ๏ธ Token Limits by Plan

Plan Token Limit Best For
Pro ~7,000 Light usage, testing (default)
Max5 ~35,000 Regular development
Max20 ~140,000 Heavy usage, large projects
Custom Max Auto-detect Automatically uses highest from previous sessions

๐Ÿ”ง Advanced Features

Auto-Detection Mode

When using --plan custom_max, the monitor:

  1. ๐Ÿ” Scans all previous session blocks
  2. ๐Ÿ“ˆ Finds the highest token count used
  3. โš™๏ธ Sets that as your limit automatically
  4. โœ… Perfect for users with varying token limits

Smart Pro Plan Switching

When using the default Pro plan:

  • ๐Ÿ” Monitor detects when usage exceeds 7,000 tokens
  • ๐Ÿ”„ Automatically switches to custom_max mode
  • ๐Ÿ“ข Shows notification of the switch
  • โ–ถ๏ธ Continues monitoring with the new limit

โšก Best Practices

  1. ๐Ÿš€ Start Early: Begin monitoring when you start a new session
  2. ๐Ÿ‘€ Watch Velocity: Monitor burn rate indicators to manage usage
  3. ๐Ÿ“… Plan Ahead: If tokens will deplete before reset, adjust your usage
  4. โฐ Custom Schedule: Set --reset-hour to match your typical work schedule
  5. ๐Ÿค– Use Auto-Detect: Let the monitor figure out your limits with --plan custom_max

๐Ÿ› Troubleshooting

"Failed to get usage data"

  • Ensure ccusage is installed: npm install -g ccusage
  • Check if you have an active Claude session
  • Verify ccusage works: ccusage blocks --json

"No active session found"

  • Start a new Claude Code session
  • The monitor only works when there's an active session

Cursor remains hidden after exit

printf '\033[?25h'

Display issues or overlapping text

  • Ensure your terminal window is at least 80 characters wide
  • Try resizing your terminal and restarting the monitor

๐Ÿš€ Example Usage Scenarios

Morning Developer

# Start work at 9 AM daily
./ccusage_monitor.py --reset-hour 9

Night Owl Coder

# Often work past midnight
./ccusage_monitor.py --reset-hour 0

Heavy User with Variable Limits

# Let the monitor figure out your limits
./ccusage_monitor.py --plan custom_max

Quick Check with Default Settings

# Just run it!
./ccusage_monitor.py

International User

# Use your local timezone
./ccusage_monitor.py --timezone America/New_York
./ccusage_monitor.py --timezone Asia/Singapore
./ccusage_monitor.py --timezone Australia/Sydney

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  • ๐Ÿ› Report bugs or issues
  • ๐Ÿ’ก Suggest new features
  • ๐Ÿ”ง Submit pull requests
  • ๐Ÿ“š Improve documentation

๐Ÿ“Š Help Us Improve Token Limit Detection

We're collecting data about actual token limits to improve the auto-detection feature. If you're using Claude and your tokens exceeded the standard limits, please share your experience in Issue #1:

What to share:

  • Your subscription type (Pro, Teams, Enterprise)
  • The maximum tokens you reached (custom_max value)
  • When the limit was exceeded
  • Any patterns you've noticed

This data helps us better understand token allocation across different subscription tiers and improve the monitoring tool for everyone.


๐Ÿ“ License

MIT License - feel free to use and modify as needed.


๐Ÿ™ Acknowledgments

This tool builds upon the excellent ccusage by @ryoppippi, adding a real-time monitoring interface with visual progress bars, burn rate calculations, and predictive analytics.

  • ๐Ÿ—๏ธ Built for monitoring Claude Code token usage
  • ๐Ÿ”ง Uses ccusage for data retrieval
  • ๐Ÿ’ญ Inspired by the need for better token usage visibility

โญ Star this repo if you find it useful! โญ

Report Bug โ€ข Request Feature โ€ข Contribute

About

Real-time Claude Code usage monitor with predictions and warnings

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%