Skip to content

feat: ccswitch statusline puts the account in Claude Code's status line - #9

Merged
NotAProgrammer187 merged 1 commit into
mainfrom
feat/statusline
Sep 2, 2026
Merged

NotAProgrammer187 merged 1 commit into
mainfrom
feat/statusline

Conversation

@NotAProgrammer187

Copy link
Copy Markdown
Owner

What

ccswitch statusline prints one line shaped for Claude Code's statusLine setting:

work · Opus 4.5 · 5h 42% · wk 12%
  • Profile resolved from the session's CLAUDE_CONFIG_DIR (which ccswitch set at launch); foreign config dirs show their base name; a session launched without ccswitch reads the default ~/.claude and labels itself claude.
  • Model name parsed from the JSON Claude Code pipes on stdin (skipped on an interactive terminal so trying the command by hand never hangs).
  • Windows colored by the same thresholds as every other view — amber ≥70%, red ≥90% with the reset time.
  • One command wires it into every profile: ccswitch defaults set statusLine '{"type":"command","command":"ccswitch statusline"}'

Never blocks the status line

The command fires many times a minute, so it is a pure read: usage comes from a new ~/.ccswitch/usage-cache.json, and a stale entry kicks a detached statusline-refresh helper (same pattern as the update check) whose result shows up a tick later. A kick stamp bounds refresher spawning to one per 30s window; failed fetches are recorded so they don't refetch every render; writes are write-then-rename so concurrent readers never see a torn file. Profile resolution deliberately avoids List() — reading every profile's .claude.json (which can be MBs) per tick — and statusline skips start-up binary cleanup too.

Verified live: first call prints BartAccount, kicks the refresher; seconds later BartAccount · 5h 21% · wk 10% from real endpoint data.

🤖 Generated with Claude Code

One line shaped for the statusLine setting — profile, model, and both
rate-limit windows, amber at 70% and red with the reset time at 90%.
Sharing it everywhere is one command:
ccswitch defaults set statusLine '{"type":"command","command":"ccswitch statusline"}'

The status line runs its command constantly, so this path is a pure read:
usage comes from ~/.ccswitch/usage-cache.json, refreshed by a detached
helper at most every two minutes (the update-check pattern), profile
resolution matches directory names without reading any profile's
.claude.json, and even start-up housekeeping is skipped. Sessions
launched without ccswitch read the default ~/.claude and label
themselves claude.
@NotAProgrammer187
NotAProgrammer187 merged commit ca395d1 into main Sep 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant