@winston.wan/burn-your-money 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,23 +29,11 @@ Claude Code 很好用,就像在你的命令行里装了一个核动力引擎
29
29
 
30
30
  ## 🚀 安装
31
31
 
32
- ### 方式 1: NPM 安装(推荐)
33
-
34
32
  ```bash
35
33
  npm install -g "@winston.wan/burn-your-money"
36
34
  ```
37
35
 
38
- ### 方式 2: 脚本安装
39
-
40
- **Linux / macOS / Git Bash**
41
- ```bash
42
- curl -fsSL https://raw.githubusercontent.com/winston-wwzhen/burn-your-money/main/install.sh | bash
43
- ```
44
-
45
- **Windows PowerShell**
46
- ```powershell
47
- curl.exe -fsSL https://raw.githubusercontent.com/winston-wwzhen/burn-your-money/main/install.sh -o install.sh; bash install.sh
48
- ```
36
+ 重启 Claude Code 即可看到效果。
49
37
 
50
38
  ---
51
39
 
@@ -74,39 +62,32 @@ curl.exe -fsSL https://raw.githubusercontent.com/winston-wwzhen/burn-your-money/
74
62
 
75
63
  ## 📊 使用命令
76
64
 
77
- ### CLI 命令
78
-
79
- 安装后可以在终端使用 `burn-your-money` 命令:
80
-
81
- ```bash
82
- burn-your-money status # 查看完整状态
83
- burn-your-money theme ocean # 切换主题
84
- burn-your-money alert 20 # 设置每日预警金额
85
- burn-your-money chart # 显示趋势图表
86
- burn-your-money today # 今日统计
87
- burn-your-money week # 本周统计
88
- burn-your-money month # 本月统计
89
- burn-your-money total # 总计统计
90
- ```
91
-
92
65
  ### Claude Code 内置命令
93
66
 
94
67
  在 Claude Code 对话中可以直接使用:
95
68
 
96
69
  | 命令 | 说明 |
97
70
  |------|------|
71
+ | `/burn-your-money` | 查看详细账单(今日/周/月/总计 + 有趣统计) |
98
72
  | `/burn-your-money-stats` | 查看 token 使用趋势图 |
99
- | `/burn-your-money-today` | 查看今日 token 使用情况 |
100
- | `/burn-your-money-week` | 查看本周 token 使用情况 |
101
- | `/burn-your-money-month` | 查看本月 token 使用情况 |
102
- | `/burn-your-money-export` | 导出 token 数据(JSON 格式) |
103
- | `/burn-your-money-export-csv` | 导出 token 数据(CSV 格式) |
73
+ | `/burn-your-money-export` | 导出 token 数据(CSV 格式) |
104
74
 
105
75
  ---
106
76
 
107
- ## 🛠️ 性能说明
77
+ ## 🛠️ 技术特点
78
+
79
+ ### 纯 Node.js 实现
80
+
81
+ - ✅ **零外部依赖** - 只需要 Node.js(Claude Code 自带)
82
+ - ✅ **无 bash 问题** - 不会有 Windows fork 错误
83
+ - ✅ **跨平台稳定** - Windows/macOS/Linux 无差异
84
+ - ✅ **执行速度快** - 无需启动 bash 子进程
108
85
 
109
- 我们深知现在的 API 有多贵,所以本插件**绝不**发起任何网络请求。所有数据纯本地计算,它只烧你的钱,不烧你的 CPU。
86
+ ### 数据来源
87
+
88
+ - **当前会话**:从 Claude Code statusline API 实时获取
89
+ - **历史统计**:从 `~/.claude/stats-cache.json` 读取
90
+ - **本地计算**:零网络请求,纯本地处理
110
91
 
111
92
  ---
112
93
 
@@ -125,18 +106,26 @@ burn-your-money total # 总计统计
125
106
  - **当前会话费用**:完全准确,使用 Claude Code 提供的实时数据
126
107
  - **历史费用统计**:基于固定费率估算(Input $3/M, Output $15/M, Cache Read $0.3/M),如果频繁切换不同模型,可能略有偏差
127
108
 
128
- ### 3. Windows 上出现 fork 错误?
109
+ ### 3. 卸载后状态栏还显示?
110
+
111
+ npm 的 `preuninstall` 钩子在某些情况下可能不触发。如果卸载后状态栏还显示:
112
+
113
+ **方案 1**:手动运行清理脚本
114
+ ```bash
115
+ node D:/code/burn-your-money/uninstall.js
116
+ ```
129
117
 
130
- 这是 Git Bash 和 Windows Defender 的兼容性问题。运行以下脚本修复:
118
+ **方案 2**:手动删除文件和配置
119
+ ```bash
120
+ # 删除插件文件
121
+ rm -f ~/.claude/statusline.js
122
+ rm -f ~/.claude/scripts/token-history.js
123
+ rm -f ~/.claude/commands/burn-your-money-*.md
131
124
 
132
- ```powershell
133
- # 以管理员身份运行 PowerShell
134
- .\fix-git-bash.ps1
125
+ # 然后编辑 settings.json 删除 statusLine 配置项
135
126
  ```
136
127
 
137
- 或手动将以下目录添加到 Windows Defender 排除列表:
138
- - `C:\Program Files\Git`
139
- - `%USERPROFILE%\.claude`
128
+ 然后重启 Claude Code。
140
129
 
141
130
  ---
142
131
 
@@ -148,24 +137,7 @@ burn-your-money total # 总计统计
148
137
  npm uninstall -g "@winston.wan/burn-your-money"
149
138
  ```
150
139
 
151
- 如果卸载后状态栏仍然显示,手动运行清理脚本:
152
-
153
- ```bash
154
- node ~/.claude/node_modules/@winston.wan/burn-your-money/uninstall.js
155
- ```
156
-
157
- 或直接删除文件和配置:
158
-
159
- ```bash
160
- # 删除插件文件
161
- rm -f ~/.claude/statusline.sh ~/.claude/statusline-wrapper.sh
162
- rm -f ~/.claude/scripts/token-history.sh
163
- rm -f ~/.claude/commands/burn-your-money-*.md
164
-
165
- # 清理配置(需要删除 statusLine 配置项)
166
- ```
167
-
168
- 然后重启 Claude Code。
140
+ 如果卸载后状态栏仍然显示,请参考常见问题中的手动清理方法。
169
141
 
170
142
  ---
171
143
 
@@ -1,11 +1,11 @@
1
1
  Stack trace:
2
2
  Frame Function Args
3
- 0007FFFFB550 00021005FE8E (000210285F68, 00021026AB6E, 000000000000, 0007FFFFA450) msys-2.0.dll+0x1FE8E
4
- 0007FFFFB550 0002100467F9 (000000000000, 000000000000, 000000000000, 0007FFFFB828) msys-2.0.dll+0x67F9
5
- 0007FFFFB550 000210046832 (000210286019, 0007FFFFB408, 000000000000, 000000000000) msys-2.0.dll+0x6832
6
- 0007FFFFB550 000210068CF6 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x28CF6
7
- 0007FFFFB550 000210068E24 (0007FFFFB560, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x28E24
8
- 0007FFFFB830 00021006A225 (0007FFFFB560, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x2A225
3
+ 0007FFFFBBC0 00021005FE8E (000210285F68, 00021026AB6E, 000000000000, 0007FFFFAAC0) msys-2.0.dll+0x1FE8E
4
+ 0007FFFFBBC0 0002100467F9 (000000000000, 000000000000, 000000000000, 0007FFFFBE98) msys-2.0.dll+0x67F9
5
+ 0007FFFFBBC0 000210046832 (000210286019, 0007FFFFBA78, 000000000000, 000000000000) msys-2.0.dll+0x6832
6
+ 0007FFFFBBC0 000210068CF6 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x28CF6
7
+ 0007FFFFBBC0 000210068E24 (0007FFFFBBD0, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x28E24
8
+ 0007FFFFBEA0 00021006A225 (0007FFFFBBD0, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x2A225
9
9
  End of stack trace
10
10
  Loaded modules:
11
11
  000100400000 bash.exe
package/install.js CHANGED
@@ -124,108 +124,22 @@ function configureSettings() {
124
124
  }
125
125
 
126
126
  const commands = [
127
- {
128
- name: 'burn-your-money-stats.md',
129
- content: `---
130
- name: burn-your-money-stats
131
- description: 📊 查看 token 使用趋势图
132
- ---
133
-
134
- # Token 使用趋势图
135
-
136
- 请执行以下命令查看过去 7 天的 token 使用趋势图:
137
-
138
- \\\`\\\`\\\`bash
139
- node ~/.claude/scripts/token-history.js chart
140
- \\\`\\\`\\\`
141
- `
142
- },
143
- {
144
- name: 'burn-your-money-today.md',
145
- content: `---
146
- name: burn-your-money-today
147
- description: 📅 查看今日 token 使用情况
148
- ---
149
-
150
- # 今日 Token 使用情况
151
-
152
- 请执行以下命令查看今日的 token 使用量:
153
-
154
- \\\`\\\`\\\`bash
155
- node ~/.claude/scripts/token-history.js today_tokens
156
- \\\`\\\`\\\`
157
- `
158
- },
159
- {
160
- name: 'burn-your-money-week.md',
161
- content: `---
162
- name: burn-your-money-week
163
- description: 📆 查看本周 token 使用情况
164
- ---
165
-
166
- # 本周 Token 使用情况
167
-
168
- 请执行以下命令查看本周的 token 使用量:
169
-
170
- \\\`\\\`\\\`bash
171
- node ~/.claude/scripts/token-history.js week_tokens
172
- \\\`\\\`\\\`
173
- `
174
- },
175
- {
176
- name: 'burn-your-money-month.md',
177
- content: `---
178
- name: burn-your-money-month
179
- description: 🗓️ 查看本月 token 使用情况
180
- ---
181
-
182
- # 本月 Token 使用情况
183
-
184
- 请执行以下命令查看本月的 token 使用量:
185
-
186
- \\\`\\\`\\\`bash
187
- node ~/.claude/scripts/token-history.js month_tokens
188
- \\\`\\\`\\\`
189
- `
190
- },
191
- {
192
- name: 'burn-your-money-export.md',
193
- content: `---
194
- name: burn-your-money-export
195
- description: 💾 导出 token 数据(JSON)
196
- ---
197
-
198
- # 导出 Token 数据
199
-
200
- 请执行以下命令导出 token 数据为 JSON 格式:
201
-
202
- \\\`\\\`\\\`bash
203
- node ~/.claude/scripts/token-history.js export json
204
- \\\`\\\`\\\`
205
- `
206
- },
207
- {
208
- name: 'burn-your-money-export-csv.md',
209
- content: `---
210
- name: burn-your-money-export-csv
211
- description: 📄 导出 token 数据(CSV)
212
- ---
213
-
214
- # 导出 Token 数据 (CSV)
215
-
216
- 请执行以下命令导出 token 数据为 CSV 格式:
217
-
218
- \\\`\\\`\\\`bash
219
- node ~/.claude/scripts/token-history.js export csv
220
- \\\`\\\`\\\`
221
- `
222
- }
127
+ 'burn-your-money.md',
128
+ 'burn-your-money-stats.md',
129
+ 'burn-your-money-export.md'
223
130
  ];
224
131
 
132
+ const projectCommandsDir = path.join(projectRoot, 'src', 'commands');
133
+
225
134
  commands.forEach(cmd => {
226
- const cmdPath = path.join(commandsDir, cmd.name);
227
- fs.writeFileSync(cmdPath, cmd.content);
228
- success(`Installed ${cmd.name}`);
135
+ const srcPath = path.join(projectCommandsDir, cmd);
136
+ const destPath = path.join(commandsDir, cmd);
137
+ if (fs.existsSync(srcPath)) {
138
+ fs.copyFileSync(srcPath, destPath);
139
+ success(`Installed ${cmd}`);
140
+ } else {
141
+ warning(`Command file not found: ${cmd}`);
142
+ }
229
143
  });
230
144
  }
231
145
 
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@winston.wan/burn-your-money",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "💸 Burn Your Money - 实时显示 Claude Code 的 token 消耗,看着你的钱包燃烧!",
5
5
  "main": "src/statusline.js",
6
6
  "scripts": {
7
7
  "postinstall": "node install.js",
8
- "preuninstall": "node uninstall.js"
8
+ "postuninstall": "node uninstall.js"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
@@ -26,4 +26,4 @@
26
26
  "url": "https://github.com/winston-wwzhen/burn-your-money/issues"
27
27
  },
28
28
  "homepage": "https://github.com/winston-wwzhen/burn-your-money#readme"
29
- }
29
+ }
@@ -0,0 +1,12 @@
1
+ ---
2
+ name: burn-your-money-export
3
+ description: 💾 导出 token 数据(CSV 格式)
4
+ ---
5
+
6
+ # 💾 导出 Token 数据
7
+
8
+ 请执行以下命令导出 token 使用数据(CSV 格式):
9
+
10
+ ```bash
11
+ node ~/.claude/scripts/token-history.js export csv > ~/burn-your-money-export.csv
12
+ ```
@@ -0,0 +1,12 @@
1
+ ---
2
+ name: burn-your-money-stats
3
+ description: 📊 查看 token 使用趋势图
4
+ ---
5
+
6
+ # 📊 Token 使用趋势
7
+
8
+ 请执行以下命令查看过去 7 天的 token 使用趋势图:
9
+
10
+ ```bash
11
+ node ~/.claude/scripts/token-history.js chart
12
+ ```
@@ -0,0 +1,12 @@
1
+ ---
2
+ name: burn-your-money
3
+ description: 💸 查看你的 Claude Code 账单详情
4
+ ---
5
+
6
+ # 💸 Burn Your Money - 账单详情
7
+
8
+ 请执行以下命令查看详细的账单信息:
9
+
10
+ ```bash
11
+ node ~/.claude/scripts/token-history.js detail
12
+ ```
package/src/statusline.js CHANGED
@@ -166,15 +166,14 @@ function main() {
166
166
  const now = Math.floor(Date.now() / 1000);
167
167
  let historyData = readJsonFile(HISTORY_CACHE, {});
168
168
 
169
- // 检查缓存是否过期(30秒)
170
- const cacheAge = now - (historyData._cache_time || 0);
171
- if (cacheAge > 30 || !historyData.total_tokens_all) {
172
- // 缓存过期,重新生成(这里简化处理,实际应该调用 token-history)
173
- historyData = {
174
- total_tokens_all: 0,
175
- total_cost: 0,
176
- _cache_time: now
177
- };
169
+ // 如果缓存不存在或无效,使用默认值(但保留已有数据)
170
+ if (!historyData || typeof historyData !== 'object') {
171
+ historyData = {};
172
+ }
173
+
174
+ // 确保 _cache_time 存在(如果是旧缓存,添加时间戳)
175
+ if (!historyData._cache_time) {
176
+ historyData._cache_time = now;
178
177
  }
179
178
 
180
179
  // 今日数据持久化
@@ -13,6 +13,16 @@ const STATS_CACHE = path.join(os.homedir(), '.claude', 'stats-cache.json');
13
13
  const TODAY = new Date().toISOString().split('T')[0];
14
14
  const CURRENT_MONTH = new Date().toISOString().slice(0, 7); // YYYY-MM
15
15
 
16
+ /**
17
+ * 格式化数字(添加 K/M 后缀)
18
+ */
19
+ function formatNumber(num) {
20
+ if (num >= 1000000000) return (num / 1000000000).toFixed(1) + 'B';
21
+ if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';
22
+ if (num >= 1000) return (num / 1000).toFixed(1) + 'K';
23
+ return num.toString();
24
+ }
25
+
16
26
  /**
17
27
  * 获取本周一的日期
18
28
  */
@@ -224,6 +234,93 @@ function main() {
224
234
  });
225
235
  console.log('');
226
236
  break;
237
+ case 'detail':
238
+ // 详细统计 + 有趣的内容
239
+ console.log('\n' + '='.repeat(50));
240
+ console.log(' 💸 BURN YOUR MONEY - 账单详情 💸');
241
+ console.log('='.repeat(50) + '\n');
242
+
243
+ // 火焰图案
244
+ const fireArt = [
245
+ ' \\ \\ / /',
246
+ ' \\ /',
247
+ ' \\ /',
248
+ ' /\\',
249
+ ' / \\',
250
+ ' / /\\ \\',
251
+ ' / / \\ \\',
252
+ ' ㅤㅤ██ㅤㅤ██',
253
+ ' ㅤㅤ██████ㅤㅤ',
254
+ ' ㅤㅤ████████ㅤㅤ'
255
+ ];
256
+ fireArt.forEach(line => console.log(' ' + line));
257
+ console.log('');
258
+
259
+ // 统计数据
260
+ console.log('📅 今日消费');
261
+ console.log('─'.repeat(40));
262
+ console.log(` Tokens: ${formatNumber(stats.today_tokens)}`);
263
+ console.log(` 费用: $${stats.today_cost}`);
264
+ console.log('');
265
+
266
+ console.log('📆 本周消费');
267
+ console.log('─'.repeat(40));
268
+ console.log(` Tokens: ${formatNumber(stats.week_tokens)}`);
269
+ console.log(` 费用: $${stats.week_cost}`);
270
+ console.log('');
271
+
272
+ console.log('🗓️ 本月消费');
273
+ console.log('─'.repeat(40));
274
+ console.log(` Tokens: ${formatNumber(stats.month_tokens)}`);
275
+ console.log(` 费用: $${stats.month_cost}`);
276
+ console.log('');
277
+
278
+ console.log('💰 历史总计');
279
+ console.log('─'.repeat(40));
280
+ console.log(` Tokens: ${formatNumber(stats.total_tokens_all)}`);
281
+ console.log(` 费用: $${stats.total_cost}`);
282
+ console.log('');
283
+
284
+ // 有趣的统计
285
+ const totalCostNum = parseFloat(stats.total_cost);
286
+ const totalTokensNum = stats.total_tokens_all;
287
+
288
+ console.log('🎯 有趣的统计');
289
+ console.log('─'.repeat(40));
290
+
291
+ // 咖啡数量
292
+ const coffees = Math.floor(totalCostNum / 5);
293
+ console.log(` 这笔钱可以买 ${coffees} 杯咖啡 ☕`);
294
+
295
+ // 午餐数量
296
+ const lunches = Math.floor(totalCostNum / 15);
297
+ console.log(` 或者 ${lunches} 顿午餐 🍱`);
298
+
299
+ // ChatGPT 对比
300
+ const gptEquiv = (totalCostNum / 20).toFixed(1);
301
+ console.log(` 等于 ${gptEquiv} 次 ChatGPT Plus 订阅 🤖`);
302
+
303
+ // 相当于多少本书
304
+ const books = Math.floor(totalCostNum / 20);
305
+ console.log(` 可以买 ${books} 本技术书 📚`);
306
+
307
+ // 每秒烧钱速度
308
+ const costPerToken = 0.000006; // 平均价格
309
+ const burnMessages = [
310
+ ` 你的钱包正在燃烧 🔥`,
311
+ ` Claude 说:谢谢老板 🙏`,
312
+ ` Token 们已经去往了更好的世界 🪦`,
313
+ ` 每一次思考都是金钱的声音 💸`,
314
+ ` 你应该为此感到自豪...或者心痛 💔`
315
+ ];
316
+ const randomMsg = burnMessages[Math.floor(Math.random() * burnMessages.length)];
317
+ console.log(` ${randomMsg}`);
318
+
319
+ console.log('');
320
+ console.log('='.repeat(50));
321
+ console.log(' 🎮 "知识就是财富,而财富就是知识" 🎮');
322
+ console.log('='.repeat(50) + '\n');
323
+ break;
227
324
  default:
228
325
  // summary
229
326
  console.log(JSON.stringify(stats, null, 2));
package/uninstall.js CHANGED
@@ -33,12 +33,9 @@ function uninstallFiles() {
33
33
  path.join(home, '.claude', 'statusline.js'),
34
34
  path.join(home, '.claude', 'scripts', 'token-history.js'),
35
35
  // 命令文件
36
+ path.join(home, '.claude', 'commands', 'burn-your-money.md'),
36
37
  path.join(home, '.claude', 'commands', 'burn-your-money-stats.md'),
37
- path.join(home, '.claude', 'commands', 'burn-your-money-today.md'),
38
- path.join(home, '.claude', 'commands', 'burn-your-money-week.md'),
39
- path.join(home, '.claude', 'commands', 'burn-your-money-month.md'),
40
- path.join(home, '.claude', 'commands', 'burn-your-money-export.md'),
41
- path.join(home, '.claude', 'commands', 'burn-your-money-export-csv.md')
38
+ path.join(home, '.claude', 'commands', 'burn-your-money-export.md')
42
39
  ];
43
40
 
44
41
  log("Removing plugin files...", colors.cyan);