Skip to content

Commit 8e5bfb0

Browse files
authored
feat!: migrate project aliases from env var to config file (#555)
1 parent 09acb0c commit 8e5bfb0

File tree

8 files changed

+83
-216
lines changed

8 files changed

+83
-216
lines changed

ccusage.example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"commands": {
1212
"daily": {
1313
"instances": true,
14-
"order": "desc"
14+
"order": "desc",
15+
"projectAliases": "ccusage=Usage Tracker,my-long-project-name=Project X"
1516
},
1617
"monthly": {
1718
"breakdown": true

config-schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@
219219
"type": "string",
220220
"description": "Filter to specific project name",
221221
"markdownDescription": "Filter to specific project name"
222+
},
223+
"projectAliases": {
224+
"type": "string",
225+
"description": "Comma-separated project aliases (e.g., 'ccusage=Usage Tracker,myproject=My Project')",
226+
"markdownDescription": "Comma-separated project aliases (e.g., 'ccusage=Usage Tracker,myproject=My Project')"
222227
}
223228
},
224229
"additionalProperties": false

docs/guide/configuration.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Settings are applied in this priority order (highest to lowest):
1717

1818
1. **Command-line arguments** (e.g., `--json`, `--offline`)
1919
2. **Custom config file** (via `--config` flag)
20-
3. **Environment variables** (e.g., `CLAUDE_CONFIG_DIR`)
20+
3. **Environment variables** (e.g., `CLAUDE_CONFIG_DIR`, `LOG_LEVEL`)
2121
4. **Local project config** (`.ccusage/ccusage.json`)
2222
5. **User config** (`~/.config/claude/ccusage.json`)
2323
6. **Legacy config** (`~/.claude/ccusage.json`)
@@ -173,10 +173,20 @@ Analyze usage by project:
173173

174174
- **Instances**: Group by project with `--instances`
175175
- **Project Filter**: Focus on specific project with `--project`
176-
- **Aliases**: Set custom names via `CCUSAGE_PROJECT_ALIASES`
176+
- **Aliases**: Set custom names via configuration file
177+
178+
```json
179+
// .ccusage/ccusage.json
180+
{
181+
"commands": {
182+
"daily": {
183+
"projectAliases": "uuid-123=My App,long-name=Backend"
184+
}
185+
}
186+
}
187+
```
177188

178189
```bash
179-
export CCUSAGE_PROJECT_ALIASES="uuid-123=My App"
180190
ccusage daily --instances --project "My App"
181191
```
182192

docs/guide/daily-reports.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,28 @@ ccusage daily --instances --json > project-analysis.json
244244

245245
### Team Usage Analysis
246246

247-
```bash
248-
# Set custom project names for better reporting
249-
export CCUSAGE_PROJECT_ALIASES="uuid-project=Frontend App,long-name=Backend API"
247+
Use project aliases to replace cryptic or long project directory names with readable labels:
248+
249+
```json
250+
// .ccusage/ccusage.json - Set custom project names for better reporting
251+
{
252+
"commands": {
253+
"daily": {
254+
"projectAliases": "uuid-project=Frontend App,long-name=Backend API"
255+
}
256+
}
257+
}
258+
```
250259

260+
The `projectAliases` setting uses a comma-separated format of `original-name=display-name` pairs. This is especially useful when:
261+
- Your projects have UUID-based names (e.g., `a2cd99ed-a586=My App`)
262+
- Directory names are long paths that get truncated
263+
- You want consistent naming across team reports
264+
265+
```bash
251266
# Generate team report with readable project names
252267
ccusage daily --instances --since 20250601
268+
# Now shows "Frontend App" instead of "uuid-project"
253269
```
254270

255271
## Tips

docs/guide/environment-variables.md

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -130,79 +130,6 @@ LOG_LEVEL=5 ccusage daily --debug
130130
LOG_LEVEL=0 ccusage monthly --json | python analyze.py
131131
```
132132

133-
## CCUSAGE_PROJECT_ALIASES
134-
135-
Configure custom display names for project directories. This is useful for replacing cryptic directory names with human-readable aliases.
136-
137-
### Format
138-
139-
Use comma-separated `raw-name=alias` pairs:
140-
141-
```bash
142-
export CCUSAGE_PROJECT_ALIASES="long-project-name=Short Name,uuid-project=My Project"
143-
```
144-
145-
### Examples
146-
147-
#### UUID Projects
148-
149-
Replace cryptic UUIDs with readable names:
150-
151-
```bash
152-
# Without aliases
153-
ccusage daily --instances
154-
# Shows: a2cd99ed-a586-4fe4-8f59-b0026409ec09
155-
156-
# With aliases
157-
export CCUSAGE_PROJECT_ALIASES="a2cd99ed-a586-4fe4-8f59-b0026409ec09=Production API"
158-
ccusage daily --instances
159-
# Shows: Production API
160-
```
161-
162-
#### Long Directory Names
163-
164-
Shorten verbose directory names for better display:
165-
166-
```bash
167-
export CCUSAGE_PROJECT_ALIASES="-Users-john-Development-my-app=My App"
168-
ccusage daily --instances
169-
```
170-
171-
#### Multiple Projects
172-
173-
Set aliases for multiple projects:
174-
175-
```bash
176-
export CCUSAGE_PROJECT_ALIASES="project1=Frontend,project2=Backend,project3=Database"
177-
ccusage session
178-
```
179-
180-
### Automatic Formatting
181-
182-
ccusage automatically formats complex project names even without aliases:
183-
184-
**Automatic Cleanup:**
185-
- Strips common directory prefixes
186-
- Shortens long UUIDs to last two segments
187-
- Extracts meaningful names from complex paths
188-
189-
**Examples:**
190-
```
191-
# Original → Formatted
192-
-Users-phaedrus-Development-adminifi-edugakko-api--feature-ticket-002-configure-dependabot
193-
→ configure-dependabot
194-
195-
a2cd99ed-a586-4fe4-8f59-b0026409ec09
196-
→ 8f59-b0026409ec09
197-
198-
/Users/john/Development/my-app
199-
→ my-app
200-
```
201-
202-
**Priority Order:**
203-
1. Custom aliases (via `CCUSAGE_PROJECT_ALIASES`)
204-
2. Automatic formatting
205-
3. Original name (fallback)
206133

207134
## Additional Environment Variables
208135

@@ -255,31 +182,27 @@ Add to your shell configuration file:
255182
```bash
256183
export CLAUDE_CONFIG_DIR="$HOME/.config/claude"
257184
export LOG_LEVEL=3
258-
export CCUSAGE_PROJECT_ALIASES="project1=MyApp,project2=API"
259185
```
260186

261187
#### Zsh (~/.zshrc)
262188

263189
```zsh
264190
export CLAUDE_CONFIG_DIR="$HOME/.config/claude"
265191
export LOG_LEVEL=3
266-
export CCUSAGE_PROJECT_ALIASES="project1=MyApp,project2=API"
267192
```
268193

269194
#### Fish (~/.config/fish/config.fish)
270195

271196
```fish
272197
set -x CLAUDE_CONFIG_DIR "$HOME/.config/claude"
273198
set -x LOG_LEVEL 3
274-
set -x CCUSAGE_PROJECT_ALIASES "project1=MyApp,project2=API"
275199
```
276200

277201
#### PowerShell (Profile.ps1)
278202

279203
```powershell
280204
$env:CLAUDE_CONFIG_DIR = "$env:USERPROFILE\.config\claude"
281205
$env:LOG_LEVEL = "3"
282-
$env:CCUSAGE_PROJECT_ALIASES = "project1=MyApp,project2=API"
283206
```
284207

285208
## Precedence

src/_consts.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,6 @@ export const DEFAULT_CLAUDE_CONFIG_PATH = `${XDG_CONFIG_DIR}/claude`;
6767
*/
6868
export const CLAUDE_CONFIG_DIR_ENV = 'CLAUDE_CONFIG_DIR';
6969

70-
/**
71-
* Environment variable for custom project name aliases
72-
*
73-
* Allows users to configure readable display names for cryptic or long project directory names.
74-
* This is particularly useful for:
75-
* - UUID-based project directories generated by Claude Code
76-
* - Long path-based project names that are hard to read in tables
77-
* - Custom branding of project names for organizational consistency
78-
*
79-
* Format: "raw-name=alias,another-name=other-alias"
80-
* Example: "a2cd99ed-a586-4fe4-8f59-b0026409ec09=My Project,long-project-name=Short"
81-
*
82-
* Environment variable approach is used because:
83-
* - No config file needed - simple and lightweight configuration
84-
* - Works in any shell/environment without file management
85-
* - Easy to set temporarily for specific invocations
86-
* - Follows Unix conventions for tool configuration
87-
* - Doesn't require file system permissions or config directory setup
88-
*
89-
* Used to override display names for project directories in all output formats.
90-
*/
91-
export const PROJECT_ALIASES_ENV = 'CCUSAGE_PROJECT_ALIASES';
92-
9370
/**
9471
* Claude projects directory name within the data directory
9572
* Contains subdirectories for each project with usage data

0 commit comments

Comments
 (0)