Add environment variable passthrough allowlist for blocked vars#207
Add environment variable passthrough allowlist for blocked vars#207
Conversation
Bun auto-loads .env files into process.env, which means API keys stored in project .env files (e.g., ANTHROPIC_API_KEY) get silently passed to agent subprocesses, causing unexpected billing. The existing envExclude feature was opt-in only. This adds DEFAULT_ENV_EXCLUDE_PATTERNS (*_API_KEY, *_SECRET_KEY, *_SECRET) that are applied by default when spawning agent processes. Users can disable defaults with envExcludeDefaults = false if they explicitly need to pass these variables through. Closes #202 https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
…d detection Instead of a blunt on/off toggle for default exclusions, users can now specify exactly which blocked vars to allow through via envPassthrough. This supports exact names and glob patterns. Also adds getEnvExclusionReport() which scans the environment and categorizes vars into blocked (won't reach agent) vs allowed (in the passthrough list). This enables the UI/doctor to show users which keys from their .env files are being filtered. Config example: envPassthrough = ["ANTHROPIC_API_KEY"] # allow this specific key https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
When sensitive env vars are detected (matching *_API_KEY, *_SECRET_KEY, *_SECRET patterns), show which are blocked and which are in the passthrough list. This makes the filtering behavior visible to users. - doctor: shows in diagnostics output and DoctorResult JSON - info: included in SystemInfo and formatSystemInfo output - run: displayed upfront before preflight/engine initialization - create-prd: displayed before agent preflight check Also adds formatEnvExclusionReport() utility and passes envPassthrough config to create-prd agent initialization. https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
The env exclusion report was invisible unless the user happened to have environment variables matching the default patterns. Now formatEnvExclusionReport always returns output — either listing blocked/ allowed vars or confirming "no vars matched exclusion patterns". Removed the conditional guards from doctor, info, run, and create-prd commands. Also adds formatEnvExclusionReport tests, env section tests for info command output, and updates website docs with envPassthrough, default patterns, and three-layer filtering documentation. https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
The env filter report was being immediately wiped when the TUI renderer took over the terminal. Now pauses 3 seconds so users can read which vars are blocked. Only triggers when blocked vars exist and running in TUI mode — headless mode continues immediately for scripting/automation. https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
The 3s setTimeout wasn't working reliably. Now uses readline to prompt "Press Enter to continue..." which truly blocks the process. Only triggers when: blocked vars exist AND stdin is a TTY AND not headless. Piped stdin, CI, and --headless all skip the prompt automatically. https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
mergeConfigs was missing envPassthrough, causing it to be silently dropped when loading project config. Also adds schema validation tests for envExclude/envPassthrough and config shorthand resolution tests verifying top-level envPassthrough is applied to the default agent. https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
WalkthroughThis PR adds envPassthrough to configs, implements passthrough-aware environment exclusion logic and reporting in the base agent plugin, and surfaces formatted env-exclusion reports (with an optional TTY pause) across CLI commands (create-prd, run, doctor, info). Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant ProcessEnv as "process.env"
participant Registry
participant Agent as "BaseAgentPlugin"
CLI->>ProcessEnv: read env
CLI->>CLI: compute getEnvExclusionReport(process.env, stored.envPassthrough, stored.envExclude)
CLI->>User: print formatEnvExclusionReport(report)
alt blocked vars && stdin is TTY
User-->>CLI: press Enter
end
CLI->>Registry: registry.getInstance(..., initConfig.envPassthrough)
Registry->>Agent: initialize with envPassthrough & envExclude
Agent->>Agent: compute effective env via filterEnvByExcludeWithPassthrough()
CLI->>CLI: proceed with preflight / command flow
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #207 +/- ##
==========================================
+ Coverage 44.88% 45.02% +0.13%
==========================================
Files 84 84
Lines 24231 24403 +172
==========================================
+ Hits 10877 10988 +111
- Misses 13354 13415 +61
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Fix all issues with AI agents
In `@src/commands/doctor.ts`:
- Around line 210-220: The human-readable output in printHumanResult currently
omits the Environment section when result.envExclusion has no blocked/allowed
entries; update printHumanResult to always print the "Environment:" section and,
when both result.envExclusion.blocked and result.envExclusion.allowed are empty,
print the same "no vars matched" message used by runDiagnostics (or a consistent
"No vars matched" line) instead of skipping the section; locate code in
printHumanResult that checks result.envExclusion and modify the conditional and
console.log calls to mirror runDiagnostics behavior for consistency.
- Around line 90-101: The env exclusion report is being printed twice: once
inside runDiagnostics (using getEnvExclusionReport and formatEnvExclusionReport
followed by log calls) and again in printHumanResult; remove the duplicate by
deleting the logging block in runDiagnostics that builds envExclusion/envLines
and prints them, or wrap that block with a guard so it only runs when the final
human output will not be printed (e.g., skip when quiet is false and
printHumanResult will run). Target the code around runDiagnostics and the calls
to getEnvExclusionReport/formatEnvExclusionReport to eliminate the duplicate
logging.
In `@src/commands/info.ts`:
- Around line 309-314: The env exclusion report is built using only the
top-level config (config.envPassthrough/config.envExclude) so per-agent
overrides are ignored; resolve the target agent's env settings first (e.g.,
determine agentEnvPassthrough and agentEnvExclude from the agent's
config/overrides) and pass those into getEnvExclusionReport(process.env,
agentEnvPassthrough, agentEnvExclude) instead of
config.envPassthrough/config.envExclude so ralph-tui info reflects
agent-specific allowlists.
In `@src/commands/run.tsx`:
- Around line 1547-1571: The env exclusion report is being built from
storedConfig?.envPassthrough and storedConfig?.envExclude which can miss
per-agent overrides; change the call to getEnvExclusionReport to use the
resolved agent configuration (config.agent) values (e.g.,
config.agent.envPassthrough and config.agent.envExclude or the merged agent
config object) so the envReport reflects the actual runtime filtering used by
the agent (symbols: getEnvExclusionReport, envReport, storedConfig,
config.agent, envPassthrough, envExclude, options.headless,
process.stdin.isTTY).
In `@src/plugins/agents/base.ts`:
- Around line 105-115: The comment above DEFAULT_ENV_EXCLUDE_PATTERNS is
outdated—remove the reference to envExcludeDefaults and update it to state that
these patterns are excluded by default to prevent accidental API key leakage
(e.g., from auto-loaded .env files) unless the new envPassthrough option is
enabled; ensure the comment references DEFAULT_ENV_EXCLUDE_PATTERNS and
envPassthrough so readers understand the current behavior.
🧹 Nitpick comments (1)
src/commands/create-prd.tsx (1)
293-299: DuplicateloadStoredConfigcall causes redundant I/O.
loadStoredConfig(cwd)is already called insidegetAgent()at line 232, and the config is used there. Calling it again here at line 294 duplicates file reads. Consider either returningstoredConfigfromgetAgent()or passing the already-loaded config to avoid the redundant operation.
- doctor.ts: Remove duplicate env report logging from runDiagnostics (now only printed in printHumanResult); always show Environment section using formatEnvExclusionReport for consistency - info.ts: Resolve per-agent envPassthrough/envExclude overrides from the [[agents]] config array instead of using only top-level values - run.tsx: Use config.agent.envPassthrough/envExclude (resolved agent config) instead of storedConfig top-level values - base.ts: Update outdated comment on DEFAULT_ENV_EXCLUDE_PATTERNS to reference envPassthrough instead of removed envExcludeDefaults https://claude.ai/code/session_01Aj9WxkRvQcJG7PaXQXwNwk
…hl6ZV Add environment variable passthrough allowlist for blocked vars
Summary
This PR adds an
envPassthroughconfiguration option that allows users to explicitly allow specific environment variables to reach agent subprocesses, overriding the default exclusion patterns. This complements the existingenvExcludeoption and provides a three-layer filtering system for environment variables.Problem
Ralph TUI automatically blocks environment variables matching
*_API_KEY,*_SECRET_KEY, and*_SECRETto prevent accidental credential leakage (e.g., from.envfiles auto-loaded by Bun). However, there was no way for users to override these defaults when they legitimately need a blocked variable (e.g., when an agent genuinely requires an API key for authentication).Solution
Introduces
envPassthroughas a new configuration option that creates an allowlist for variables that would otherwise be blocked. This enables a three-layer filtering system:*_API_KEY,*_SECRET_KEY,*_SECRET(always applied)Key Changes
New exports from
base.ts:DEFAULT_ENV_EXCLUDE_PATTERNS— exported constant for the default blocking patternsgetEnvExclusionReport()— analyzes current environment and categorizes variables as blocked vs. allowedformatEnvExclusionReport()— formats the report as human-readable console outputEnvExclusionReportinterface — type for the report structureUpdated
BaseAgentPlugin:envPassthroughfield to store passthrough patternsfilterEnvByExcludeWithPassthrough()to apply three-layer filteringgetExclusionReport()method for diagnosticsexecute()to use default patterns + user excludes + passthrough logicConfiguration updates:
envPassthroughtoAgentPluginConfigandStoredConfigschemasenvPassthroughto type definitions with documentationUser-facing improvements:
ralph-tui runandralph-tui primenow display env filter report before startingralph-tui doctorincludes env exclusion report in diagnostics outputralph-tui infoincludes env exclusion report in system informationDocumentation:
options.mdxexplaining the three-layer filtering systemTests:
envPassthroughallowlist functionalityenvExcludeandenvPassthroughgetEnvExclusionReport()andformatEnvExclusionReport()functionsgetExclusionReport()methodImplementation Details
runcommand)Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.