cc-switch-usage-audit
Skill0 starsChanged 2 months agoMITView on GitHub
从 CC Switch 本地数据库聚合真实 API 用量(token / 成本 / 缓存命中率 / 模型分布),产出可入内容的成本评估与配图素材。当用户说「看看我们的 token 消耗」「实际用量统计」「CC Switch 的记录」「成本评估/背书」「一次真实的账单」时使用。
In this repository139 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/caveman-learn/CLAUDE.mdCLAUDE.md
- adversarial-reviewSkill
- ai-repo-engineering-layoutSkill
- ai-session-material-minerSkill
- ai-usage-reportSkill
- ardot-effect-fallbackSkill
- audio-friendly-adaptSkill
- automation-resurrectionSkill
- book2vido-videoSkill
- boss-autopilotSkill
- brand-icon-sourcingSkill
- canvas-designSkill
- cavecrewSkill
- caveman-commitSkill
- caveman-compressSkill
- caveman-discoverSkill
- caveman-evidence-reviewSkill
- caveman-exploreSkill
- caveman-helpSkill
- caveman-learnSkill
- caveman-manageSkill
- caveman-optimizeSkill
- caveman-reviewSkill
- caveman-setupSkill
- cavemanSkill
- caveman-statsSkill
- certification-submission-kitSkill
- comment-reply-playbookSkill
- concept-anchor-figureSkill
- conference-archiveSkill
- constitution-amendmentSkill
- content-format-auditSkill
- content-matrix-channel-auditSkill
- cross-repo-skill-curationSkill
- daily-judgment-briefSkill
- daily-reportSkill
- de-ai-flavorSkill
- desktop-ai-forensicsSkill
- discernment-nudgeSkill
- doc-translateSkill
- doubao-app-layer-archiveSkill
- effort-accountingSkill
- ego-browserSkill
- egress-allowlistSkill
- eval-skillsSkill
- evolve-skillsSkill
- exam-prep-pmpSkill
- fact-check-gateSkill
- fanout-mainline-ledgerSkill
- free-token-channel-auditSkill
- github-repo-gallerySkill
- git-identity-pinSkill
- git-push-in-sandboxSkill
- harness-governanceSkill
- harness-model-upgrade-auditSkill
- hidden-contract-auditSkill
- investigate-firstSkill
- ip-platform-fit-auditSkill
- lean-buildSkill
- The first 60 shown.
The file
Files
CC Switch 真实用量审计
把「本地代理日志」变成可对外引用的成本账。适用于:给内容做一手背书、评估换模型/迁档的真实收益、核对第三方面板数字是否可信。
数据源(只读)
- 库:
~/.cc-switch/cc-switch.db(SQLite,随时间增长;另有backups/快照可对比) - 关键表:
proxy_request_logs— 逐条请求(含 input/output/cache_read/cache_creation tokens、各项成本、latency、first_token_ms、status_code、provider_type、model)usage_daily_rollups— 按天×模型聚合(字段最全,但可能滞后于明细表)providers— 供应商配置(含密钥,只取 name/app_type/provider_type/cost_multiplier/is_current)provider_health/stream_check_logs— 可用性、流检查
⚠️ 安全纪律
- 绝不读
providers.settings_config(内含 API key),查询时列名白名单。 - 只读:不加
-w、不做任何 UPDATE/DELETE。 - 输出给人看之前,去掉可能含账号标识的字段。
步骤
- 定位新鲜度:
ls -la ~/.cc-switch/cc-switch.db(判断数据截至何时)。 - 取时段与条数:
SELECT datetime(MIN(created_at),'unixepoch','localtime'), datetime(MAX(created_at),'unixepoch','localtime'), COUNT(*) FROM proxy_request_logs; - 按模型聚合(核心一刀):
SELECT model, COUNT(*) reqs, SUM(input_tokens) inp, SUM(output_tokens) outp, SUM(cache_read_tokens) cache_r, ROUND(100.0*SUM(cache_read_tokens)/NULLIF(SUM(cache_read_tokens)+SUM(input_tokens),0),1) hit_pct, ROUND(SUM(CAST(total_cost_usd AS REAL)),2) cost_usd, ROUND(AVG(NULLIF(latency_ms,0))) lat_ms, ROUND(AVG(NULLIF(first_token_ms,0))) ttft_ms FROM proxy_request_logs GROUP BY model ORDER BY reqs DESC LIMIT 15; - 命中率口径:
cache_read / (cache_read + input)。这是成本账的开关——缓存价通常只有新输入价的 1/50。 - 交叉验证:与 CC Switch「设置 → 使用统计」页逐项对齐(请求数/总量/命中/成本应一致);不一致则说明明细与汇总口径不同(如
data_source去重、rollup 滞后)。 - 产出:
- 表格:真实消耗总量 / 命中占比 / 全价输入占比 / 输出 / 总成本 / 模型分布
- 配图(入内容用):仿
tools/fig_fit.py的 1080px 白底黑红灰卡,注明「来源:本地代理日志聚合 + 时段 + 条数」;自制转录,不贴原始面板截图(风格统一 + 防泄漏)
用官方定价重算(必做,别用平台记录的数字)
CC Switch 记录的 total_cost_usd 是平台/中转层计价,与官方定价可能不同。要写进内容或做决策,必须按官方价×逐条日志重算:
- 拉官方价表(双轨!):如 DeepSeek 空闲/高峰两套价,
高峰 = 空闲 × 2;高峰时段 = 北京时间工作日 9:00-12:00、14:00-18:00。 - 按 created_at 切时段(
datetime.fromtimestamp(ts, tz=UTC+8);weekday()<5 and (9<=h<12 or 14<=h<18)为高峰)。 - 计费公式:
命中×命中价 + (未命中输入 + 缓存创建)×未命中价 + 输出×输出价,空闲/高峰分别算再加总。- ⚠️
cache_creation_tokens按未命中输入价计费,别漏。
- ⚠️
- 同量对比(最有说服力的一刀):同样的 token 结构,分别代入候选模型的价表 → 得出「Flash 750 元 vs Pro 3,983 元,5.3×」这种可直接引用的结论。
- 敏感性:固定用量,让命中率在 97.7% / 90% / 80% / 60% / 0% 之间变,输出账单倍数表——命中率对账单的杠杆一目了然。
- 时段杠杆:算「若高峰全挪到空闲」的差额,常能再省 30~50%。
实例(2026-09-14 MODEL-02):77.14 亿 tokens、命中率 97.7%、高峰占 77% → Flash 750 元/月 vs Pro 3,983 元/月;命中率掉到 80% 账单变 3,144 元(4.2×);全挪空闲降到 421 元。
坑
latency_ms/first_token_ms常为空(未记录)→ 四指标框架里「延迟」项如实标注待补,别编。usage_daily_rollups可能停在更早日期,明细表更新——以proxy_request_logs为准。- 同一时间段
rollups与logs的成本若不等,优先信明细(logs)。 - 库在 App 运行时可能被占用:只读查询无需锁,但拿到
database is locked就先拷一份副本再查。
<!-- public-sync: 2026-10-12 | 脱敏版本 | 源 ~/.workbuddy/skills/cc-switch-usage-audit -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

