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.

fix(accounts): destroy the login node with its removed account

enes056958ec89bf
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 1207502da..65d6f098f 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -127,6 +127,7 @@ import {
alignNodes,
arrangeNodes,
createAccountLoginNode,
+ isAccountLoginNode,
systemAccountDisplay,
createAgentNode,
createBrowserNode,
@@ -1496,32 +1497,6 @@ export function Canvas() {
// the "System account" entry with it.
useEffect(() => useSystemAccount.getState().ensure(), [])
- // 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
- )
- // Schedule a workspace write: persist() re-serializes the cleared live nodes and writes
- // the whole projects store to disk, also covering AccountsSection's setState on the other
- // projects' serialized nodes + defaultAccountId. Without this, quitting right after a
- // removal would leave the dead accountId in workspace.json.
- markDirty()
- }
- window.addEventListener('nodeterm:account-removed', onAccountRemoved)
- return () => window.removeEventListener('nodeterm:account-removed', onAccountRemoved)
- }, [setNodes, markDirty])
-
const addAgentNode = useCallback(
(agentId: AgentId, center?: { x: number; y: number }, groupId?: string, accountId?: string) => {
const project = useProjects.getState().getProject(activeProjectId)
@@ -1673,6 +1648,40 @@ export function Canvas() {
[setNodes, markDirty]
)
+ // When an account is removed in Settings, patch the ACTIVE project's live nodes (the projects
+ // store only holds the other projects' serialized copies). The account's login node is
+ // permanently DELETED — left alive with its accountId cleared, a cold restart would respawn
+ // its `claude /login` under the SYSTEM env, where completing the OAuth silently overwrites the
+ // user's ~/.claude identity (observed in the wild). Ordinary nodes just drop the accountId and
+ // fall back to the system account (the missing-dir spawn fallback is safe either way).
+ // Declared after deleteNodes: the dep array would hit the const's TDZ above it.
+ useEffect(() => {
+ const onAccountRemoved = (ev: Event): void => {
+ const accountId = (ev as CustomEvent<{ accountId: string }>).detail?.accountId
+ if (!accountId) return
+ const loginIds = nodesRef.current
+ .filter((n) => n.data.accountId === accountId && isAccountLoginNode(n.data))
+ .map((n) => n.id)
+ if (loginIds.length) deleteNodes(loginIds)
+ setNodes((ns) =>
+ ns.some((n) => n.data.accountId === accountId)
+ ? ns.map((n) =>
+ n.data.accountId === accountId
+ ? { ...n, data: { ...n.data, accountId: undefined } }
+ : n
+ )
+ : ns
+ )
+ // Schedule a workspace write: persist() re-serializes the cleared live nodes and writes
+ // the whole projects store to disk, also covering AccountsSection's setState on the other
+ // projects' serialized nodes + defaultAccountId. Without this, quitting right after a
+ // removal would leave the dead accountId in workspace.json.
+ markDirty()
+ }
+ window.addEventListener('nodeterm:account-removed', onAccountRemoved)
+ return () => window.removeEventListener('nodeterm:account-removed', onAccountRemoved)
+ }, [setNodes, markDirty, deleteNodes])
+
// Delete / Backspace asks for confirmation, then deletes the selected nodes.
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
diff --git a/src/renderer/components/settings/sections/AccountsSection.tsx b/src/renderer/components/settings/sections/AccountsSection.tsx
index bda437d77..ff7f4b288 100644
--- a/src/renderer/components/settings/sections/AccountsSection.tsx
+++ b/src/renderer/components/settings/sections/AccountsSection.tsx
@@ -3,6 +3,7 @@ import type { ClaudeAccount } from '@shared/types'
import { sshHostKey } from '@shared/ssh'
import { useSettings } from '../../../state/settings'
import { useSystemAccount } from '../../../state/systemAccount'
+import { isAccountLoginNode } from '../../../state/workspace'
import { useProjects } from '../../../state/projects'
import { useSshConn } from '../../../state/sshConn'
import { ConfirmDialog } from '../../ConfirmDialog'
@@ -141,9 +142,12 @@ export function AccountsSection({ isActive }: { isActive: boolean }): React.JSX.
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
- )
+ // The account's serialized login node is DROPPED, not kept account-less: respawned
+ // without its env, its `claude /login` would run against the system ~/.claude and
+ // overwrite the user's identity on completion. Other nodes just lose the accountId.
+ nodes: p.nodes
+ .filter((n) => !(n.accountId === account.id && isAccountLoginNode(n)))
+ .map((n) => (n.accountId === account.id ? { ...n, accountId: undefined } : n))
}))
}))
// ...and off the active project's LIVE nodes (Canvas listener patches React Flow).
diff --git a/src/renderer/state/workspace.account.test.ts b/src/renderer/state/workspace.account.test.ts
index 89ee3bb15..f4044743c 100644
--- a/src/renderer/state/workspace.account.test.ts
+++ b/src/renderer/state/workspace.account.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { accountChipLabel, systemAccountDisplay } from './workspace'
+import { accountChipLabel, isAccountLoginNode, systemAccountDisplay } from './workspace'
import type { ClaudeAccount } from '@shared/types'
const acct = (over: Partial<ClaudeAccount>): ClaudeAccount => ({
@@ -65,3 +65,19 @@ describe('systemAccountDisplay', () => {
expect(systemAccountDisplay(undefined, undefined)).toBe('System account')
})
})
+
+describe('isAccountLoginNode', () => {
+ it('matches the factory title (the only persisted signature)', () => {
+ expect(isAccountLoginNode({ title: 'Claude login' })).toBe(true)
+ })
+
+ it('matches a live node by its one-shot initialCommand', () => {
+ expect(isAccountLoginNode({ title: 'renamed', initialCommand: 'claude /login' })).toBe(true)
+ })
+
+ it('does not match ordinary claude nodes', () => {
+ expect(isAccountLoginNode({ title: 'My session', initialCommand: 'claude' })).toBe(false)
+ expect(isAccountLoginNode({ title: 'Terminal' })).toBe(false)
+ expect(isAccountLoginNode({})).toBe(false)
+ })
+})
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 902c3fe35..c41a0abad 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -381,6 +381,17 @@ export function createAccountLoginNode(
return node
}
+/**
+ * True when node data is (or started as) an account-login terminal (`claude /login`).
+ * `initialCommand` is one-shot and never persisted, so the factory title is the only durable
+ * signature — serialized copies match on title alone. Used to DESTROY the login node together
+ * with its removed account: left alive, a cold restart would respawn its `claude /login` under
+ * the system env, where completing the OAuth overwrites the user's ~/.claude identity.
+ */
+export function isAccountLoginNode(data: { title?: string; initialCommand?: string }): boolean {
+ return data.title === 'Claude login' || (data.initialCommand ?? '').startsWith('claude /login')
+}
+
/**
* 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