Skip to content

Releases: SDpower/ccusage_go

v0.14.0

Choose a tag to compare

@github-actions github-actions released this 08 May 02:51

🚨 重大修復(強烈建議升級)

filter 模式漏掃 subagents/ 子目錄

Anthropic CLI 將 sub-agent 對話分流寫入 ~/.claude/projects/<project>/subagents/agent-*.jsonl,占整體 JSONL 大小約 53%。v0.13.0 之前,filter 模式的
collectProjectFiles 對所有子目錄一律 skip,導致:

模式 v0.13.0 行為 v0.14.0 行為
daily(預設 filepath.Walk ✅ 含 sub-agent ✅ 含 sub-agent
blocks --live / --modified-within / --only-active 漏算 sub-agent ✅ 含 sub-agent

實測差距(單一使用者全資料集):

+ 21,775 entries
+ 1,285,065  input tokens
+ 4,711,090  output tokens

修復後:所有指令對同一份資料回傳一致 cost。


✨ 新功能

1. server_tool_use 計費機制

新增 Anthropic web tools 的 per-request 計費:

  • usage.server_tool_use.web_search_requestsentry.WebSearchRequests
  • usage.server_tool_use.web_fetch_requestsentry.WebFetchRequests
  • entry.WebSearchCost = WebSearchRequests * webSearchPrice
  • entry.WebFetchCost = WebFetchRequests * webFetchPrice
  • Cost 含 web tool 費用、APICost 不含(與 cache 同類處理)

Embedded fallback 採 Anthropic 公告值:web_search $0.01/reqweb_fetch $0/req

2. nested cache_creation fallback

當 flat cache_creation_input_tokens 缺值時,自動讀取:

usage.cache_creation.ephemeral_1h_input_tokens
+ usage.cache_creation.ephemeral_5m_input_tokens

為 Anthropic 未來移除 flat 欄位預先相容;目前 flat 與 nested 同值,flat 優先。

3. UsageEntry first-class 欄位

欄位 用途
CacheCreationInputTokens / CacheReadInputTokens 取代 Raw["cache_*"] 間接存取
IsSidechain / IsMeta 對話樹 metadata,僅供 breakdown 報表使用,永不過濾
WebSearchRequests / WebFetchRequests / WebSearchCost / WebFetchCost server_tool_use 計費
CacheMissReason (*types.CacheMissReason) Anthropic 提供的 cache 未命中診斷

新增 CacheMissReason 結構:

type CacheMissReason struct {
    Type                   string `json:"type"`
    CacheMissedInputTokens int    `json:"cache_missed_input_tokens"`
}

4. SessionName 第三順位來源

優先序:custom-title > agent-name > ai-title

更多原本沒有 SessionName 的 session 會自動取得有意義名稱。


⚠️ Breaking Changes

PricingService.GetModelPrice 簽章變更

- GetModelPrice(ctx context.Context, model string) (
-     inputPrice, outputPrice, cacheCreatePrice, cacheReadPrice float64,
-     err error,
- )
+ GetModelPrice(ctx context.Context, model string) (
+     inputPrice, outputPrice, cacheCreatePrice, cacheReadPrice,
+     webSearchPrice, webFetchPrice float64,
+     err error,
+ )

影響範圍:

  • pricing.PricingServicecalculator.PricingService 介面
  • 任何透過 pkg/ccusage 公開 API 直接實作或呼叫此介面的下游程式

本 repo 內所有使用點已同步更新;下游需各自補上兩個 _ 或實際費率。


🔧 Refactor

  • 抽出 clearRawExceptKeys(entry, keep) helper,統一 stream / 非 stream / project_cache 三處 Raw 清理;usage_limit_reset_time
    在所有路徑一致保留(修前非 stream 路徑會遺失此欄位)
  • shouldCountAsParseError 白名單集中宣告 nonUsageEntryTypes,新增 attachment / system / last-prompt / file-history-snapshot /
    permission-mode / agent-setting / queue-operation / ai-title,避免合法 type 被誤計入 parseErrors(debug 輸出失真修復)
  • extractProjectPath 移除 YYYY/MM/DD dead code 與未使用的 isNumeric;補上 subagents/ 父目錄 fallback
  • 全 repo 移除 Raw["cache_*"] 取用:internal/calculator/{calculator,blocks}.gointernal/output/tablewriter_formatter.go

📁 變更檔案

檔案 性質
internal/types/usage.go UsageEntry 欄位擴充、新增 CacheMissReason
internal/loader/loader.go P0 修復、nested fallback、server_tool_use 萃取、SessionName、白名單
internal/loader/project_cache.go live cache 涵蓋 subagents/
internal/pricing/pricing.go GetModelPrice 簽章、ModelPricing 新欄位、Anthropic 預設常數
internal/calculator/calculator.go calculateSingleCost 全改寫、PricingService 介面同步
internal/calculator/blocks.go 改用 first-class cache 欄位
internal/output/tablewriter_formatter.go 同上

📦 安裝

# macOS arm64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.14.0/ccusage_go-darwin-arm64.tar.gz | tar xz

# macOS amd64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.14.0/ccusage_go-darwin-amd64.tar.gz | tar xz

# Linux amd64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.14.0/ccusage_go-linux-amd64.tar.gz | tar xz

🔗 Commits

  • 19c1ff3 — feat: 修正 subagents 漏算並新增 server_tool_use 計費與 first-class cache 欄位
  • e2431d9 — docs: v0.14.0 文件更新(CHANGELOG / docs / README)

Full Changelog: v0.13.0...v0.14.0

v0.13.0

Choose a tag to compare

@github-actions github-actions released this 06 Apr 15:10

ccusage_go v0.13.0

✨ Features

  • OAuth Token Auto-Refresh: Automatically refreshes expired tokens via POST platform.claude.com/v1/oauth/token
    • Triggers on token expiry (expiresAt <= now) or HTTP 401 response
    • Retries the failed Usage API call once after a successful refresh
    • Cross-platform credential persistence: macOS Keychain / Linux & Windows .credentials.json (0600)
    • Mutex-based concurrency control to prevent duplicate refresh attempts

🐛 Bug Fixes

  • Fix missing Usage API headers: Added Content-Type: application/json and User-Agent: claude-code/2.1.92 — all 4 headers
    are required for a successful response
  • Fix token read priority: Changed from env → file → Keychain to env → Keychain → file to match Claude Code v2.x
    behavior (Keychain is the default store; .credentials.json may not exist)

📦 Installation

macOS

# Intel Mac
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.13.0/ccusage_go-darwin-amd64.tar.gz | tar xz

# Apple Silicon (M1/M2/M3)
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.13.0/ccusage_go-darwin-arm64.tar.gz | tar xz

Linux

# x64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.13.0/ccusage_go-linux-amd64.tar.gz | tar xz

# ARM64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.13.0/ccusage_go-linux-arm64.tar.gz | tar xz

Windows

Download the appropriate .zip file and extract it.

Full Changelog: v0.12.0...v0.13.0

v0.12.0

Choose a tag to compare

@github-actions github-actions released this 24 Mar 15:51

Release Notes — v0.12.0 (2026-03-24)

✨ Features

Session Query & Detail View

  • New --session-id / --session-name flags for precise session lookup
  • Session name resolution from JSONL custom-title / agent-name entries with global cross-file backfill
  • Filtered mode displays per-source-file breakdown: Session as a block header, each Source File as an independent row with its own Models, Input, Output, Cache, Cost, and Last Activity

Cost Breakdown

  • All reports (Daily / Monthly / Session / Blocks) now include CC Cost, CR Cost, and API Cost as independent columns
  • API Cost = input + output only (excludes cache)
  • CC Cost = Cache Create cost, CR Cost = Cache Read cost
  • Legacy data without cache fields shows -

Blocks Report Enhancement

  • Expanded from single Tokens + Cost columns to full breakdown: Input / Output / Cache Create / CC Cost / Cache Read / CR Cost / Total Tokens / API Cost / Cost
  • Gap rows and REMAINING/PROJECTED special rows updated accordingly

Other Improvements

  • Daily / Monthly reports now include a Sessions count column
  • Session report tracks all unique Session IDs and Source Files
  • Last Activity displays date + time with (localtime) header annotation
  • CSV output adds session_name, session_ids, source_files, cache_create_cost, cache_read_cost columns

📦 Installation

macOS

# Intel Mac
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.12.0/ccusage_go-darwin-amd64.tar.gz | tar xz

# Apple Silicon (M1/M2/M3)
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.12.0/ccusage_go-darwin-arm64.tar.gz | tar xz

Linux

# x64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.12.0/ccusage_go-linux-amd64.tar.gz | tar xz

# ARM64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.12.0/ccusage_go-linux-arm64.tar.gz | tar xz

Windows

Download the appropriate .zip file and extract it.

Full Changelog: v0.11.1...v0.12.0

v0.11.1

Choose a tag to compare

@github-actions github-actions released this 15 Mar 12:26

v0.11.1 — Project-level Incremental Cache for blocks --live

⚡ Performance

Add project-level incremental cache for blocks --live mode, reducing CPU usage by 68% when data is unchanged.

How it works:

  • Tracks file state (ModTime + Size) per project directory
  • Only reloads files that have actually changed
  • Skips entirely when no changes detected (< 1ms)
  • Per-project deduplication for efficient append-only JSONL handling
  • Full project reload on file deletion for cache consistency

📊 Performance Metrics

Metric Before After Improvement
CPU avg (30s) 26.7% 8.5% -68%

📁 Files Changed

  • internal/loader/project_cache.go — New incremental cache implementation
  • internal/loader/project_cache_test.go — 9 unit tests
  • internal/monitor/blocks_live.go — Integrated incremental cache into tick handler

📦 Installation

# macOS Apple Silicon
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.11.1/ccusage_go-darwin-arm64.tar.gz | tar xz

# macOS Intel
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.11.1/ccusage_go-darwin-amd64.tar.gz | tar xz

# Linux x64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.11.1/ccusage_go-linux-amd64.tar.gz | tar xz

Full Changelog: https://github.com/SDpower/ccusage_go/compare/v0.11.0...v0.11.1

v0.11.0

Choose a tag to compare

@github-actions github-actions released this 11 Mar 15:11

What's New

📊 Usage Limits Display (blocks --live)

  • New LIMITS section showing Claude API quota in real-time
  • Displays session (5-hour) and weekly limits with progress bars
  • Color-coded indicators: green (≤60%), yellow (60-90%), red (>90%)
  • Shows reset times in local timezone
  • Reads OAuth token from environment, credentials file, or macOS Keychain
  • Graceful degradation: section hidden when no token or API unavailable

🔧 Fix Model Name Display for New Format

  • Fixed truncated display for dateless model IDs (e.g. claude-opus-4-6, claude-sonnet-4-6)
  • claude-opus-4-6 now correctly shows as Opus-4.6 instead of claude-opus-
  • claude-sonnet-4-6 now correctly shows as Sonnet-4.6 instead of claude-sonne
  • Existing dated formats (e.g. claude-haiku-4-5-20251001) remain unaffected

📸 Updated Screenshot

  • Updated blocks --live monitor screenshot reflecting new LIMITS section

New Package

  • internal/usage/ — Claude OAuth Usage API client with cross-platform token reading and 5-minute cache

Full Changelog

v0.10.1...v0.11.0

v0.10.1

Choose a tag to compare

@github-actions github-actions released this 16 Oct 01:21

ccusage_go v0.10.1

🚀 Performance

  • Memory usage: ~45MB (88% less than TypeScript version)
  • CPU usage: Peak during startup, low during monitoring

📦 Installation

macOS

# Intel Mac
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.1/ccusage_go-darwin-amd64.tar.gz | tar xz

# Apple Silicon (M1/M2/M3)
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.1/ccusage_go-darwin-arm64.tar.gz | tar xz

Linux

# x64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.1/ccusage_go-linux-amd64.tar.gz | tar xz

# ARM64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.1/ccusage_go-linux-arm64.tar.gz | tar xz

Windows

Download the appropriate .zip file and extract it.

Full Changelog: v0.10.0...v0.10.1

v0.10.0

Choose a tag to compare

@github-actions github-actions released this 02 Oct 04:07

ccusage_go v0.10.0

🚀 Performance

  • Memory usage: ~45MB (88% less than TypeScript version)
  • CPU usage: Peak during startup, low during monitoring

📦 Installation

macOS

# Intel Mac
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.0/ccusage_go-darwin-amd64.tar.gz | tar xz

# Apple Silicon (M1/M2/M3)
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.0/ccusage_go-darwin-arm64.tar.gz | tar xz

Linux

# x64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.0/ccusage_go-linux-amd64.tar.gz | tar xz

# ARM64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.10.0/ccusage_go-linux-arm64.tar.gz | tar xz

Windows

Download the appropriate .zip file and extract it.

Full Changelog: v0.9.0...v0.10.0

v0.9.0

Choose a tag to compare

@github-actions github-actions released this 23 Aug 23:32

ccusage_go v0.9.0

🚀 Performance

  • Memory usage: ~45MB (88% less than TypeScript version)
  • CPU usage: Peak during startup, low during monitoring

📦 Installation

macOS

# Intel Mac
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.9.0/ccusage_go-darwin-amd64.tar.gz | tar xz

# Apple Silicon (M1/M2/M3)
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.9.0/ccusage_go-darwin-arm64.tar.gz | tar xz

Linux

# x64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.9.0/ccusage_go-linux-amd64.tar.gz | tar xz

# ARM64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.9.0/ccusage_go-linux-arm64.tar.gz | tar xz

Windows

Download the appropriate .zip file and extract it.

Full Changelog: v0.8.0...v0.9.0

v0.8.0

Choose a tag to compare

@github-actions github-actions released this 14 Aug 12:59

ccusage-go v0.8.0

🚀 Performance

  • Memory usage: ~54MB (87% less than TypeScript version)
  • CPU usage: ~10% (92% less than TypeScript version)

📦 Installation

macOS

# Intel Mac
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.8.0/ccusage-go-darwin-amd64.tar.gz | tar xz

# Apple Silicon (M1/M2/M3)
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.8.0/ccusage-go-darwin-arm64.tar.gz | tar xz

Linux

# x64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.8.0/ccusage-go-linux-amd64.tar.gz | tar xz

# ARM64
curl -L https://github.com/SDpower/ccusage_go/releases/download/v0.8.0/ccusage-go-linux-arm64.tar.gz | tar xz

Windows

Download the appropriate .zip file and extract it.

Full Changelog: https://github.com/SDpower/ccusage_go/commits/v0.8.0