Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 7 additions & 15 deletions plugins/carbon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ You can also manage all of this interactively via Claude Code's built-in `/plugi

After installing, run `/carbon:setup` in any project. It walks you through:

1. **Project name** — defaults to your GitHub repo (e.g., `org/repo`), or set a custom name
2. **Historical sessions** — start fresh or backfill from existing transcript files on disk
3. **Anonymous tracking** — optionally sync metrics to CNaught's API
4. **Display name** — choose a name or get a random one (e.g., "Curious Penguin")
1. **Historical sessions** — start fresh or backfill from existing transcript files on disk
2. **Anonymous tracking** — optionally sync metrics to CNaught's API
3. **Organization** — optionally provide your company or organization name

Setup initializes the SQLite database, configures the CO₂ statusline, and optionally enables background sync. Dependencies are installed automatically on first session start.

Expand All @@ -62,8 +61,7 @@ Setup initializes the SQLite database, configures the CO₂ statusline, and opti
|---------|-------------|
| `/carbon:setup` | Initialize and configure the plugin |
| `/carbon:report` | Generate a carbon emissions report |
| `/carbon:rename-project` | Change the project name (or reset to auto-detect) |
| `/carbon:rename-user` | Change your display name for anonymous tracking |
| `/carbon:rename-user` | Change your organization name for anonymous tracking |
| `/carbon:uninstall` | Remove carbon tracking for the current project |
| `/carbon:cleanup-cache` | Remove old cached plugin versions to free disk space |

Expand All @@ -75,7 +73,7 @@ Generates a report including:
- **Relatable equivalents** — car-years off road, days of home energy usage
- **Usage by model** — breakdown by Claude model with visual progress bars
- **Project breakdown** — top projects from the last 30 days (shown when multiple projects exist)
- **Anonymous sync info** — display name and pending sync count (when sync is enabled)
- **Anonymous sync info** — organization name and pending sync count (when sync is enabled)

### `/carbon:uninstall`

Expand Down Expand Up @@ -121,13 +119,7 @@ Per-model configs (Haiku, Sonnet, Opus) capture GPU power draw, utilization boun

### Project Identification

Projects are identified automatically with this priority:

1. **Custom name** (via `/carbon:setup` or `/carbon:rename-project`) — `<name>_<hash>`
2. **Git remote** — `<org>_<repo>_<hash>` (e.g., `cnaught_claude-code-plugins_a1b2c3d4`)
3. **Local fallback** — `local_<hash>`

The hash is the first 8 characters of SHA-256 of the project path, ensuring uniqueness across machines.
Projects are identified by a hash of the project path — the first 8 characters of SHA-256. This ensures a stable, unique identifier across machines.

## Privacy

Expand All @@ -136,7 +128,7 @@ When session sync is enabled, the following metrics are sent to CNaught's API:
- Token counts (input, output, cache creation, cache read)
- Energy consumption (Wh) and CO₂ emissions (g)
- Models used
- Project identifier (custom display name if provided, otherwise automatically derived from github repository name)
- Project identifier (hash of project path)

**No code, conversation content, or personal information is ever shared.** Sync can be disabled at any time by re-running `/carbon:setup`.

Expand Down
24 changes: 3 additions & 21 deletions plugins/carbon/commands/rename-project.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
# /carbon:rename-project

Update the project name used for carbon tracking.
This command has been removed. Project IDs are now automatically generated from the project path and cannot be customized.

## Instructions

### Step 1: Ask for a new project name
Let the user know that project IDs are now automatically generated as a hash of the project path. There is no need to set or rename project names. Show them their current project ID by running:

Use the `AskUserQuestion` tool to ask what they'd like to name this project. Let them know that by default, the project is identified by the GitHub repo (e.g., `cnaught/claude-code-plugins`) if available, otherwise it falls back to a local hash. They can provide a custom name to override this.

If they want to reset to the default (auto-detected from git), they can say "reset" or "default".

### Step 2: Run the rename-project script

If the user provided a name:
```bash
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-rename-project.ts --name "Their Project Name"
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-setup-check.ts
```

If the user wants to reset to the default:
```bash
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-rename-project.ts --reset
```

Show the output to the user.

## Notes

- Always use the `AskUserQuestion` tool when asking the user a question
14 changes: 4 additions & 10 deletions plugins/carbon/commands/rename-user.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# /carbon:rename-user

Update your display name for anonymous carbon tracking.
Update the organization name for anonymous carbon tracking.

## Instructions

### Step 1: Ask for a new name
### Step 1: Ask for an organization name

Use the `AskUserQuestion` tool to ask what they'd like their new display name to be. Let them know they can also skip to get a new randomly generated name (e.g., "Curious Penguin").
Use the `AskUserQuestion` tool to ask what company or organization name they'd like to use. This is the name associated with their synced sessions.

### Step 2: Run the rename script

If the user provided a name:
```bash
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-rename-user.ts --name "Their Name"
```

If the user wants a random name:
```bash
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-rename-user.ts
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-rename-user.ts --name "Their Organization"
```

Show the output to the user.
Expand Down
33 changes: 12 additions & 21 deletions plugins/carbon/commands/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-setup-check.ts

This outputs JSON. If `isSetup` is `true`, the plugin has already been configured. Show the user their current configuration:
- When they first set up (installedAt)
- Whether sync is enabled and their display name
- Their project name (if custom)
- Whether sync is enabled and their organization name
- Their project ID
- Whether the statusline is active

Then ask the user what they'd like to do:
Expand All @@ -26,37 +26,29 @@ Then ask the user what they'd like to do:

If `isSetup` is `false`, this is a first-time setup — proceed to Step 1.

### Step 1: Ask about project name

Ask the user if they'd like to set a custom project name. Let them know:
- By default, the project is identified by the GitHub repo (e.g., `cnaught/claude-code-plugins`) if available
- Otherwise, it falls back to a local hash
- They can provide a custom name to override this, or skip to use the default

### Step 2: Ask about historical sessions
### Step 1: Ask about historical sessions

Ask the user whether they want to:
- **Start fresh** — only track new sessions going forward
- **Backfill** — process all previous Claude Code sessions from transcript files on disk

### Step 3: Ask about anonymous tracking
### Step 2: Ask about anonymous tracking

Ask the user whether they want to enable anonymous carbon tracking with CNaught:
- **Enable** — session metrics (token counts, CO₂, energy, project path) will be synced to CNaught's API. No code, conversations, or personal information is shared. (default)
- **Enable** — session metrics (token counts, CO₂, energy, project ID) will be synced to CNaught's API. No code, conversations, or personal information is shared. (default)
- **Disable** — all data stays local only

If the user kept sync enabled (the default), ask them for an optional display name (DO NOT refer to a leaderboard as there is no such thing). Let them know that if they skip this, a fun random name will be generated for them (e.g., "Curious Penguin", "Swift Falcon").
If the user kept sync enabled (the default), ask them for their company or organization name (free text, **required**). This is used to group users into teams and identify their sessions when syncing to CNaught. They cannot skip this — organization is required for sync.

### Step 4: Run the setup script
### Step 3: Run the setup script

Build the command with the appropriate flags based on the user's choices:
- Add `--backfill` if the user chose to backfill historical sessions
- Add `--disable-sync` if the user chose to disable anonymous tracking
- Add `--user-name "Their Name"` if the user provided a custom display name
- Add `--project-name "Their Project Name"` if the user provided a custom project name
- Add `--organization "Their Org"` if the user provided an organization name

```bash
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-setup.ts [--backfill] [--disable-sync] [--user-name "Name"] [--project-name "Project"]
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-setup.ts [--backfill] [--disable-sync] [--organization "Org Name"]
```

This will:
Expand All @@ -65,13 +57,13 @@ This will:
- Configure `~/.claude/settings.json` to enable the CO₂ statusline (active across all projects)
- (If `--backfill`) Process historical transcript files into the database
- (Unless `--disable-sync`) Generate a random identity and enable background sync to CNaught API
- (If `--project-name`) Store the custom project name in the database
- (If `--organization`) Store the organization name in the database

### Step 5: Check for local statusline overrides
### Step 4: Check for local statusline overrides

After the setup script runs, check if the current project has a `.claude/settings.local.json` or `.claude/settings.json` file that contains its own `statusLine` entry. If it does, warn the user that this local statusline will override the global carbon statusline, and the CO₂ indicator won't appear in this project. Offer to remove the `statusLine` key from the local file to fix it.

### Step 6: Verify setup
### Step 5: Verify setup

```bash
npx -y bun ${CLAUDE_PLUGIN_ROOT}/src/scripts/carbon-report.ts
Expand All @@ -85,5 +77,4 @@ Show the output to the user and confirm that the database is initialized, the st
- The statusline shows real-time CO₂ estimates in the Claude Code status bar across all projects
- Sessions are tracked automatically via hooks — no manual action needed
- If sync is enabled, data syncs in the background after each response (non-blocking)
- Use `/carbon:rename-project` to change the project name later
- Always use the `AskUserQuestion` tool when asking the user a question
37 changes: 18 additions & 19 deletions plugins/carbon/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
"name": "@cnaught-inc/claude-code-carbon",
"version": "2.5.6",
"private": true,
"description": "Claude Code plugin for tracking carbon emissions from AI usage",
"scripts": {
"typecheck": "tsc --noEmit",
"test": "bun test"
},
"dependencies": {
"unique-names-generator": "^4.7.1",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.12",
"@types/bun": "latest",
"@types/node": "^20.17.9",
"better-sqlite3": "^11.0.0",
"typescript": "5.9.3"
}
"name": "@cnaught-inc/claude-code-carbon",
"version": "2.5.6",
"private": true,
"description": "Claude Code plugin for tracking carbon emissions from AI usage",
"scripts": {
"typecheck": "tsc --noEmit",
"test": "bun test"
},
"dependencies": {
"zod": "^3.25.76"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.12",
"@types/bun": "latest",
"@types/node": "^20.17.9",
"better-sqlite3": "^11.0.0",
"typescript": "5.9.3"
}
}
Loading