Commit 203c94c
feat(agent): add custom environment variables to agent configuration (#13357)
### What this PR does
Fix #13343
Before this PR:
There was no way to configure custom environment variables for agents.
Users could not pass additional env vars to the Claude Code SDK process
at runtime.
After this PR:
Users can set custom environment variables (KEY=value pairs) for agents
via a TextArea in both the AgentModal (create/edit popup) and
AdvancedSettings (agent settings page). These env vars are merged into
the Claude Code SDK process environment at runtime, with a security
blocklist preventing overrides of critical system variables.
### Why we need it and why it was done in this way
Users need the ability to customize the agent runtime environment (e.g.,
setting `DEBUG=true`, custom API keys for MCP tools, or tool-specific
config). The implementation follows existing patterns:
- The `env_vars` field is added to `AgentConfigurationSchema` as an
optional `Record<string, string>` — no database migration needed since
configuration uses `.loose()` and is stored as JSON text.
- The AgentModal uses inline parse/serialize helpers for the KEY=value
text format.
- The AdvancedSettings follows the existing commit-on-blur pattern (same
as `maxTurns`).
- A blocklist in ClaudeCodeService prevents users from overriding
critical variables (API keys, Electron flags, etc.).
The following alternatives were considered:
- A key-value pair editor UI — rejected in favor of a simpler TextArea
matching the existing code tools page pattern.
### Breaking changes
None.
### Special notes for your reviewer
- The `env_vars` field uses `.optional().default({})` in Zod, consistent
with `permission_mode` and `max_turns`.
- Security: A blocklist of 12 critical env var keys (ANTHROPIC_API_KEY,
ELECTRON_RUN_AS_NODE, etc.) is enforced server-side with a warning log
when blocked.
- User env vars are applied **after** system env vars so they can
override shell env but NOT critical Anthropic/Electron vars.
### Checklist
- [x] PR: The PR description is expressive enough and will help future
contributors
- [x] Code: Write code that humans can understand and Keep it simple
- [x] Refactor: You have left the code cleaner than you found it (Boy
Scout Rule)
- [ ] Upgrade: Impact of this change on upgrade flows was considered and
addressed if required
- [x] Documentation: A user-guide update was considered and is present
(link) or not required.
- [ ] Self-review: I have reviewed my own code before requesting review
from others
### Release note
```release-note
Add custom environment variables support to agent configuration. Users can now set KEY=value pairs in the agent create/edit modal and advanced settings, which are passed to the Claude Code SDK runtime environment.
```
---------
Signed-off-by: Payne Fu <payne@Paynes-MacBook-Air.local>
Co-authored-by: Payne Fu <payne@Paynes-MacBook-Air.local>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent bec5ea4 commit 203c94c
File tree
17 files changed
+282
-4
lines changed- src
- main/services/agents/services/claudecode
- renderer/src
- components/Popups/agent
- i18n
- locales
- translate
- pages/settings/AgentSettings/components
- types
- utils
- __tests__
17 files changed
+282
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
167 | 198 | | |
168 | 199 | | |
169 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
169 | 191 | | |
170 | 192 | | |
171 | 193 | | |
| |||
455 | 477 | | |
456 | 478 | | |
457 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
458 | 491 | | |
459 | 492 | | |
460 | 493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
0 commit comments