Skip to content

Commit ea3eb64

Browse files
authored
fix!: add offline mode support to statusline command (ccusage#471)
* fix\!: add offline mode support to statusline command BREAKING CHANGE: statusline command now accepts CLI arguments - Add --offline flag to statusline command for cached pricing data usage - Pass offline flag to all data loading functions (loadSessionUsageById, loadDailyUsageData, loadSessionBlockData) - Update documentation with offline mode configuration examples - Enables faster performance without network dependencies to LiteLLM API This is a breaking change as the statusline command signature has changed from accepting no arguments to accepting the --offline flag. However, existing configurations will continue to work without modification. * fix\!: make offline mode default for statusline command BREAKING CHANGE: statusline now defaults to offline mode for better performance - Set offline mode as default (true) for statusline command - Update documentation to reflect offline as default behavior - Users can opt-in to online mode with --no-offline flag - Provides instant response times without network latency This change prioritizes performance for the statusline which needs to be responsive. The cached pricing data is sufficient for most use cases and eliminates network dependencies. * simplified test statusline
1 parent 4bfca72 commit ea3eb64

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

docs/guide/statusline.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ Add this to your `~/.claude/settings.json` or `~/.config/claude/settings.json`:
2828
}
2929
```
3030

31+
By default, statusline uses **offline mode** with cached pricing data for optimal performance.
32+
33+
### Online Mode (Optional)
34+
35+
If you need the latest pricing data from LiteLLM API, you can explicitly enable online mode:
36+
37+
```json
38+
{
39+
"statusLine": {
40+
"type": "command",
41+
"command": "bun x ccusage statusline --no-offline", // Fetches latest pricing from API
42+
"padding": 0
43+
}
44+
}
45+
```
46+
3147
## Output Format
3248

3349
The statusline displays a compact, single-line summary:
@@ -59,6 +75,8 @@ The statusline command:
5975
- Identifies the active 5-hour billing block
6076
- Calculates real-time burn rates and projections
6177
- Outputs a single line suitable for status bar display
78+
- **Uses offline mode by default** for instant response times without network dependencies
79+
- Can be configured to use online mode with `--no-offline` for latest pricing data
6280

6381
## Beta Notice
6482

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
"release": "bun lint && bun typecheck && vitest run && bun run build && bumpp",
5353
"start": "bun run ./src/index.ts",
5454
"test": "TZ=UTC vitest",
55-
"test:statusline": "cat test/statusline-test.json | bun run ./src/index.ts statusline",
56-
"test:statusline:dev": "cat test/statusline-test.json | bun run start statusline",
55+
"test:statusline": "cat test/statusline-test.json | bun run start statusline",
5756
"typecheck": "tsgo --noEmit"
5857
},
5958
"devDependencies": {

src/commands/statusline.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import getStdin from 'get-stdin';
33
import { define } from 'gunshi';
44
import pc from 'picocolors';
55
import { calculateBurnRate } from '../_session-blocks.ts';
6+
import { sharedArgs } from '../_shared-args.ts';
67
import { statuslineHookJsonSchema } from '../_types.ts';
78
import { formatCurrency } from '../_utils.ts';
89
import { calculateTotals } from '../calculate-cost.ts';
@@ -28,8 +29,13 @@ function formatRemainingTime(remaining: number): string {
2829
export const statuslineCommand = define({
2930
name: 'statusline',
3031
description: 'Display compact status line for Claude Code hooks (Beta)',
31-
args: {},
32-
async run() {
32+
args: {
33+
offline: {
34+
...sharedArgs.offline,
35+
default: true, // Default to offline mode for faster performance
36+
},
37+
},
38+
async run(ctx) {
3339
// Set logger to silent for statusline output
3440
logger.level = 0;
3541

@@ -61,7 +67,7 @@ export const statuslineCommand = define({
6167
// Load current session's cost by finding the specific JSONL file
6268
let sessionCost: number | null = null;
6369
try {
64-
const sessionData = await loadSessionUsageById(sessionId, { mode: 'auto' });
70+
const sessionData = await loadSessionUsageById(sessionId, { mode: 'auto', offline: ctx.values.offline });
6571
if (sessionData != null) {
6672
sessionCost = sessionData.totalCost;
6773
}
@@ -80,6 +86,7 @@ export const statuslineCommand = define({
8086
since: todayStr,
8187
until: todayStr,
8288
mode: 'auto',
89+
offline: ctx.values.offline,
8390
});
8491

8592
if (dailyData.length > 0) {
@@ -97,6 +104,7 @@ export const statuslineCommand = define({
97104
try {
98105
const blocks = await loadSessionBlockData({
99106
mode: 'auto',
107+
offline: ctx.values.offline,
100108
});
101109

102110
// Only identify blocks if we have data

0 commit comments

Comments
 (0)