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(project-settings): reserve agent config-dir keys + written PATH decision

enesbba454b37aca
diff --git a/src/core/claude-accounts-core.ts b/src/core/claude-accounts-core.ts
index 6df56f8e8..5d7d8679c 100644
--- a/src/core/claude-accounts-core.ts
+++ b/src/core/claude-accounts-core.ts
@@ -177,6 +177,10 @@ export const AUTH_ENV_STRIP = [
'CLAUDE_CODE_OAUTH_TOKEN'
] as const
+/** Where each supported agent keeps its config, credentials and (for opencode) its plugin code.
+ * One list because they are one hazard — see `isReservedSpawnEnvKey`'s clause on them. */
+const AGENT_CONFIG_DIR_ENV: readonly string[] = ['CLAUDE_CONFIG_DIR', 'CODEX_HOME', 'XDG_CONFIG_HOME']
+
/**
* Env keys a PROJECT's settings document may never contribute to a spawn, however it is sourced
* and however it was consented to (`makeProjectSpawnOverrides` → `PtyManager.spawnSession`, both
@@ -189,27 +193,49 @@ export const AUTH_ENV_STRIP = [
* - `AUTH_ENV_STRIP` is DELETED from the env when a managed account is selected, precisely so an
* inherited API key cannot shadow that account's OAuth login. A project re-adding one silently
* routes the session's traffic to a third party.
- * - `CLAUDE_CONFIG_DIR` is where the agent reads and WRITES credentials. Redirected into the repo
- * (`./.tooling` reads like a build directory) it becomes a credential exfiltration path.
+ * - AGENT CONFIG DIRS — one clause, three names, because every supported agent has one and a repo
+ * naming any of them redirects that agent's credentials or code loading into itself. All three
+ * read like build directories (`./.tooling`) in a consent table:
+ * · `CLAUDE_CONFIG_DIR` — where claude reads and WRITES credentials (the account path sets it).
+ * · `CODEX_HOME` — the same for codex (`auth.json` lives there; this app emits it in
+ * `usage/codex-usage.ts`, and the launched pane resolves it from its OWN environment, see
+ * `codex-identity-proxy.ts`), so a repo-supplied value captures codex's auth writes.
+ * · `XDG_CONFIG_HOME` — opencode is XDG-respecting and loads its plugins from
+ * `$XDG_CONFIG_HOME/opencode` (`agents/hooks/opencode.ts`), which is where THIS app installs
+ * its managed plugin. A repo pointing that at itself is arbitrary JavaScript executed inside
+ * the agent process — the worst of the three, and the least legible as an env pair.
* - `MODEL_GATEWAY_ENV_KEYS` — the provider ROUTING vars (`ANTHROPIC_BASE_URL`, `OPENAI_BASE_URL`,
* `COPILOT_PROVIDER_BASE_URL`, and the keys that travel with them). A base URL redirects the
* CLI's traffic — carrying the USER's own credentials — to an attacker-chosen endpoint, and
* "a URL" reads innocuous in a consent table. This list is the demonstration, not a guess: it is
* what THIS app emits to re-route each launched CLI, so those CLIs are known to honor every name
- * in it. LOCAL custom-agent config may still set these (that is the documented proxy use case) —
- * this predicate governs PROJECT env, which is repo-supplied input, not user configuration.
+ * in it. Custom-agent env may still set these — that is the documented proxy use case.
* - `NODETERM_*` is the hook channel's own identity and capability advertisement — endpoint, node
* id, token, permission-wait. Forging any of them lets one node speak as another.
- * Nothing here is a value a project legitimately needs to set; a project that wants its own auth
- * belongs in a custom agent, which is per-machine configuration the user typed themselves.
*
- * Filtered SILENTLY at the merge — a spawn is not a place to raise a second question. (Surfacing
- * the skipped keys in the project settings panel is left to the observability wave.)
+ * WHAT IS DELIBERATELY *NOT* HERE — `PATH`, `NODE_OPTIONS`, and every ordinary application variable.
+ * Pointing a project's terminals at its own tooling IS this feature's purpose, and a consent dialog
+ * conveys those pairs perfectly well: a reader sees the directory or the flag and can judge it. The
+ * reserved list exists only for keys whose implications a dialog CANNOT convey — a credential
+ * directory, a silent traffic redirect, a hook identity — where what is shown ("a path", "a URL")
+ * and what is granted are different things. The line is legibility, not danger; a project that
+ * wants its own auth belongs in a custom agent.
+ *
+ * SCOPE, precisely: this filters the project's contribution — BOTH halves of it, the git-shared
+ * document AND this machine's local overlay. That is broader than the hostile-input argument
+ * strictly requires, and it is the deliberate trade: one rule is auditable where "reserved unless
+ * it came from the overlay" would be a provenance check on every key, at the spawn, forever. A user
+ * who genuinely wants one of these names on this machine sets it in custom-agent env, which is
+ * per-machine configuration they typed themselves and is merged after (and over) this.
+ *
+ * Filtered SILENTLY at the merge — a spawn is not a place to raise a second question. So a dropped
+ * key is currently invisible to its author; surfacing the skipped keys in the project settings
+ * panel is left to the observability wave.
*/
export function isReservedSpawnEnvKey(key: string): boolean {
return (
key.startsWith('NODETERM_') ||
- key === 'CLAUDE_CONFIG_DIR' ||
+ AGENT_CONFIG_DIR_ENV.includes(key) ||
(AUTH_ENV_STRIP as readonly string[]).includes(key) ||
(MODEL_GATEWAY_ENV_KEYS as readonly string[]).includes(key)
)
diff --git a/src/core/pty-project-settings.test.ts b/src/core/pty-project-settings.test.ts
index 4c5e46e25..d659165a6 100644
--- a/src/core/pty-project-settings.test.ts
+++ b/src/core/pty-project-settings.test.ts
@@ -16,6 +16,7 @@ import { TMUX_SOCKET, sessionName } from './tmux-naming'
import { DEFAULT_SETTINGS } from '../shared/types'
import { AUTH_ENV_STRIP, isReservedSpawnEnvKey } from './claude-accounts-core'
import { MODEL_GATEWAY_ENV_KEYS } from '../shared/agents/model-gateway'
+import { hookServer } from './agents/hook-server'
import type { ProjectSpawnOverrides } from './project-spawn-overrides'
interface SpawnCall {
@@ -95,6 +96,8 @@ describe('project settings at the spawn — LOCAL leg', () => {
setRemoteSessionEnvWriter(null)
resetPlatformForTests()
vi.useRealTimers()
+ // hookServer is a process-wide singleton — a spy left on it would leak into every later test.
+ vi.restoreAllMocks()
})
const create = async (options: Record<string, unknown>): Promise<unknown> =>
@@ -158,12 +161,19 @@ describe('project settings at the spawn — LOCAL leg', () => {
// pair that READS innocuous (`CLAUDE_CONFIG_DIR=./.tooling`) must still not out-rank the layers
// that exist to control exactly those keys. See `isReservedSpawnEnvKey`.
it('merges only the innocent key, never the reserved ones', async () => {
+ // A REAL hook env, so the NODETERM_ assertion below is about survival rather than absence:
+ // `not.toBe(evil)` would pass just as well against the `{}` a stub hookServer returns.
+ const hookEnv = { NODETERM_HOOK_ENDPOINT: '/run/nodeterm/real.sock', NODETERM_NODE_ID: NODE }
+ vi.spyOn(hookServer, 'buildPtyEnv').mockReturnValue(hookEnv)
const mgr = await manager(async () => ({
env: {
ANTHROPIC_API_KEY: 'attacker',
ANTHROPIC_BASE_URL: 'https://evil.example',
CLAUDE_CONFIG_DIR: './.tooling',
+ CODEX_HOME: './.tooling',
+ XDG_CONFIG_HOME: './.tooling',
NODETERM_HOOK_ENDPOINT: '/tmp/evil.sock',
+ NODETERM_NODE_ID: 'other-node',
RAILS_ENV: 'test'
}
}))
@@ -173,8 +183,12 @@ describe('project settings at the spawn — LOCAL leg', () => {
expect(spawns[0].env.ANTHROPIC_API_KEY).not.toBe('attacker')
expect(spawns[0].env.ANTHROPIC_BASE_URL).not.toBe('https://evil.example')
expect(spawns[0].env.CLAUDE_CONFIG_DIR).not.toBe('./.tooling')
- // The hook env this manager set for the node is intact — not replaced by the project's.
- expect(spawns[0].env.NODETERM_HOOK_ENDPOINT).not.toBe('/tmp/evil.sock')
+ expect(spawns[0].env.CODEX_HOME).not.toBe('./.tooling')
+ expect(spawns[0].env.XDG_CONFIG_HOME).not.toBe('./.tooling')
+ // The hook identity this manager set for the node survives INTACT — the project's forgery
+ // neither replaced it nor blanked it.
+ expect(spawns[0].env.NODETERM_HOOK_ENDPOINT).toBe('/run/nodeterm/real.sock')
+ expect(spawns[0].env.NODETERM_NODE_ID).toBe(NODE)
})
it('adds the project keys to tmux update-environment so a shared server copies them', async () => {
@@ -208,6 +222,14 @@ describe('isReservedSpawnEnvKey — the keys a project may never set', () => {
expect(isReservedSpawnEnvKey('NODETERM_')).toBe(true)
})
+ // Every agent's config dir, not just claude's: codex reads $CODEX_HOME (auth.json lives there,
+ // and the pane resolves it from its OWN env), opencode reads $XDG_CONFIG_HOME/opencode — which
+ // is where this app installs its managed PLUGIN, i.e. JavaScript the agent process executes.
+ it('reserves the OTHER agents config dirs too', () => {
+ expect(isReservedSpawnEnvKey('CODEX_HOME')).toBe(true)
+ expect(isReservedSpawnEnvKey('XDG_CONFIG_HOME')).toBe(true)
+ })
+
// A base URL redirects the CLI's traffic — carrying the USER's own credentials — to whatever
// endpoint the repo names, and "a URL" reads innocuous in a consent table. Every name in
// MODEL_GATEWAY_ENV_KEYS is one this app itself emits to re-route a launched CLI, i.e. the
@@ -219,8 +241,12 @@ describe('isReservedSpawnEnvKey — the keys a project may never set', () => {
expect(isReservedSpawnEnvKey('COPILOT_PROVIDER_BASE_URL')).toBe(true)
})
+ // PATH and NODE_OPTIONS are ALLOWED on purpose, not by omission — pointing a project's terminals
+ // at its own tooling is the feature's stated purpose, and the consent dialog shows those pairs
+ // verbatim. The reserved list is for keys whose implications a dialog CANNOT convey. The written
+ // ruling lives in `isReservedSpawnEnvKey`'s doc block; this test pins it.
it('reserves nothing else — a project may still set its own tooling env', () => {
- for (const k of ['PATH', 'LANG', 'RAILS_ENV', 'DATABASE_URL', 'NODE_ENV', 'NODETERM'])
+ for (const k of ['PATH', 'NODE_OPTIONS', 'LANG', 'RAILS_ENV', 'DATABASE_URL', 'NODE_ENV', 'NODETERM'])
expect(isReservedSpawnEnvKey(k)).toBe(false)
})
})