Commit c6337cf
fix(config): don't require .claude directory for non-Claude agents (#1017)
* fix(config): don't require .claude directory for non-Claude agents
ccusage now supports codex, opencode, amp, and pi-agent in addition to
Claude Code. Running it on a machine without a Claude data directory
crashed with "No valid Claude data directories found" because
getConfigSearchPaths() called the throwing getClaudePaths() while
discovering ccusage.json locations.
Treat Claude config dirs as best-effort: swallow the error and fall back
to the local .ccusage directory so users of other agents (or no agent
yet) can run ccusage without setting CLAUDE_CONFIG_DIR.
Fixes #1014
* refactor(claude): split getClaudePaths into safe/required variants
Previously getClaudePaths() threw when no Claude data directory was found,
which forced callers that don't actually need a Claude dir (like config
discovery in getConfigSearchPaths) to wrap the call in try/catch or
Result.try. That asymmetry is what made #1014 easy to hit in the first
place.
Make getClaudePaths() the unsurprising "give me what you find, possibly
nothing" variant, and add requireClaudePaths() for explicit Claude-only
entry points (claude:* command loaders, statusline session lookup) that
want to surface the helpful setup hint when no data exists. debug.ts
already had its own length check so it keeps using getClaudePaths().
The config layer now just calls getClaudePaths() directly — no wrapping
needed — restoring the consistency with the other agents' detect
functions and getClaudeProjectPaths().
No behavior change for users:
- `ccusage` on a machine without .claude still runs and reports "None"
- `ccusage claude daily` without .claude still surfaces the original
"No valid Claude data directories found" error
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4103209 commit c6337cf
2 files changed
Lines changed: 60 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
254 | 258 | | |
255 | 259 | | |
256 | | - | |
| 260 | + | |
257 | 261 | | |
258 | 262 | | |
259 | 263 | | |
| |||
276 | 280 | | |
277 | 281 | | |
278 | 282 | | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 283 | + | |
| 284 | + | |
288 | 285 | | |
289 | 286 | | |
290 | 287 | | |
| |||
307 | 304 | | |
308 | 305 | | |
309 | 306 | | |
310 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
311 | 324 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
| 325 | + | |
| 326 | + | |
316 | 327 | | |
317 | 328 | | |
318 | 329 | | |
319 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
320 | 336 | | |
321 | 337 | | |
322 | 338 | | |
| |||
2271 | 2287 | | |
2272 | 2288 | | |
2273 | 2289 | | |
2274 | | - | |
| 2290 | + | |
2275 | 2291 | | |
2276 | 2292 | | |
2277 | 2293 | | |
| |||
2407 | 2423 | | |
2408 | 2424 | | |
2409 | 2425 | | |
2410 | | - | |
| 2426 | + | |
2411 | 2427 | | |
2412 | 2428 | | |
2413 | 2429 | | |
| |||
2596 | 2612 | | |
2597 | 2613 | | |
2598 | 2614 | | |
2599 | | - | |
| 2615 | + | |
2600 | 2616 | | |
2601 | 2617 | | |
2602 | 2618 | | |
| |||
2846 | 2862 | | |
2847 | 2863 | | |
2848 | 2864 | | |
2849 | | - | |
| 2865 | + | |
2850 | 2866 | | |
2851 | 2867 | | |
2852 | 2868 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | | - | |
78 | | - | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| |||
622 | 625 | | |
623 | 626 | | |
624 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
625 | 645 | | |
626 | 646 | | |
627 | 647 | | |
| |||
0 commit comments