1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

複数デバイスに対応したccusageラッパーを作った

1
Last updated at Posted at 2025-07-25

作ったもの

ccumd

$ bunx ccumd device add remote-pc # `ssh remote-pc` で接続できる必要がある
Device 'remote-pc' added successfully.
Syncing device data...
Synced 90 files from device 'remote-pc'
Device data synced successfully.

でデバイスを追加して、

$ bunx ccumd --since 20250724
Syncing device data...
Synced 90 files from device 'remote-pc'
✓ Synced remote-pc


[ccusage]  WARN  Fetching latest model pricing from LiteLLM...

[ccusage] ℹ Loaded pricing for 1250 models

 ╭──────────────────────────────────────────╮
 │                                          │
 │  Claude Code Token Usage Report - Daily  │
 │                                          │
 ╰──────────────────────────────────────────╯

┌──────────┬─────────────────┬──────────┬──────────┬────────────┬───────────┬────────────┬───────────┐
│ Date     │ Models          │    Input │   Output │      Cache │     Cache │      Total │      Cost │
│          │                 │          │          │     Create │      Read │     Tokens │     (USD) │
├──────────┼─────────────────┼──────────┼──────────┼────────────┼───────────┼────────────┼───────────┤
│ 2025     │ - opus-4        │    4,836 │  178,823 │  2,365,924 │ 58,057,6… │ 60,607,227 │   $101.54 │
│ 07-24    │ - sonnet-4      │          │          │            │           │            │           │
├──────────┼─────────────────┼──────────┼──────────┼────────────┼───────────┼────────────┼───────────┤
│ 2025     │ - opus-4        │   15,752 │  169,362 │  2,504,502 │ 49,468,0… │ 52,157,697 │    $49.36 │
│ 07-25    │ - sonnet-4      │          │          │            │           │            │           │
├──────────┼─────────────────┼──────────┼──────────┼────────────┼───────────┼────────────┼───────────┤
│ 2025     │ - opus-4        │    2,335 │   17,870 │    230,170 │ 3,118,660 │  3,369,035 │     $5.54 │
│ 07-26    │ - sonnet-4      │          │          │            │           │            │           │
├──────────┼─────────────────┼──────────┼──────────┼────────────┼───────────┼────────────┼───────────┤
│ Total    │                 │   22,923 │  366,055 │  5,100,596 │ 110,644,… │ 116,133,9… │   $156.43 │
└──────────┴─────────────────┴──────────┴──────────┴────────────┴───────────┴────────────┴───────────┘

で、ローカル&追加したデバイスの合計使用額が見れます。Bunの機能にべったり依存しているので、本家のようにnpxでは実行できません。

おまけ機能

ccumdはccusage-multi-devicesの略なので本来スコープ外なのですが、こういうツールにはグラフ化機能があるべきだと思ったので bunx ccumd --graph で棒グラフが表示できます。

graph

綺麗。ccusageラッパーのグラフ化ツールにはもっと使いやすいものがありますが、ccumdとくっつけようと思うとしんどそうだったので一旦独自実装しています。

今後の展開について

  • npxで実行できるようにしたい
  • デバイスごとに分けて使用料を見れるようにしたい
  • Claude Code Actionの使用料も取得できるようにしたい
  • そもそもあんまりリポジトリをちゃんと整理していないのでしたい

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?