Skip to content

Add devsecrets run to launch commands with secrets injected#5

Draft
peterkracik wants to merge 2 commits into
mainfrom
claude/auto-source-env-secrets-orvsvu
Draft

Add devsecrets run to launch commands with secrets injected#5
peterkracik wants to merge 2 commits into
mainfrom
claude/auto-source-env-secrets-orvsvu

Conversation

@peterkracik

Copy link
Copy Markdown
Owner

Summary

Adds a new run subcommand (alias exec) that automatically sources an environment's secrets into a command's environment. The secrets are injected as real environment variables (layered on top of the inherited environment), so the launched program "just sees" them — no .env file on disk and no manual eval.

devsecrets run -- npm start              # uses this folder's assigned project/env
devsecrets run -p api -e dev -- python app.py
devsecrets exec -p api -e dev --raw -- ./script.sh

This is the most direct way to load secrets for a single process: the variables exist only for the launched command and disappear when it exits.

What's included

  • run / exec subcommand (src/cli.rs): -p/--project, -e/--env, --raw, and a trailing <command>... (use -- to separate the command's own flags).
  • Implementation (src/commands.rs): resolves project/env from flags or the folder assignment (same logic as export), resolves ${...} references unless --raw, spawns the command with the secrets via Command::envs, and propagates the child's exit code.
  • Refactor: factored the shared project/env + resolved-values logic out of export into a resolve_env_values helper, now reused by both export and run.
  • Tests (tests/cli.rs): cover secret injection into the child env, the exec alias, --raw (references kept literal), and exit-code propagation.
  • Docs (README.md): new features bullet, a "Run a command with secrets" CLI section, and a "Run a command directly" entry under loading secrets into your shell.

Verification

  • cargo fmt --all --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test --all --locked ✓ (all unit + integration tests pass, including the two new run_* tests)

🤖 Generated with Claude Code


Generated by Claude Code

claude added 2 commits June 21, 2026 10:08
Adds a `run` subcommand (alias `exec`) that executes a command with an
environment's secrets injected as real environment variables, layered on
top of the inherited environment. This is the most direct way to "source"
secrets — the child process sees them without a `.env` file or manual eval.

- Resolves project/env from flags or the folder assignment, mirroring export.
- References are resolved unless `--raw`.
- Propagates the command's exit code.
- Factors the shared project/env resolution out of `export` into a helper.
- Integration tests cover injection, the `exec` alias, `--raw`, and exit-code
  propagation; README documents the new command.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C3zFWGBSgR1BBt8sVGXsEd
A child process can't change its parent shell's environment, so loading
secrets into your *current* shell must be done by the shell via eval.
`shellenv` prints a hardened `dsenv` function for ~/.bashrc / ~/.zshrc:

    eval "$(devsecrets shellenv)"
    dsenv -p api -e dev   # secrets now in the current shell, no prefix

The function captures `export --format shell` into a variable and only
eval's it on success, so a failed export never wipes the shell. Also lets
`run`/`exec` open an interactive subshell when given no command, as an
alternative no-prefix workflow. Integration tests drive a real shell to
verify dsenv loads values into the current shell, plus the subshell path.
README documents both, with `dsenv` as the recommended approach.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C3zFWGBSgR1BBt8sVGXsEd
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.

2 participants