npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cc-third-party-usage

v1.1.4

Published

AI API Usage Monitor - Track Kimi and GLM API usage with automatic configuration detection

Downloads

1,138

Readme

CC Third Party Usage Monitor

English | 中文

在 Claude Code 状态栏中监控第三方 AI 模型(Kimi / GLM)API 用量的 CLI 工具

npm version CI License: MIT

demo

✨ 特性

  • 多服务商支持 — 同时支持 Kimi(月之暗面)和 GLM(智谱 AI)API 用量监控
  • 自动配置 — 自动从环境变量或本地代理检测 API 凭据,零配置即可使用
  • 即时响应 — 同步读取缓存,30ms 内输出结果;API 请求在后台独立进程异步完成
  • 灵活输出 — 支持默认精简格式、JSON、自定义模板等多种输出方式

📦 安装与使用

全局安装(推荐)

为什么不建议使用 npx/bunx? npx/bunx 每次调用都需要 1-2 秒进行包解析和锁文件管理。对于要求快速响应的工具(如带有执行超时的状态栏集成),这一开销会导致超时问题。全局安装可彻底消除此开销。

# 使用 npm
npm install -g cc-third-party-usage

# 使用 Bun(更快)
bun install -g cc-third-party-usage

# 安装后即可在任何地方运行(30ms 响应)
cc-third-party-usage

一次性使用(npx/bunx)

⚠️ 不推荐通过 npx/bunx 运行。 每次调用额外增加 1-2 秒开销,请使用全局安装。

# 使用 npx
npx cc-third-party-usage

# 使用 bunx(稍快)
bunx cc-third-party-usage

# 附带参数
npx cc-third-party-usage --json

从源码运行

git clone https://github.com/abrahamgreyson/cc-third-party-usage.git
cd cc-third-party-usage

# 最快方式(Node 约 30ms,Bun 约 18ms)
node dist/usage.js
bun dist/usage.js

⚡ 性能

| 方式 | 响应时间 | 说明 | |------|---------|------| | node dist/usage.js | ~30ms | 直接执行文件,最快 | | bun dist/usage.js | ~18ms | Bun 运行时,更快 | | cc-third-party-usage(全局安装) | ~900ms | Node 启动 + SQLite 初始化 | | bunx cc-third-party-usage | ~1100ms | 每次都需要包解析 | | npx cc-third-party-usage | ~2500ms | 最慢,npm 解析开销最大 |

本工具采用即时响应架构:同步读取缓存数据后立即输出退出,同时启动独立的守护进程在后台获取最新 API 数据供下次调用使用。脚本本身执行始终在 30ms 以内——上表中的时间差异完全来自运行时的启动开销。

🚀 集成

Claude Code 原生状态栏

在 Claude Code 设置文件(~/.claude/settings.json)中添加:

{
  "statusLine": {
    "command": "cc-third-party-usage"
  }
}

如需最快响应,可先克隆并构建,然后使用绝对路径:

git clone https://github.com/abrahamgreyson/cc-third-party-usage.git
cd cc-third-party-usage && bun run build
{
  "statusLine": {
    "command": "node /path/to/cc-third-party-usage/dist/usage.js"
  }
}

ccstatusline 集成

ccstatusline 中作为 Custom Command 组件使用:

  1. 添加一个 Custom Command 组件
  2. 设置命令:cc-third-party-usage(需全局安装)
  3. 或设置命令:node /path/to/cc-third-party-usage/dist/usage.js(最快)
  4. 设置超时:3000(毫秒,在组件编辑器中按 t 键)

命令行使用

# 首先设置环境变量(或通过本地代理配置)
export ANTHROPIC_BASE_URL=https://api.kimi.com
export ANTHROPIC_API_KEY=your-api-key

# 默认输出(为状态栏优化)
cc-third-party-usage
# 输出:Kimi: 45.2% used | 2h30m left

# JSON 输出
cc-third-party-usage --json

# 自定义模板
cc-third-party-usage --template "{provider}: {used}/{total} ({percent}%)"

# 详细模式(调试用)
cc-third-party-usage --verbose

# 自定义缓存时长(默认 60 秒)
cc-third-party-usage --cache-duration 120

# 帮助信息
cc-third-party-usage --help

# 版本号
cc-third-party-usage --version

📋 输出格式

默认格式(状态栏优化)

Kimi: 45.2% used | 2h30m left

JSON 输出(--json

{
  "provider": "kimi",
  "quotas": [
    {
      "window": "5h",
      "total": 100,
      "used": 45,
      "remaining": 55,
      "percent": 45.2,
      "reset": "2h30m",
      "reset_timestamp": "2026-04-02T12:00:00Z"
    }
  ],
  "fetchedAt": "2026-04-02T10:30:00Z"
}

自定义模板(--template

支持的占位符:

  • {provider} — 服务商名称(Kimi/GLM)
  • {total} — 总配额(最短窗口)
  • {used} — 已用配额(最短窗口)
  • {remaining} — 剩余配额(最短窗口)
  • {percent} — 用量百分比(最短窗口)
  • {reset} — 重置时间(最短窗口)
  • {5h_total}, {5h_used} 等 — 指定窗口的值

示例:

cc-third-party-usage --template "{provider}: {used}/{total}"
# 输出:Kimi: 45/100

cc-third-party-usage --template "{percent}% used, {remaining} remaining"
# 输出:45.2% used, 55 remaining

🔧 配置

环境变量

工具会自动检测 API 凭据,优先级如下:

  1. 本地代理数据库(当 ANTHROPIC_BASE_URL 指向 localhost 时)— 适用于代理用户
  2. 环境变量(回退方案):
    • ANTHROPIC_API_KEYANTHROPIC_AUTH_TOKEN
    • ANTHROPIC_BASE_URLBASE_URL

支持的服务商

| 服务商 | API 地址 | 说明 | |--------|---------|------| | Kimi | api.kimi.com | 月之暗面 | | GLM | open.bigmodel.cn | 智谱 AI |

缓存位置

缓存文件存储在系统临时目录:

  • macOS/Linux/tmp/cc-usage-cache/cc-usage-{provider}-cache.json
  • TTL:60 秒(可通过 --cache-duration 配置)

🛠️ 系统要求

  • 运行时:Bun 1.3.10+ 或 Node.js 22.5.0+
  • API 密钥:Kimi 或 GLM API 密钥(通过环境变量或代理配置)

🗺️ 路线图

v1.0(当前版本)

  • 跨运行时的核心基础设施
  • Kimi 与 GLM API 集成
  • 自动凭据检测
  • 智能缓存层
  • 灵活的 CLI 接口

v1.1(规划中)

  • 更多服务商支持
  • 配置文件支持(YAML/JSON)
  • 用量历史导出(CSV/JSON)
  • 持续监控模式

📝 许可证

MIT 许可证 — 详见 LICENSE

📮 链接