SIFT2009's recent timeline updates
SIFT2009

SIFT2009

V2EX member #81053, joined on 2014-11-11 11:06:37 +08:00
SIFT2009's recent replies
# [更新] cc-monitor v0.2.0 — 加了费用 spike 告警和会话结束自动总结

之前发的 [Claude Code 实时 token 监控器]( https://github.com/SagesAi/claude-cost-monitor) 更新到 **v0.2.0** 了,这次主要补了两个呼声最高的功能。

---

## 1. 费用 spike 告警

用户最痛的场景:开了个 Claude Code 会话去做别的事,回来发现烧了十几刀。

现在 monitor 会追踪每个项目 5 分钟内的 cost 变化,如果突增 ≥ $0.50 ,TUI 顶部会出现红色告警横幅,同时触发 terminal bell:

```
┌─────────────────────────────────────────────────────────────────┐
│ cc-monitor ● hook ● jsonl refreshed 14:38:42 total: $7.72 │
├─────────────────────────────────────────────────────────────────┤
│ ⚠ my-startup +$0.82 │
├───────────────────┬─────────────────────────────────────────────┤
│ PROJECTS │ my-startup │
│ ...
```

阈值目前硬编码在 $0.50/5min ,后续考虑做成可配置。

---

## 2. 会话结束自动总结

之前只有实时监控,会话结束后数据就留在内存里,没有事后分析。

现在检测到某个 session 的 JSONL 5 分钟没有更新(视为结束)时,会自动:

1. 在终端 stderr 打印一行总结
2. 追加一条记录到 `~/.claude/cc-monitor-sessions.jsonl`

效果:

```bash
# 终端里直接看到
cc-monitor: session ended #a3f2d1e9 2.0k tokens $0.43 (compaction saved 96k tokens)

# 日志文件可以 jq 分析
cat ~/.claude/cc-monitor-sessions.jsonl | jq -s 'group_by(.project)[] | {project: .[0].project, sessions: length, total_cost: map(.total_cost) | add}'
```

---

## 升级

```bash
cd claude-cost-monitor
git pull
pip install -e .
```

不需要重新装 hook ,`cc-monitor` 和 `cc-monitor-tui` 直接重启就行。

---

## 其他

- 代码结构之前也重构过,现在是比较标准的 `src/` package layout ,9 个模块 + 对应测试。
- 接下来准备做 `--report` 命令( today/this-week 聚合)和按 model 拆分成本,有兴趣可以 track GitHub 。

代码和 README:[github.com/SagesAi/claude-cost-monitor]( https://github.com/SagesAi/claude-cost-monitor)

MIT 协议,欢迎 issue / PR 。
Jul 3, 2025
Replied to a topic by SIFT2009 › 程序员 › sagesai: 10 倍提升 devops 效率
@l4ever 人一样也会发生误操作导致宕机、数据被删除的问题
Jul 3, 2025
Replied to a topic by SIFT2009 › 程序员 › sagesai: 10 倍提升 devops 效率
@l4ever 有命令安全检查以及 sandbox 机制,另外在有用户直接接管的功能。技术能解决的问题就不是问题。
Jul 2, 2025
Replied to a topic by SIFT2009 › 程序员 › sagesai: 10 倍提升 devops 效率
@sampeng 总要有一些人去身先士卒
Jul 2, 2025
Replied to a topic by SIFT2009 › 程序员 › sagesai: 10 倍提升 devops 效率
@highkay yeah, but terminal agent focus devops and ci
Aug 5, 2018
Replied to a topic by hansonwang99 › 程序员 › 一只菜鸡的半年技术博客之路
首先非常佩服 LZ 的毅力,希望能继续加油!!其次还是想提点意见,看 LZ 的分享定位:“ 虚拟化,容器化,API 化 和 微服务化的 Web 技术” ,其实人的精力是有限的,就单从这四个方面来说,你只要深入搞透一个就已经很 NB 了。加油!!!
@SoulSleep 祝梦想成真
@wintersun 点赞
这个很明显是想给你次警告。如果真的工作被边缘化了,我觉得还是做好换工作的打算
后台编辑器用的是什么
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2568 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 25ms · UTC 07:40 · PVG 15:40 · LAX 00:40 · JFK 02:40
♥ Do have faith in what you're doing.