Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(usage): switch the project's default Claude account from the usage pill

enes9290d1d49f88
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 955c57948..6c173f0f4 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -9194,7 +9194,9 @@ export function Canvas() {
onKillSession={killSessionById}
/>
- <UsageIndicator overBoard={kanbanOpen} />
+ {/* Same write path as the TabBar caret menu (project.defaultAccountId + persist) — the
+ popover row is a second, better-placed entrance to the same action (issue #142). */}
+ <UsageIndicator overBoard={kanbanOpen} onSetDefaultAccount={setProjectDefaultAccount} />
</div>
<PresenceNamePrompt />
diff --git a/src/renderer/components/UsageIndicator.tsx b/src/renderer/components/UsageIndicator.tsx
index 720bdfa1e..a165fff16 100644
--- a/src/renderer/components/UsageIndicator.tsx
+++ b/src/renderer/components/UsageIndicator.tsx
@@ -4,7 +4,7 @@ import { AGENT_CONFIG } from '@shared/agents/config'
import { useSettings } from '../state/settings'
import { useProjects } from '../state/projects'
import { useSshConn } from '../state/sshConn'
-import { scopeFromKey, scopeUsage, usageScopeKey } from '../lib/usageScope'
+import { accountRowAction, scopeFromKey, scopeUsage, usageScopeKey } from '../lib/usageScope'
import {
barFillPercent,
formatResetCountdown,
@@ -58,6 +58,43 @@ function LimitRow({ limit, mode }: { limit: UsageLimit; mode: 'used' | 'remainin
)
}
+/**
+ * The account-row affordance for issue #142 — the switch lives where the decision is made.
+ * It writes `project.defaultAccountId` and nothing else: `data.accountId` is resolved once at
+ * node creation and is immutable after, so the copy says "new sessions" and running sessions
+ * never move. `isDefault` marks the row the project currently resolves to; `onUse` is absent
+ * when there is nothing honest to offer (no active project, or a row whose account this
+ * project cannot launch).
+ */
+function DefaultAccountMark({
+ isDefault,
+ onUse
+}: {
+ isDefault: boolean
+ onUse?: () => void
+}) {
+ if (isDefault)
+ return (
+ <span
+ className="usage-account__default"
+ title="New Claude nodes in this project open under this account."
+ >
+ ✓ new sessions
+ </span>
+ )
+ if (!onUse) return null
+ return (
+ <button
+ type="button"
+ className="usage-account__use"
+ title="New Claude nodes in this project will open under this account. Running sessions keep theirs."
+ onClick={onUse}
+ >
+ Use for new sessions
+ </button>
+ )
+}
+
/**
* One account's limit bars under a label, for the multi-account popover. Reuses LimitRow's
* markup — `u` is null while its on-demand fetch is in flight.
@@ -66,16 +103,23 @@ function AccountUsageBlock({
label,
email,
u,
- mode
+ mode,
+ isDefault = false,
+ onUse
}: {
label: string
email?: string
u: ClaudeUsage | null
mode: 'used' | 'remaining'
+ isDefault?: boolean
+ onUse?: () => void
}) {
return (
<div className="usage-account">
- <div className="usage-account__label">{label}</div>
+ <div className="usage-account__label">
+ {label}
+ <DefaultAccountMark isDefault={isDefault} onUse={onUse} />
+ </div>
{(email ?? u?.email) && <div className="usage-account__email">{email ?? u?.email}</div>}
{u?.limits.map((l) => (
<LimitRow key={limitKey(l)} limit={l} mode={mode} />
@@ -95,7 +139,17 @@ function AccountUsageBlock({
* `claude` has nothing to report, and listing it would turn "connect an SSH project" into "grow
* a permanent empty section".
*/
-function RemoteUsageBlock({ row, mode }: { row: RemoteAccountUsage; mode: 'used' | 'remaining' }) {
+function RemoteUsageBlock({
+ row,
+ mode,
+ isDefault = false,
+ onUse
+}: {
+ row: RemoteAccountUsage
+ mode: 'used' | 'remaining'
+ isDefault?: boolean
+ onUse?: () => void
+}) {
if (row.usage.status === 'unavailable') return null
const showHost = row.label !== row.hostKey
return (
@@ -105,6 +159,7 @@ function RemoteUsageBlock({ row, mode }: { row: RemoteAccountUsage; mode: 'used'
<span className="usage-account__host" title={`Read on ${row.hostKey} over SSH`}>
{showHost ? row.hostKey : 'SSH'}
</span>
+ <DefaultAccountMark isDefault={isDefault} onUse={onUse} />
</div>
{row.usage.email && <div className="usage-account__email">{row.usage.email}</div>}
{row.usage.limits.map((l) => (
@@ -156,7 +211,15 @@ function ProviderBlock({ u, mode }: { u: ProviderUsage; mode: 'used' | 'remainin
* last-known data shown on stale/error. Compact pill = mini-bar + one "N% label" per limit,
* e.g. "93% 5h · 39% wk · 13% Fable" — the bar tracks whichever limit is closest to biting.
*/
-export function UsageIndicator({ overBoard = false }: { overBoard?: boolean }): JSX.Element | null {
+export function UsageIndicator({
+ overBoard = false,
+ onSetDefaultAccount
+}: {
+ overBoard?: boolean
+ /** Writes `project.defaultAccountId` + persists (Canvas's own TabBar handler). When absent the
+ * popover is a pure readout, exactly as before issue #142. */
+ onSetDefaultAccount?: (projectId: string, accountId: string | undefined) => void
+}): JSX.Element | null {
const [usage, setUsage] = useState<ClaudeUsage | null>(null)
const [open, setOpen] = useState(false)
const [refreshing, setRefreshing] = useState(false)
@@ -185,6 +248,37 @@ export function UsageIndicator({ overBoard = false }: { overBoard?: boolean }):
)
const scope = useMemo(() => scopeFromKey(scopeHostKey), [scopeHostKey])
+ // Issue #142 — "Use for new sessions" on the account rows. A PRIMITIVE selector on purpose
+ // (see scopeHostKey above): selecting the project object would re-render the pill on every
+ // canvas edit.
+ const projectDefaultId = useProjects(
+ (s) => s.projects.find((p) => p.id === s.activeProjectId)?.defaultAccountId
+ )
+ // The accounts THIS project can actually launch — the same host rule the whole panel follows
+ // (local project: local accounts; SSH project: that host's). The persisted default is validated
+ // against them, exactly as resolveNewNodeAccount does at node creation: a stale id (account
+ // since removed) marks the System row, never a ghost.
+ const eligibleAccounts = useMemo(
+ () =>
+ claudeAccounts.filter(
+ (a) => !a.pending && (scopeHostKey ? a.host === scopeHostKey : !a.host)
+ ),
+ [claudeAccounts, scopeHostKey]
+ )
+ // One rule for every row, local and remote alike — `accountRowAction` (pure, tested) decides
+ // default/offer/none; this pair just turns its answer into props. Absent handler / no project =
+ // pure readout, exactly as before. null = the System row (clears the override).
+ const rowMark = (accountId: string | null): { isDefault: boolean; onUse?: () => void } => {
+ const action = accountRowAction(accountId, eligibleAccounts, projectDefaultId)
+ return {
+ isDefault: action === 'default',
+ onUse:
+ action === 'offer' && onSetDefaultAccount && activeProjectId
+ ? () => onSetDefaultAccount(activeProjectId, accountId ?? undefined)
+ : undefined
+ }
+ }
+
useEffect(() => {
void window.nodeTerminal.usage.fetch().then(setUsage)
return window.nodeTerminal.usage.onUpdate(setUsage)
@@ -400,9 +494,17 @@ export function UsageIndicator({ overBoard = false }: { overBoard?: boolean }):
// Avoid printing the email twice when it's already the display label.
email={systemLabelSetting.trim() ? (claudeUsage.email ?? undefined) : undefined}
u={claudeUsage}
+ {...rowMark(null)}
/>
{scoped.accounts.map((a) => (
- <AccountUsageBlock key={a.id} mode={percentMode} label={a.label} email={a.email} u={acctUsage[a.id] ?? null} />
+ <AccountUsageBlock
+ key={a.id}
+ mode={percentMode}
+ label={a.label}
+ email={a.email}
+ u={acctUsage[a.id] ?? null}
+ {...rowMark(a.id)}
+ />
))}
</>
) : (
@@ -426,8 +528,15 @@ export function UsageIndicator({ overBoard = false }: { overBoard?: boolean }):
))}
{/* On an SSH project these are the whole panel; the host badge is what says the numbers
were read somewhere other than this machine. */}
+ {/* The same offer on an SSH project's rows — scoped as ever: only the host's system
+ identity and THIS host's managed accounts are actionable (accountRowAction). */}
{visibleRemote.map((r) => (
- <RemoteUsageBlock key={`${r.hostKey}#${r.accountId ?? ''}`} row={r} mode={percentMode} />
+ <RemoteUsageBlock
+ key={`${r.hostKey}#${r.accountId ?? ''}`}
+ row={r}
+ mode={percentMode}
+ {...rowMark(r.accountId)}
+ />
))}
{scope.kind === 'ssh' && visibleRemote.length === 0 && (
<div className="usage-popover__empty">
diff --git a/src/renderer/lib/usageScope.test.ts b/src/renderer/lib/usageScope.test.ts
index 9076c744a..de79572a4 100644
--- a/src/renderer/lib/usageScope.test.ts
+++ b/src/renderer/lib/usageScope.test.ts
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest'
import {
+ accountRowAction,
scopeFromKey,
scopeUsage,
usageScopeFor,
@@ -170,3 +171,36 @@ describe('scopeUsage — SSH project', () => {
expect(out.remote).toEqual([])
})
})
+
+/**
+ * Issue #142 — the "Use for new sessions" affordance on the popover's account rows. The rules
+ * deliberately mirror resolveNewNodeAccount at node creation; drifting apart would mark one
+ * account here and launch another there.
+ */
+describe('accountRowAction', () => {
+ const eligible = [{ id: 'a1' }, { id: 'a2' }]
+
+ it('marks the System row as default when no override is set', () => {
+ expect(accountRowAction(null, eligible, undefined)).toBe('default')
+ expect(accountRowAction('a1', eligible, undefined)).toBe('offer')
+ })
+
+ it('marks the overriding account and offers the rest, System included', () => {
+ expect(accountRowAction('a1', eligible, 'a1')).toBe('default')
+ expect(accountRowAction('a2', eligible, 'a1')).toBe('offer')
+ expect(accountRowAction(null, eligible, 'a1')).toBe('offer')
+ })
+
+ it('treats a STALE default (account since removed) as System — never a ghost row', () => {
+ expect(accountRowAction(null, eligible, 'gone')).toBe('default')
+ expect(accountRowAction('a1', eligible, 'gone')).toBe('offer')
+ })
+
+ it("refuses to act on a row this project cannot launch (another host's account)", () => {
+ expect(accountRowAction('other-host-acct', eligible, undefined)).toBe('none')
+ })
+
+ it('with no managed accounts the System row is default and nothing is offered', () => {
+ expect(accountRowAction(null, [], undefined)).toBe('default')
+ })
+})
diff --git a/src/renderer/lib/usageScope.ts b/src/renderer/lib/usageScope.ts
index 06153ae22..6b8ede3db 100644
--- a/src/renderer/lib/usageScope.ts
+++ b/src/renderer/lib/usageScope.ts
@@ -85,6 +85,33 @@ export interface ScopedUsage {
pillLimits: ClaudeUsage['limits']
}
+/**
+ * What the "Use for new sessions" affordance on one popover account row should be (issue #142).
+ *
+ * `rowAccountId` — null for a machine's system identity (~/.claude), else the managed account id.
+ * `eligible` — the accounts THIS project can launch (already host-filtered, the panel's own rule).
+ * `projectDefaultId` — the raw persisted `project.defaultAccountId`.
+ *
+ * Two decisions in one place, mirroring `resolveNewNodeAccount` at node creation:
+ * - the persisted default is VALIDATED against `eligible` — a stale id (account since removed)
+ * marks the System row as default, never a ghost row;
+ * - a row is only actionable when the project could actually launch it: the system identity, or
+ * one of the eligible accounts. Anything else (another host's row) is a plain readout.
+ */
+export function accountRowAction(
+ rowAccountId: string | null,
+ eligible: readonly { id: string }[],
+ projectDefaultId: string | undefined
+): 'default' | 'offer' | 'none' {
+ const activeDefault =
+ projectDefaultId && eligible.some((a) => a.id === projectDefaultId)
+ ? projectDefaultId
+ : undefined
+ const actionable = rowAccountId === null || eligible.some((a) => a.id === rowAccountId)
+ if (!actionable) return 'none'
+ return (rowAccountId ?? undefined) === activeDefault ? 'default' : 'offer'
+}
+
export function scopeUsage(input: ScopeInput): ScopedUsage {
const { scope, claude, accounts, providers, remote } = input
if (scope.kind === 'local') {
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 8c3c04305..50808c979 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -5874,6 +5874,37 @@ body,
background: rgba(var(--tint-rgb), 0.08);
vertical-align: middle;
}
+/* "Use for new sessions" affordance + current-default chip on an account row (issue #142).
+ Same chip grammar as __host above; the button reads as quiet text until hovered so the
+ readout stays a readout. */
+.usage-account__default {
+ margin-left: 6px;
+ padding: 1px 5px;
+ border-radius: 4px;
+ font-size: 10px;
+ letter-spacing: 0.02em;
+ color: var(--accent);
+ background: color-mix(in srgb, var(--accent) 12%, transparent);
+ vertical-align: middle;
+ white-space: nowrap;
+}
+.usage-account__use {
+ margin-left: 6px;
+ padding: 1px 5px;
+ border-radius: 4px;
+ border: none;
+ font-size: 10px;
+ letter-spacing: 0.02em;
+ color: rgba(var(--tint-rgb), 0.45);
+ background: transparent;
+ cursor: pointer;
+ vertical-align: middle;
+ white-space: nowrap;
+}
+.usage-account__use:hover {
+ color: var(--accent);
+ background: color-mix(in srgb, var(--accent) 12%, transparent);
+}
/* ---- Session-memory panel (opened by the system-resource pill) ----
Same surface, border and shadow as `.usage-popover` above — the two panels open from adjacent