Show HN:Claude 代码使用监控器——实时追踪器,避免使用中断
Show HN: Claude Code Usage Monitor – real-time tracker to dodge usage cut-offs

原始链接: https://github.com/Maciek-roboblog/Claude-Code-Usage-Monitor

这个命令行工具可在您的终端实时监控 Claude AI 代币的使用情况。使用 `ccusage`,它可以追踪代币消耗、燃烧率并预测代币耗尽时间。它提供可视化进度条,基于燃烧率的智能预测,并支持 Pro、Max5 和 Max20 方案,并能自动检测自定义限额。当超过限额时,会发出警告。 安装非常简单,使用方法包括设置方案、重置时间和小时区。它处理 Claude 的 5 小时滚动会话窗口并准确计算燃烧率。对于代币限额可变的用户,`--plan custom_max` 选项会根据之前的会话自动确定您的最大使用量。 如果遇到问题,请确保已安装 `ccusage` 并且您有一个活动的 Claude 会话。欢迎为错误修复、功能建议和代币限额检测改进做出贡献。它采用 MIT 许可证,基于 @ryoppippi 的 `ccusage` 构建。

Maciej-roboblog 创建了 Claude 代码使用监控器,这是一个实时跟踪 Claude API 使用情况并防止达到使用限制的工具。由于意外中断感到沮丧,Maciej 开发了一个本地追踪器,它可以流式传输提示和完成情况的使用情况,并预测何时会达到上限。该工具在本地运行,无需身份验证或服务器,并提供针对不同计划限制(专业版、Max x5、Max x20)的预设。用户可以通过 JSON 文件自定义限制。 该项目已在 GitHub 上发布,目前仍在开发中,欢迎反馈和贡献。一位用户询问了如何使用 uv 以自包含的方式安装 Python 和 Node 工具,以避免重复和脆弱性。Maciej-roboblog 对此表示赞同,并建议创建一个 GitHub issue 以便实施。此外,Maciej 计划引入一个“自动模式”,利用机器学习和 DuckDB 动态确定用户的令牌限制,以取代硬编码的解决方案。他还提到了撰写博客文章的可能性,内容是如何通过检查 `~/.claude/projects/*/*.jsonl` 的内容来发现 Claude 的使用跟踪方法。
相关文章

原文

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



  • 🔄 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

  1. Python 3.6+ installed on your system
  2. pytz Python package:
  3. ccusage CLI tool installed globally:
# 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

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

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

# 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

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

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

Press Ctrl+C to gracefully exit the monitoring tool.


📊 Understanding Claude Sessions

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

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.

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

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

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

  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

"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

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

# Start work at 9 AM daily
./ccusage_monitor.py --reset-hour 9
# 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
# Use your local timezone
./ccusage_monitor.py --timezone America/New_York
./ccusage_monitor.py --timezone Asia/Singapore
./ccusage_monitor.py --timezone Australia/Sydney

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.


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


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

联系我们 contact @ memedata.com