一名开发者在Hacker News上发布了开源工具ClaudeStatsBar,旨在帮助Claude Code用户实时了解会话的实际成本1。该工具通过在状态栏显示当前会话的上下文大小、下一轮消息的令牌消耗和API使用窗口剩余时间,让用户发现往往被忽视的隐藏成本1。
作者通过两周的实际测量发现了显著的数据规律:在711个会话的测试周期内,用户共消耗11.6亿令牌,其中用户输入仅占1.3百万令牌,而系统重新读取已有上下文耗费了111亿令牌1。在一个486k上下文大小的会话中,即使用户未输入任何内容,每轮对话也需要消耗49k令牌1。数据表明会话大小增长与成本之间存在接近线性平方的关系,每轮对话约增加1.7k令牌1。
为了帮助用户优化成本,工具提供了针对性的优化建议排序:清除会话间任务可减少35%的成本,减少对话轮次可减少20%,修剪指令文件可减少2%,降低推理强度可减少2%1。ClaudeStatsBar采用MIT开源许可证,使用纯Python标准库实现,无需外部依赖1。该工具要求Claude Code版本2.1.251或更高,以支持prompt_cache功能1。
A developer has released ClaudeStatsBar, an open-source utility designed to expose the accumulating expenses of extended Claude Code sessions by displaying real-time context metrics directly in the status bar 1. The tool shows the current session's context size, the token cost of the next message, and remaining API usage window time, addressing a critical visibility gap that leaves users unaware of how quickly their conversations consume resources 1.
The creator's two-week measurement across 711 sessions revealed the extent of the problem: 57,451 API requests consumed 1.16 billion tokens, with user inputs accounting for only 1.3 million tokens while the system re-read 11.1 billion tokens of existing context 1. In a deeply nested 486k-context session, a single round-trip conversation costs 49,000 tokens before the user types anything 1. Context size grows at approximately a quadratic rate, with each conversational turn adding roughly 1.7k tokens 1.
To optimize token usage, the developer recommends prioritizing clearing sessions between tasks (responsible for 35% of potential savings), followed by reducing conversation rounds (20%), trimming instruction files (2%), and lowering reasoning intensity (2%) 1. ClaudeStatsBar requires Claude Code version 2.1.251 or later to support the prompt_cache feature, is released under an MIT license, and uses only Python standard library with no external dependencies 1.
评论
还没有评论,欢迎留下第一条。