Skip to content

feat(bash): add env parameter for setting environment variables#21756

Open
taxilian wants to merge 3 commits intoanomalyco:devfrom
taxilian:add-bash-env-parameter
Open

feat(bash): add env parameter for setting environment variables#21756
taxilian wants to merge 3 commits intoanomalyco:devfrom
taxilian:add-bash-env-parameter

Conversation

@taxilian
Copy link
Copy Markdown

@taxilian taxilian commented Apr 9, 2026

Issue for this PR

Closes #21753

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Add optional env parameter to the bash tool that allows passing environment variables to spawned processes. This enables plugins to inject variables like AGENT_MODE and AGENT_ID to track whether commands run in primary or subagent sessions. The env vars are merged with the shell environment.

This is a replacement for the previously closed PR #11068 / issue #11065 - the need persists and workarounds continue to cause issues.

How did you verify your code works?

Added tests in bash.test.ts for single and multiple environment variables.

Screenshots / recordings

N/A - no UI changes

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

taxilian added 3 commits April 9, 2026 16:37
Add optional `env` parameter to the bash tool that allows passing
environment variables to the spawned process. This enables plugins
to inject environment variables like AGENT_MODE and AGENT_ID to
track whether commands are running in primary or subagent sessions.

Changes:
- Add `env` parameter to bash tool schema (z.record(z.string(), z.string()))
- Merge env vars with process.env in spawn call
- Add tests for single and multiple environment variables
Use Bun's process.env instead of shell-specific echo syntax for cross-platform support

- Replace Unix $VAR syntax with bun -e "console.log(process.env.VAR)"

- Use existing test helpers (bin, evalarg) for proper quoting

- Tests now pass on Windows regardless of shell type
@taxilian taxilian force-pushed the add-bash-env-parameter branch from 43d2eb8 to 43840f7 Compare April 9, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(bash): add env parameter for setting environment variables

1 participant