Skip to content

feat: add opt-in $(command) substitution for .env values - #685

Open
kavin0x wants to merge 2 commits into
theskumar:mainfrom
kavin0x:feat/env-command-parsing
Open

feat: add opt-in $(command) substitution for .env values#685
kavin0x wants to merge 2 commits into
theskumar:mainfrom
kavin0x:feat/env-command-parsing

Conversation

@kavin0x

@kavin0x kavin0x commented Aug 19, 2026

Copy link
Copy Markdown

Summary

This adds optional command substitution for .env values using shell-style $(command) syntax — useful for things like pulling a token at load time:

GITHUB_TOKEN=$(gh auth token)

It's off by default. Enable it with execute_commands=True on load_dotenv() / dotenv_values(), or --execute-commands on the CLI (list, get, run).

Resolution happens after normal ${VAR} interpolation, so mixed values like PREFIX=${BASE}-$(echo suffix) work as expected. Failed commands log a warning and resolve to an empty string.

Test plan

  • uv run pytest — all feature tests pass (273+ passing locally)
  • Verified $(whoami), $(echo ...), ${VAR} + $(cmd) combos, and $(gh auth token) with real subprocesses
  • Confirmed default behavior unchanged (execute_commands=False leaves $(...) literal)
  • CLI --execute-commands covered in tests

Notes

  • Commands with ) inside $(...) aren't supported (documented in README)
  • Only intended for trusted .env files since commands run with the current process permissions

Disclaimer: AI tools were used to help with parts of the implementation and tests, but I reviewed everything before pushing.

Made with Cursor

kavin0x and others added 2 commits August 18, 2026 21:19
Enable shell command substitution via execute_commands=True on load_dotenv()
and dotenv_values(), or --execute-commands on the CLI, so trusted .env files
can populate variables from command output like gh auth token.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the gh auth token integration test that fails on unauthenticated
runners, skip POSIX shell env expansion on Windows, and use python
--version instead of printenv --version in CLI flag tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant