Repository navigation
Per-project environment variables for runs, dev servers and terminals (#188) - #1578
Conversation
…#188) Projects get an `env` map (Edit Project → Environment variables, one KEY=value per line). It is persisted and normalized on load (PATH and invalid names dropped), and layered into: - agent runs for every provider, locally and across ssh/WSL (forwarded as quoted `env K=V` through resolveSpawn / resolveWorkflowSpawn) - workflow phase agents - the thread terminal - verify, setup and quick-action commands - dev servers (already read project.env) Precedence: inherited env < project env < provider overlay (CODEX_HOME, KIMI_CODE_HOME, ...) < thread secrets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 380fefaff5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| envExtra: withProjectEnv( | ||
| opts.project, | ||
| entry && entry.id === "grok" ? mergeGrokSpawnEnv(wrapEnv) : undefined, | ||
| ), |
There was a problem hiding this comment.
Route Claude workflow phases through the boundary wrapper
For an SSH or WSL project whose workflow phase uses Claude, the project variables added here only enter the locally spawned process: unlike every other workflow provider, the spawn immediately above calls resolveWorkflowSpawn only for Grok. Consequently the remote Claude process never receives these variables and the phase may run against the local checkout instead; route Claude through the boundary wrapper as well.
Useful? React with 👍 / 👎.
| if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) { | ||
| return `Invalid environment line: ${line}`; | ||
| } | ||
| if (key === "PATH") return "PATH cannot be set per project."; |
There was a problem hiding this comment.
Reject PATH case-insensitively on Windows
On Windows, environment variable names are case-insensitive, so entering Path=... bypasses this exact-case check and is also accepted by normalizeProjectEnv. On systems where the inherited key is Path, the project value then overwrites the executable search path for agents, terminals, and commands, despite the UI claiming PATH is prohibited; compare the key case-insensitively.
Useful? React with 👍 / 👎.
| export function parseEnvText(text: string): Record<string, string> | string { | ||
| const env: Record<string, string> = {}; | ||
| for (const raw of text.split("\n")) { | ||
| const line = raw.trim(); |
There was a problem hiding this comment.
Preserve whitespace in environment values
When a value intentionally begins or ends with whitespace, trimming the entire line before splitting silently changes it—for example, TOKEN=abc is saved as TOKEN=abc. Because every project edit submits the parsed environment map, an existing whitespace-bearing value is also corrupted when the user saves an unrelated setting; trim only the key/formatting rather than the value.
Useful? React with 👍 / 👎.
Closes #188.
What
Projects get an
envmap, edited in Edit Project → Environment variables (oneKEY=valueper line,#comments and blank lines skipped). It is applied to:runVerifyCommand)project.envviaspawnEnvForDevServer; now there's a way to set it)How
worktreeEnv.withProjectEnv(project, overlay)layers project env under a spawn's own overlay. Remote: injected once inresolveSpawn/resolveWorkflowSpawn, forwarded as quotedenv K=V. Local: one wrap perrunner-provider-*.js/workflow-agents-*.js.CODEX_HOME,KIMI_CODE_HOME, …) < thread secrets.services-projects.updateProject(null/{}clears) and normalized instore-migrate(PATH and invalid names dropped, existingnormalizeProjectEnv).spawnEnv, so an edit respawns the kept-alive CLI next turn.Known limits
PATHis blocked; other keys pass through.WSLENV); verify doesn't wrap ssh at all today.Tests
electron/test/project-env.test.js: merge precedence, ssh forwarding, persist/reload/clear, a real generic run seeing the env, verify with an overlapping inherited key.test/editProject.test.tsx: prefill, bad-line rejection, saved payload.test:electron4481 pass / 0 fail (CI-like env), typecheck,vite build, edit-project renderer tests green.🤖 Generated with Claude Code