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(accounts): Settings accounts section + canvas login-node flow

enesa3350887e456
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 011c64070..76c6c590d 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -116,6 +116,7 @@ import {
applyCanvasMutation,
claudeLaunchCommand,
COLLAPSED_HEIGHT,
+ createAccountLoginNode,
createAgentNode,
createBrowserNode,
createChatNode,
@@ -1327,6 +1328,43 @@ export function Canvas() {
return () => window.removeEventListener('nodeterm:open-chat', onOpenChat)
}, [setNodes, markDirty])
+ // Task 6: the Settings → Accounts "Add account" flow dispatches 'nodeterm:add-account-login'
+ // to open a terminal node running `claude /login` under the new account's config dir.
+ useEffect(() => {
+ const onAddAccountLogin = (ev: Event): void => {
+ const accountId = (ev as CustomEvent<{ accountId: string }>).detail?.accountId
+ if (!accountId) return
+ setNodes((ns) => [
+ ...ns.map((n) => ({ ...n, selected: false })),
+ { ...createAccountLoginNode(accountId, ns.length, viewCenter()), selected: true }
+ ])
+ markDirty()
+ }
+ window.addEventListener('nodeterm:add-account-login', onAddAccountLogin)
+ return () => window.removeEventListener('nodeterm:add-account-login', onAddAccountLogin)
+ }, [setNodes, markDirty, viewCenter])
+
+ // When an account is removed in Settings, clear it off the ACTIVE project's live nodes (the
+ // projects store only holds the other projects' serialized copies). Referencing nodes fall
+ // back to the system account; the missing-dir spawn fallback (Task 3) is safe either way.
+ useEffect(() => {
+ const onAccountRemoved = (ev: Event): void => {
+ const accountId = (ev as CustomEvent<{ accountId: string }>).detail?.accountId
+ if (!accountId) return
+ setNodes((ns) =>
+ ns.some((n) => n.data.accountId === accountId)
+ ? ns.map((n) =>
+ n.data.accountId === accountId
+ ? { ...n, data: { ...n.data, accountId: undefined } }
+ : n
+ )
+ : ns
+ )
+ }
+ window.addEventListener('nodeterm:account-removed', onAccountRemoved)
+ return () => window.removeEventListener('nodeterm:account-removed', onAccountRemoved)
+ }, [setNodes])
+
const addAgentNode = useCallback(
(agentId: AgentId, center?: { x: number; y: number }, groupId?: string) => {
const project = useProjects.getState().getProject(activeProjectId)
diff --git a/src/renderer/components/settings/SettingsIcons.tsx b/src/renderer/components/settings/SettingsIcons.tsx
index 0aad14191..195ce8d90 100644
--- a/src/renderer/components/settings/SettingsIcons.tsx
+++ b/src/renderer/components/settings/SettingsIcons.tsx
@@ -26,6 +26,12 @@ const PATHS: Record<SettingsSectionId, React.JSX.Element> = {
agents: (
<path d="M8 2.3 9.4 5.9 13 7.3 9.4 8.7 8 12.3 6.6 8.7 3 7.3 6.6 5.9z" />
),
+ accounts: (
+ <>
+ <circle cx="8" cy="5.5" r="2.6" />
+ <path d="M3.4 13c0-2.5 2.1-4 4.6-4s4.6 1.5 4.6 4" />
+ </>
+ ),
'custom-agents': (
<>
<rect x="2.5" y="2.5" width="11" height="11" rx="2.5" />
diff --git a/src/renderer/components/settings/SettingsPage.tsx b/src/renderer/components/settings/SettingsPage.tsx
index 47d495daf..58d060695 100644
--- a/src/renderer/components/settings/SettingsPage.tsx
+++ b/src/renderer/components/settings/SettingsPage.tsx
@@ -9,6 +9,7 @@ import { ShellSection } from './sections/ShellSection'
import { BehaviorSection } from './sections/BehaviorSection'
import { AppearanceSection } from './sections/AppearanceSection'
import { AgentsSection } from './sections/AgentsSection'
+import { AccountsSection } from './sections/AccountsSection'
import { CustomAgentsSection } from './sections/CustomAgentsSection'
import { NotificationsSection } from './sections/NotificationsSection'
import { CommitSection } from './sections/CommitSection'
@@ -65,6 +66,7 @@ export function SettingsPage({
<BehaviorSection isActive={active === 'behavior'} />
<AppearanceSection isActive={active === 'appearance'} />
<AgentsSection isActive={active === 'agents'} />
+ <AccountsSection isActive={active === 'accounts'} />
<CustomAgentsSection isActive={active === 'custom-agents'} />
<NotificationsSection isActive={active === 'notifications'} />
<CommitSection isActive={active === 'commit'} />
diff --git a/src/renderer/components/settings/nav.test.ts b/src/renderer/components/settings/nav.test.ts
index e1ccbd8e3..0e79c55cc 100644
--- a/src/renderer/components/settings/nav.test.ts
+++ b/src/renderer/components/settings/nav.test.ts
@@ -2,10 +2,10 @@ import { describe, it, expect } from 'vitest'
import { SETTINGS_GROUPS, allSectionIds, FIRST_SECTION_ID } from './nav'
describe('SETTINGS_GROUPS', () => {
- it('lists exactly 14 sections with no duplicates', () => {
+ it('lists exactly 15 sections with no duplicates', () => {
const ids = allSectionIds()
- expect(ids).toHaveLength(14)
- expect(new Set(ids).size).toBe(14)
+ expect(ids).toHaveLength(15)
+ expect(new Set(ids).size).toBe(15)
})
it('starts at a section that exists in the groups', () => {
expect(allSectionIds()).toContain(FIRST_SECTION_ID)
diff --git a/src/renderer/components/settings/nav.ts b/src/renderer/components/settings/nav.ts
index 3b4a1081e..fda932e7e 100644
--- a/src/renderer/components/settings/nav.ts
+++ b/src/renderer/components/settings/nav.ts
@@ -4,6 +4,7 @@ export type SettingsSectionId =
| 'behavior'
| 'appearance'
| 'agents'
+ | 'accounts'
| 'custom-agents'
| 'notifications'
| 'commit'
@@ -36,6 +37,7 @@ export const SETTINGS_GROUPS: SettingsGroup[] = [
title: 'Agents',
sections: [
{ id: 'agents', title: 'Agents' },
+ { id: 'accounts', title: 'Accounts' },
{ id: 'custom-agents', title: 'Custom agents' },
{ id: 'notifications', title: 'Notifications' },
{ id: 'commit', title: 'Commit messages' }
diff --git a/src/renderer/components/settings/sections/AccountsSection.tsx b/src/renderer/components/settings/sections/AccountsSection.tsx
new file mode 100644
index 000000000..953f46dba
--- /dev/null
+++ b/src/renderer/components/settings/sections/AccountsSection.tsx
@@ -0,0 +1,195 @@
+import { useState } from 'react'
+import type { ClaudeAccount } from '@shared/types'
+import { useSettings } from '../../../state/settings'
+import { useProjects } from '../../../state/projects'
+import { ConfirmDialog } from '../../ConfirmDialog'
+import { SettingsSection } from '../SettingsSection'
+import { SearchableRow } from '../SearchableRow'
+import { Button } from '@renderer/ui/Button'
+import { Input } from '@renderer/ui/Input'
+
+const ROWS = {
+ accounts: {
+ title: 'Claude accounts',
+ keywords: ['account', 'claude', 'login', 'isolated', 'multi', 'email']
+ }
+}
+const ENTRIES = Object.values(ROWS)
+
+/** Reads fresh settings then applies a transform to the accounts list (avoids stale closures
+ * after an awaited login resolves late). */
+function applyAccounts(fn: (accs: ClaudeAccount[]) => ClaudeAccount[]): void {
+ const s = useSettings.getState()
+ s.update({ claudeAccounts: fn(s.settings.claudeAccounts) })
+}
+
+/** Counts nodes bound to an account across every project's SERIALIZED nodes. The active
+ * project's live React Flow edits since the last commit aren't reflected here, so the count
+ * can be slightly stale for the active canvas — acceptable for a confirmation warning. */
+function countNodesUsing(accountId: string): number {
+ return useProjects
+ .getState()
+ .projects.reduce(
+ (sum, p) => sum + p.nodes.filter((n) => n.accountId === accountId).length,
+ 0
+ )
+}
+
+export function AccountsSection({ isActive }: { isActive: boolean }): React.JSX.Element {
+ const accounts = useSettings((s) => s.settings.claudeAccounts)
+ const [versionWarning, setVersionWarning] = useState(false)
+ const [pendingRemove, setPendingRemove] = useState<ClaudeAccount | null>(null)
+
+ const setLabel = (id: string, label: string): void =>
+ applyAccounts((accs) => accs.map((a) => (a.id === id ? { ...a, label } : a)))
+
+ // Open a login terminal for an account and wait (up to ~5 min) for the CLI to write its
+ // credentials; on success flip the row out of `pending` and adopt the captured email.
+ const runLogin = async (id: string): Promise<void> => {
+ window.dispatchEvent(new CustomEvent('nodeterm:add-account-login', { detail: { accountId: id } }))
+ const captured = await window.nodeTerminal.claudeAccounts.waitLogin(id)
+ if (!captured) return // timeout / cancel: row stays pending, offers Retry
+ applyAccounts((accs) =>
+ accs.map((a) =>
+ a.id === id
+ ? {
+ ...a,
+ label: a.label === 'New account' ? captured.email : a.label,
+ email: captured.email,
+ pending: false
+ }
+ : a
+ )
+ )
+ }
+
+ const onAddAccount = async (): Promise<void> => {
+ const { id, versionSupported } = await window.nodeTerminal.claudeAccounts.add()
+ // Non-blocking: the account still isolates config, but an old CLI's unscoped macOS keychain
+ // service would collide across accounts — surface a dismissable warning.
+ if (!versionSupported) setVersionWarning(true)
+ const account: ClaudeAccount = {
+ id,
+ label: 'New account',
+ pending: true,
+ createdAt: Date.now()
+ }
+ applyAccounts((accs) => [...accs, account])
+ await runLogin(id)
+ }
+
+ const confirmRemove = async (account: ClaudeAccount): Promise<void> => {
+ setPendingRemove(null)
+ await window.nodeTerminal.claudeAccounts.remove(account.id)
+ applyAccounts((accs) => accs.filter((a) => a.id !== account.id))
+ // Clear the account off serialized nodes (all projects) + any project default...
+ useProjects.setState((s) => ({
+ projects: s.projects.map((p) => ({
+ ...p,
+ ...(p.defaultAccountId === account.id ? { defaultAccountId: undefined } : {}),
+ nodes: p.nodes.map((n) =>
+ n.accountId === account.id ? { ...n, accountId: undefined } : n
+ )
+ }))
+ }))
+ // ...and off the active project's LIVE nodes (Canvas listener patches React Flow).
+ window.dispatchEvent(
+ new CustomEvent('nodeterm:account-removed', { detail: { accountId: account.id } })
+ )
+ }
+
+ const removeMessage = (a: ClaudeAccount): string => {
+ const n = countNodesUsing(a.id)
+ return `Remove account "${a.label}"? Its logged-in credentials and all its Claude transcripts will be deleted. ${n} node(s) currently use it and will fall back to the system account.`
+ }
+
+ return (
+ <SettingsSection
+ id="accounts"
+ title="Accounts"
+ description="Isolated Claude logins. Each account has its own config dir, credentials, and transcripts; a node keeps the account it was created with for life."
+ isActive={isActive}
+ searchEntries={ENTRIES}
+ >
+ <SearchableRow {...ROWS.accounts}>
+ <div className="space-y-4">
+ {versionWarning ? (
+ <div className="flex items-start justify-between gap-3 rounded-md border border-[#ff453a]/40 bg-[#ff453a]/10 px-3 py-2 text-[13px] leading-relaxed text-[#ff453a]">
+ <span>
+ Your installed Claude CLI is older than the version that scopes credentials per
+ config dir. Accounts still isolate their config, but on macOS logins may collide in
+ the shared keychain. Update the Claude CLI to keep them fully separate.
+ </span>
+ <button
+ className="shrink-0 cursor-pointer text-muted hover:text-text"
+ onClick={() => setVersionWarning(false)}
+ >
+ Dismiss
+ </button>
+ </div>
+ ) : null}
+
+ {accounts.length === 0 ? (
+ <p className="text-[13px] text-muted">No accounts yet.</p>
+ ) : (
+ accounts.map((account) => (
+ <div
+ key={account.id}
+ className="flex items-center justify-between gap-3 rounded-md border border-border p-3"
+ >
+ <div className="min-w-0 flex-1 space-y-1">
+ <div className="flex items-center gap-2">
+ <Input
+ className="w-56"
+ placeholder="Account label"
+ value={account.label}
+ onChange={(e) => setLabel(account.id, e.target.value)}
+ />
+ {account.pending ? (
+ <span className="rounded-full bg-[#ff9f0a]/15 px-2 py-0.5 text-[11px] font-medium text-[#ff9f0a]">
+ pending
+ </span>
+ ) : null}
+ </div>
+ {account.email && !account.pending ? (
+ <p className="text-[12px] text-muted">{account.email}</p>
+ ) : null}
+ </div>
+ <div className="flex shrink-0 items-center gap-2">
+ {account.pending ? (
+ <Button onClick={() => void runLogin(account.id)}>Retry login</Button>
+ ) : null}
+ <Button
+ variant="ghost"
+ aria-label="Remove account"
+ onClick={() => setPendingRemove(account)}
+ >
+ ×
+ </Button>
+ </div>
+ </div>
+ ))
+ )}
+
+ <Button variant="primary" onClick={() => void onAddAccount()}>
+ Add account
+ </Button>
+
+ <p className="text-[12px] leading-relaxed text-muted">
+ Accounts are isolated Claude logins. New Claude nodes pick an account from the add
+ menus; each node keeps its account for life.
+ </p>
+ </div>
+ </SearchableRow>
+
+ {pendingRemove ? (
+ <ConfirmDialog
+ message={removeMessage(pendingRemove)}
+ confirmLabel="Remove"
+ onConfirm={() => void confirmRemove(pendingRemove)}
+ onCancel={() => setPendingRemove(null)}
+ />
+ ) : null}
+ </SettingsSection>
+ )
+}
diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.ts
index 3cfde835b..0095f8d7f 100644
--- a/src/renderer/state/workspace.test.ts
+++ b/src/renderer/state/workspace.test.ts
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest'
import {
+ createAccountLoginNode,
createAgentNode,
createChatNode,
createDinoNode,
@@ -202,6 +203,16 @@ describe('accountId serialization', () => {
})
})
+describe('createAccountLoginNode', () => {
+ it('produces a terminal node that logs the given account in', () => {
+ const node = createAccountLoginNode('acct-1', 0)
+ expect(node.type).toBe('terminal')
+ expect(node.data.title).toBe('Claude login')
+ expect(node.data.accountId).toBe('acct-1')
+ expect(node.data.initialCommand).toBe('claude /login')
+ })
+})
+
describe('dino node serialization', () => {
it('round-trips a dino node and its highScore', () => {
const dino = {
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index e2b8aef67..a2f4cc355 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -309,6 +309,27 @@ export function createClaudeNode(
return createAgentNode('claude', index, cwd, center)
}
+/**
+ * Terminal node used to log a new managed account in: the session runs under the account's
+ * CLAUDE_CONFIG_DIR (Task-3 env injection keyed off `data.accountId`), so `claude /login`
+ * writes credentials + `.claude.json` into the account dir, where the main process captures
+ * the email. A plain terminal (not an agent node) so no session-name tracking kicks in.
+ */
+export function createAccountLoginNode(
+ accountId: string,
+ index: number,
+ center?: { x: number; y: number }
+): CanvasNode {
+ const node = createTerminalNode(index, undefined, center)
+ node.data = {
+ ...node.data,
+ title: 'Claude login',
+ accountId,
+ initialCommand: 'claude /login'
+ }
+ return node
+}
+
/**
* Creates a code editor node for a file. When `sshFs` is true, `data.sshFs` is stamped so EditorNode
* reads/writes over the project's remote fs (`sshFs`) and `filePath` is the remote path — mirroring