Claude Usage Checker
Launches the Claude CLI interactively (PTY) and reads the /usage output to report your Claude Code / Claude Max quota.
Prerequisites
- - Claude CLI must be installed (
npm i -g @anthropic-ai/claude-code) and logged in - If running
claude shows "Missing API key", the user must log in manually first: open a terminal, run claude, and complete the browser login flow - Requires an interactive PTY — the agent will launch a local process and read its output (quota info only)
Steps
- 1. Launch
claude with PTY - Wait for the welcome screen (poll until it appears)
- Send
/usage + Enter - Read the output (poll until usage data appears)
- Close with Escape then INLINECODE6
- Report the results
Commands
CODEBLOCK0
Notes
- - If you see "Missing API key" → tell the user to log in; browser-based login won't work headlessly
- Allow a few seconds between polls — Claude CLI starts slowly
- "Current week" = weekly reset, not daily
Output Format
Report in a table:
| Usage | Resets |
|---|
| Current session | X% used | today at HH:MM (timezone) |
| Weekly (all models) |
X% used | HH:MM (timezone) |
|
Weekly (Sonnet only) | X% used | HH:MM (timezone) |
|
Extra usage | X% used / $X of $Y spent | date (timezone) |
Always show reset times. The CLI displays them as "Resets Xpm" — convert to HH:MM format.
Claude 用量检查器
以交互方式(PTY)启动 Claude CLI,读取 /usage 输出,报告您的 Claude Code / Claude Max 配额。
前置条件
- - 必须安装 Claude CLI(npm i -g @anthropic-ai/claude-code)并已登录
- 如果运行 claude 显示缺少 API 密钥,用户必须先手动登录:打开终端,运行 claude,完成浏览器登录流程
- 需要交互式 PTY — 代理将启动本地进程并读取其输出(仅限配额信息)
步骤
- 1. 使用 PTY 启动 claude
- 等待欢迎界面(轮询直至出现)
- 发送 /usage + 回车
- 读取输出(轮询直至用量数据出现)
- 按 Escape 键,然后输入 /exit 退出
- 报告结果
命令
bash
使用 PTY 启动 claude
exec pty=true command=claude
等待并检查日志
process action=poll sessionId=XXX timeout=5000
发送 /usage
process action=send-keys sessionId=XXX literal=/usage
process action=send-keys sessionId=XXX keys=[Enter]
读取输出
process action=poll sessionId=XXX timeout=5000
退出
process action=send-keys sessionId=XXX keys=[Escape]
process action=send-keys sessionId=XXX literal=/exit
process action=send-keys sessionId=XXX keys=[Enter]
注意事项
- - 如果看到缺少 API 密钥→ 告知用户登录;基于浏览器的登录无法在无头模式下工作
- 轮询之间等待几秒 — Claude CLI 启动较慢
- 当前周 = 每周重置,而非每日重置
输出格式
以表格形式报告:
| 用量 | 重置时间 |
|---|
| 当前会话 | 已用 X% | 今天 HH:MM(时区) |
| 每周(所有模型) |
已用 X% | HH:MM(时区) |
|
每周(仅 Sonnet) | 已用 X% | HH:MM(时区) |
|
额外用量 | 已用 X% / 已花费 $X(共 $Y) | 日期(时区) |
始终显示重置时间。CLI 显示为重置 Xpm — 请转换为 HH:MM 格式。