claude-carbon 1.1.1 → 1.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.
Files changed (2) hide show
  1. package/README.md +99 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -3,9 +3,13 @@
3
3
  [![GitHub stars](https://img.shields.io/github/stars/gwittebolle/claude-carbon)](https://github.com/gwittebolle/claude-carbon/stargazers)
4
4
  [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
5
5
  [![GitHub release](https://img.shields.io/github/v/release/gwittebolle/claude-carbon)](https://github.com/gwittebolle/claude-carbon/releases)
6
+ [![npm](https://img.shields.io/npm/v/claude-carbon)](https://www.npmjs.com/package/claude-carbon)
7
+ [![CI](https://github.com/gwittebolle/claude-carbon/actions/workflows/ci.yml/badge.svg)](https://github.com/gwittebolle/claude-carbon/actions/workflows/ci.yml)
6
8
 
7
9
  Track the carbon footprint of your Claude Code sessions.
8
10
 
11
+ ![Live CO2 in the Claude Code status line](docs/demo.gif)
12
+
9
13
  **1. Install (or update):**
10
14
 
11
15
  ```bash
@@ -67,6 +71,9 @@ bash ~/code/claude-carbon/scripts/generate-report.sh --since 2026-03-01
67
71
 
68
72
  # All time
69
73
  bash ~/code/claude-carbon/scripts/generate-report.sh --all
74
+
75
+ # A closed period (--until is an exclusive upper bound: this one stops at June 30th)
76
+ bash ~/code/claude-carbon/scripts/generate-report.sh --since 2026-01-01 --until 2026-07-01
70
77
  ```
71
78
 
72
79
  </details>
@@ -75,9 +82,30 @@ bash ~/code/claude-carbon/scripts/generate-report.sh --all
75
82
  <summary>Custom install directory</summary>
76
83
 
77
84
  ```bash
78
- CLAUDE_CARBON_DIR=~/my-path/claude-carbon curl -fsSL https://raw.githubusercontent.com/gwittebolle/claude-carbon/main/install.sh | bash
85
+ curl -fsSL https://raw.githubusercontent.com/gwittebolle/claude-carbon/main/install.sh | CLAUDE_CARBON_DIR=~/my-path/claude-carbon bash
79
86
  ```
80
87
 
88
+ The env var has to sit on the `bash` side of the pipe, not the `curl` side, or the installer never sees it.
89
+
90
+ </details>
91
+
92
+ <details>
93
+ <summary>Second Claude environment (CLAUDE_CONFIG_DIR)</summary>
94
+
95
+ If you run a second Claude Code environment out of its own config directory, e.g.
96
+
97
+ ```bash
98
+ alias claude-work="CLAUDE_CONFIG_DIR=~/.claude-work claude"
99
+ ```
100
+
101
+ install claude-carbon into that same directory by passing `CLAUDE_CONFIG_DIR` to the installer:
102
+
103
+ ```bash
104
+ curl -fsSL https://raw.githubusercontent.com/gwittebolle/claude-carbon/main/install.sh | CLAUDE_CONFIG_DIR=~/.claude-work bash
105
+ ```
106
+
107
+ The status line, the hooks, the database and the `/carbon-*` commands all live under that config dir, so each environment tracks its own sessions independently. When `CLAUDE_CONFIG_DIR` is unset everything falls back to `~/.claude` as before.
108
+
81
109
  </details>
82
110
 
83
111
  <details>
@@ -86,9 +114,10 @@ CLAUDE_CARBON_DIR=~/my-path/claude-carbon curl -fsSL https://raw.githubuserconte
86
114
  ```bash
87
115
  git clone https://github.com/gwittebolle/claude-carbon.git ~/code/claude-carbon
88
116
  bash ~/code/claude-carbon/scripts/setup.sh
117
+ bash ~/code/claude-carbon/scripts/configure-settings.sh
89
118
  ```
90
119
 
91
- Then add to `~/.claude/settings.json`:
120
+ The second script merges the block below into `~/.claude/settings.json` (additively: an existing status line or third-party hooks are left alone) and symlinks the `/carbon-*` commands. To wire it by hand instead, skip it and add:
92
121
 
93
122
  ```json
94
123
  {
@@ -107,11 +136,24 @@ Then add to `~/.claude/settings.json`:
107
136
  }
108
137
  ]
109
138
  }
139
+ ],
140
+ "SessionStart": [
141
+ {
142
+ "matcher": "",
143
+ "hooks": [
144
+ {
145
+ "type": "command",
146
+ "command": "~/code/claude-carbon/scripts/safety-rescan.sh"
147
+ }
148
+ ]
149
+ }
110
150
  ]
111
151
  }
112
152
  }
113
153
  ```
114
154
 
155
+ The `Stop` hook records the session that just ended. The `SessionStart` one re-scans for sessions that hook missed (crash, kill) and drives the daily update check the status line reads; without it you are never told a new version exists.
156
+
115
157
  Restart Claude Code.
116
158
 
117
159
  </details>
@@ -120,9 +162,9 @@ Restart Claude Code.
120
162
 
121
163
  claude-carbon measures one developer's sessions, locally. If the question comes from your CTO, a client RFP or a CSR committee, the same methodology exists as a hosted layer:
122
164
 
123
- - [Free calculator and per-model factor sheets](https://tokenclimate.com/calculator) - the exact versioned factors of this repo, browsable.
124
- - [Bilan IA](https://tokenclimate.com/bilan) - a self-serve, shareable report of your organisation's real Claude usage (cost, CO2e, water, energy), generated in minutes from an Anthropic admin key. The key is never stored; the methodology annex is citation-ready.
125
- - [TokenClimate](https://tokenclimate.com) - hosted team dashboards. Both sides share this repo's golden vectors, verified weekly in CI.
165
+ - [Free calculator](https://tokenclimate.com/en/calculator?ref=github) and [per-model factor sheets](https://tokenclimate.com/en/models?ref=github) - the exact versioned factors of this repo, browsable.
166
+ - [AI usage report](https://tokenclimate.com/bilan/en?ref=github) - a self-serve, shareable report of your organisation's real Claude usage (cost, CO2e, water, energy), generated in minutes from an Anthropic admin key. The key is never stored; the methodology annex is citation-ready.
167
+ - [TokenClimate](https://tokenclimate.com/en?ref=github) - hosted team dashboards. Both sides share this repo's golden vectors, verified weekly in CI.
126
168
 
127
169
  The only places the OSS points there are a one-line footer in `/carbon-report` and a small credit on the `/carbon-card` PNGs. No status-line promo, no email capture: nothing leaves your machine.
128
170
 
@@ -171,15 +213,25 @@ bash scripts/recompute.sh
171
213
  | `safety-rescan.sh` | SessionStart hook (throttled background re-scan, catches missed sessions) |
172
214
  | `backfill.sh` | Re-parse all historical JSONL transcripts (incl. subagents) |
173
215
  | `recompute.sh` | Re-derive cost/CO2 from stored tokens after a price/factor change (no transcripts needed) |
174
- | `generate-report.sh` | Export PNG report cards (CLI, with `--since` / `--all`) |
216
+ | `generate-report.sh` | Export PNG report cards (CLI, with `--since` / `--until` / `--all`) |
175
217
 
176
218
  Note: backfill now derives project names from the transcript's `cwd` (matching the live hook). Sessions backfilled before this change keep their old, possibly truncated names; delete those rows and re-run `backfill.sh` to normalize them.
177
219
 
178
220
  </details>
179
221
 
222
+ ## Using with ccstatusline
223
+
224
+ Claude Code accepts a single `statusLine` command, so claude-carbon's full status line and [ccstatusline](https://github.com/sirmalloc/ccstatusline) cannot run side by side. If ccstatusline drives your status line, embed the CO2 segment instead: in the ccstatusline TUI, add a `Custom Command` widget pointing to
225
+
226
+ ```
227
+ ~/code/claude-carbon/scripts/statusline.sh --segment
228
+ ```
229
+
230
+ (adjust the path if you installed with `CLAUDE_CARBON_DIR`). The widget receives the same status JSON on stdin and prints just the cost + CO2 pair, e.g. `$0.68 · 35g CO₂`. Segment mode never touches the network. Recording to the local database is unaffected either way: persistence runs from hooks, not from the status line.
231
+
180
232
  ## Emission factors
181
233
 
182
- Factors from [Jegham et al. 2025](https://arxiv.org/abs/2505.09598), a peer-reviewed study measuring energy consumption of LLM inference on AWS infrastructure.
234
+ Factors from [Jegham et al. 2025](https://arxiv.org/abs/2505.09598), an arXiv preprint that estimates the energy consumption of LLM inference on AWS infrastructure from public API performance data (latency, throughput) over inferred hardware configurations.
183
235
 
184
236
  | Model | Input (gCO2e/Mtok) | Output (gCO2e/Mtok) | Basis |
185
237
  | ------ | ------------------ | ------------------- | -------------------------- |
@@ -190,12 +242,14 @@ Factors from [Jegham et al. 2025](https://arxiv.org/abs/2505.09598), a peer-revi
190
242
 
191
243
  **Important: these are order-of-magnitude estimates, not precise measurements.**
192
244
 
193
- - Sonnet factors are a 3-point least-squares fit to the three measured Claude 3.7 Sonnet per-query energies in Jegham et al. v6 (0.950 / 2.989 / 5.671 Wh), giving a ~21:1 output:input ratio. The value is cross-validated against [EcoLogits](https://ecologits.ai): its independent estimate for Sonnet brackets the same range. Fable, Opus and Haiku are extrapolated (no public data from Anthropic on per-model energy consumption); Opus = 2x Sonnet matches both the current EcoLogits Opus 4.5+ parameter ratio and the Anthropic price ratio (honest band 2x-5x).
245
+ - Sonnet factors are a 3-point least-squares fit to the three Claude 3.7 Sonnet per-query energies estimated in Jegham et al. v6 (0.950 / 2.989 / 5.671 Wh), giving a ~21:1 output:input ratio. The value is consistent with [EcoLogits](https://ecologits.ai): its independent estimate for Sonnet brackets the same range (a wide band, so this is a consistency check, not proof). Fable, Opus and Haiku are extrapolated (no public data from Anthropic on per-model energy consumption); Opus = 2x Sonnet matches both the current EcoLogits Opus 4.5+ parameter ratio and the Anthropic price ratio (honest band 2x-5x).
194
246
  - Sessions run on non-Anthropic models (e.g. local models behind `ANTHROPIC_BASE_URL`) are stored with their raw tokens but zero cost/CO2 and excluded from reports - a datacenter factor doesn't apply to them. Add patterns to `exclude_models` in `data/factors.json` to exclude more models by name.
195
247
  - Cache read tokens are counted at a reduced factor (default 0.08 of an input token, set in `data/factors.json`). A cached token skips prefill compute but still incurs decode-phase memory reads, so it is cheap but not free. This is an engineering estimate derived from the literature, not Anthropic's 0.1x billing ratio. See [METHODOLOGY.md](METHODOLOGY.md).
196
248
  - Carbon intensity uses the AWS region grid (location-based, 0.287 kgCO2e/kWh), not real-time grid data. This sits at the low end of the location-based range; the US national average is ~380 g/kWh.
197
249
  - Anthropic does not publish Scope 1, 2, or 3 emissions. These estimates are independent and based on academic research, not provider data.
198
250
 
251
+ Report equivalences follow your locale, since a car and a kWh differ by ~2x between countries: ADEME/SNCF factors on a French or undetected locale, EPA ones in miles on a US locale, world-average ones otherwise (200 gCO2/km by car, 8.7 g per smartphone charge). Force a set with `CLAUDE_CARBON_LOCALE` (`fr`, `us`, `world`, or any locale string). The factors live in `data/factors.json` under `equivalences`.
252
+
199
253
  Factors are editable in `data/factors.json`. See [METHODOLOGY.md](METHODOLOGY.md) for the full scientific basis, formula, and equivalences.
200
254
 
201
255
  ### Golden vectors
@@ -239,7 +293,7 @@ Measuring is step one. Here are concrete levers to reduce your AI carbon footpri
239
293
 
240
294
  ### Use the right model for the task
241
295
 
242
- Output tokens cost ~21x more energy than input tokens (the marginal output:input ratio from Jegham v6). Opus consumes ~2x more than Sonnet per token.
296
+ Output tokens cost ~21x more energy than input tokens (the marginal output:input ratio fit on Jegham v6). Opus is estimated at ~2x Sonnet per token (uncertainty band 2x-5x, see METHODOLOGY.md).
243
297
 
244
298
  ```json
245
299
  {
@@ -249,7 +303,7 @@ Output tokens cost ~21x more energy than input tokens (the marginal output:input
249
303
  }
250
304
  ```
251
305
 
252
- Use Opus for architecture and planning. Sonnet for daily work. Haiku for subagents (exploration, file reading, reviews). This alone can cut your emissions by 60%.
306
+ Use Opus for architecture and planning. Sonnet for daily work. Haiku for subagents (exploration, file reading, reviews). As an indicative estimate with this tool's factors, this alone can cut your emissions by up to ~60% vs all-Opus.
253
307
 
254
308
  ### Install RTK (Rust Token Killer)
255
309
 
@@ -284,6 +338,16 @@ By default, Claude Code compacts context at 95% usage. Compacting earlier keeps
284
338
  }
285
339
  ```
286
340
 
341
+ ### Disconnect unused MCP servers
342
+
343
+ Every connected MCP server ships its full tool schemas into the context window with every request, whether the session uses them or not. Most of that overhead is served from prompt cache after the first turn, and cache reads carry a much lower energy factor (see METHODOLOGY.md), so the saving per turn is modest; the gain comes from repetition across every turn of every session.
344
+
345
+ ```bash
346
+ claude mcp list
347
+ ```
348
+
349
+ Keep the servers the project actually uses, remove the rest with `claude mcp remove <name>`.
350
+
287
351
  ### Write concise instructions
288
352
 
289
353
  Add to your project's CLAUDE.md:
@@ -296,18 +360,27 @@ Output tokens are the most expensive in both cost and energy.
296
360
 
297
361
  ### Combined impact
298
362
 
299
- | Lever | Estimated reduction |
300
- | -------------------- | ----------------------- |
301
- | Right model per task | -60% vs all-Opus |
302
- | RTK | -70% on CLI tokens |
303
- | Thinking cap at 10k | -70% on thinking tokens |
304
- | Haiku subagents | -80% on exploration |
305
- | **All combined** | **-50 to 70% total** |
363
+ These reductions are indicative estimates, not measurements on a benchmark workload. The RTK figure comes from RTK's own documentation. The Haiku rows follow from this tool's own factors (Haiku = 0.5x Sonnet = 0.25x Opus per token): -50% when your subagents would otherwise run Sonnet, -75% when they would run Opus. They inherit the 0.5x extrapolation, the widest uncertainty band in the tool (see METHODOLOGY.md); if most of your usage is already Haiku, your absolute total rides on that band, so read it as an order of magnitude.
364
+
365
+ | Lever | Estimated reduction |
366
+ | -------------------- | ---------------------------- |
367
+ | Right model per task | -60% vs all-Opus |
368
+ | RTK | -70% on CLI tokens |
369
+ | Thinking cap at 10k | -70% on thinking tokens |
370
+ | Haiku subagents | -75% vs Opus, -50% vs Sonnet |
371
+ | **All combined** | **-50 to 70% total** |
372
+
373
+ ### Related projects
374
+
375
+ - [EcoLogits](https://ecologits.ai) - Python library estimating the footprint of GenAI API calls across providers.
376
+ - [CodeCarbon](https://github.com/mlco2/codecarbon) - measures the emissions of compute you run yourself (training, local inference).
377
+ - [ImpactIA](https://github.com/SNCFdevelopers/ImpactIA) - AI impact calculator and guide by SNCF, Wavestone and Resilio.
378
+ - [green-claude](https://github.com/Institut-du-Numerique-Responsable/green-claude) - Claude Code skill that steers generated code toward eco-design rules (RGESN, GR491).
306
379
 
307
380
  ### Further reading
308
381
 
309
382
  - [IEA - Energy and AI (2025)](https://www.iea.org/reports/energy-and-ai/) - data center projections
310
- - [Jegham et al. - How Hungry is AI?](https://arxiv.org/abs/2505.09598) - per-model energy measurements
383
+ - [Jegham et al. - How Hungry is AI?](https://arxiv.org/abs/2505.09598) - per-model energy estimates
311
384
  - [UCL/UNESCO - 90% AI energy reduction](https://www.ucl.ac.uk/news/2025/jul/practical-changes-could-reduce-ai-energy-demand-90) - frugal AI approaches
312
385
  - [GreenIT.fr - AI impacts 2025-2030](https://www.greenit.fr/impacts-ia-monde-2025-2030-rapport/) - French data
313
386
 
@@ -315,6 +388,14 @@ Output tokens are the most expensive in both cost and energy.
315
388
 
316
389
  Every Claude Code session uses real compute, real energy, real emissions. The number is small per query, but it adds up. Making it visible is the first step to owning it.
317
390
 
391
+ ## Citing
392
+
393
+ If claude-carbon's numbers or methodology end up in your article, talk or product, a citation is appreciated. GitHub's "Cite this repository" button generates BibTeX/APA from [CITATION.cff](CITATION.cff). Short form:
394
+
395
+ > Wittebolle, G. (2026). claude-carbon: carbon footprint tracker for Claude Code sessions. https://github.com/gwittebolle/claude-carbon
396
+
397
+ The shareable report cards already carry this attribution in their footer, so reposting a card as-is credits the tool.
398
+
318
399
  ## Open source
319
400
 
320
401
  claude-carbon is free and open source under the [MIT license](LICENSE). Contributions welcome.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-carbon",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "Track the carbon footprint of your Claude Code sessions",
5
5
  "bin": {
6
6
  "claude-carbon": "bin/claude-carbon.js"