Repository navigation
feat(collector): collect local Claude Code usage - #2
Merged
Merged
Conversation
Add a write-only ingest endpoint bound to per-device key digests, store pushed accounts, usage and quota snapshots idempotently, and price Claude models with separate 1-hour cache write rates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z
Read Claude Code session logs and the cached account and quota state read-only, dedupe split response lines per request, attribute usage to the observed login, and push batches to the ingest endpoint from a launchd job packaged as Meterleaf.app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z
Optionally read the rate-limit TSV written by the user's statusline script, use the file time as the sample time and the login observed at that time as the account, and skip samples whose account cannot be determined. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z
install-launchd now registers a bundled agent with SMAppService when it runs from Meterleaf.app, so Login Items shows the app name and icon. Custom paths still fall back to a plain LaunchAgent. sync --log writes the background output into the data directory with a 1 MiB rotation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z
macOS pins the launched program's ad-hoc code signature in the background item record, so rebuilding the collector made launchd refuse it with OS_REASON_CODESIGNING. The bundled agent now launches the small, rarely changing service helper, which execs the collector. The label moves to io.meterleaf.collector.background because the old one stays pinned to a previous build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z
meterleaf-collector server <url> rewrites only the server in the local config, so a machine can move from a LAN address to a public HTTPS one without regenerating its ingest key or touching the server. The deployment guide shows how to expose only the push endpoint through a reverse proxy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
本地直连的 Claude Code 不经过 Sub2API,它的用量只保存在使用它的电脑上,Meterleaf 无法统计。Claude Code 自带的
/stats把同一次请求拆分保存的多行逐行累加,显示的 Token 总数约为实际的两倍,不能直接作为账本依据。变化
src/collector,打包为带品牌图标的Meterleaf.app,由 launchd 每分钟以低优先级运行一次同步。~/.claude/projects会话记录与~/.claude.json,不写入 Claude Code 目录,不读取 OAuth 令牌、钥匙串或凭据,不调用 Anthropic 接口。requestId与message.id合并拆分保存的行,每次请求只计一次;同组取四桶总量最大的一行。~/.claude.json;可选读取状态栏脚本写出的额度缓存,获得更及时的额度。bind-history可明确声明首次运行前的历史归属。server <url>只更换服务地址,写入密钥与来源 ID 不变,便于从局域网地址切换到公网 HTTPS 地址。(sourceId, externalId)幂等写入,断网恢复后补发不重复。POST /api/ingest/v1/batches。每台电脑一个写入密钥,METERLEAF_INGEST_KEYS只保存 SHA-256 摘要并绑定来源;未配置时不注册路由。部署指南说明如何只在反向代理上公开这一个地址。prices/meterleaf-2026-09-25.json,加入 Claude Fable 5.1、Opus 5.5、Opus 5、Sonnet 5、Haiku 4.5(含官方别名)的官方价格。新增可选cacheWrite1h费率,1 小时与 5 分钟缓存写入分开计价,缺少 TTL 拆分时保留未计价;快速模式记为 priority 档。Max 5x。文档新增 本机采集器,更新部署、计价、README 与 CHANGELOG。验证
bun run typecheck、bun test tests(294 pass)、所改文件 Prettier 与git diff --check通过。~/.claude.json的旧快照更新为状态栏最新采样ï 8000 ¼Œ不再标记过时。install-launchd,系统沿用同一登记继续运行。改用助手之前,同样的升级会被OS_REASON_CODESIGNING拒绝。POST /api/ingest/v1/batches绕过登录保护后,本机采集器改用公网 HTTPS 地址推送成功。无密钥或错误密钥返回 401,GET 被拒绝,3 MB 请求体未被代理截断,其余页面仍需登录。已知限制
~/.claude.json的额度缓存只在打开用量面板时刷新,未启用状态栏缓存时额度通常过时。🤖 Generated with Claude Code
https://claude.ai/code/session_012bEAuLoXyJtm1PRMVvDi3z