Skip to content

feat(runtime): wire per-agent auth profile to CLI env injection (#422)#433

Merged
alexey-pelykh merged 1 commit intomainfrom
feat/422-wire-auth-env-injection
Mar 8, 2026
Merged

feat(runtime): wire per-agent auth profile to CLI env injection (#422)#433
alexey-pelykh merged 1 commit intomainfrom
feat/422-wire-auth-env-injection

Conversation

@alexey-pelykh
Copy link
Copy Markdown

Summary

  • Add resolveAuthEnv() in src/auth/env-injection.ts to resolve per-agent auth profile references to CLI subprocess environment variables
  • Add resolveProviderEnvVarName() mapping providers to their primary env var (anthropic→ANTHROPIC_API_KEY, google→GEMINI_API_KEY, etc.)
  • Implement round-robin rotation for auth: ["id1", "id2"] array configs with per-agent tracking (resets on process restart)
  • Wire into agent-runner-execution.ts: auth profile env vars override runtimeEnv (highest credential precedence)
  • Graceful fallback: missing/invalid profiles log a warning and fall through to next precedence level

Credential precedence (highest → lowest)

agent.auth profile key → runtimeEnv → process.env → CLI-native auth

Test plan

  • Auth profile key injected as correct env var for each provider type (18 unit tests)
  • auth: false results in no profile injection
  • runtimeEnv is overridden by auth profile when both set same var (spread order)
  • Round-robin cycles through array entries across calls
  • Missing/invalid profile ID logs warning, falls through (returns undefined)
  • Inherits auth from agents.defaults.auth
  • Unknown provider returns undefined (no env var mapping)
  • Empty auth array returns undefined
  • Per-agent rotation tracking (independent state per agent ID)

Closes #422

🤖 Generated with Claude Code

Resolve the agent's `auth` config field to environment variables and
inject them into the CLI subprocess environment, completing the
auth-profile → runtime credential pipeline.

- Add `resolveAuthEnv()` to resolve profile references to env vars
- Add `resolveProviderEnvVarName()` for provider → env var mapping
- Implement round-robin rotation for auth profile arrays
- Integrate into agent runner: auth env overrides runtimeEnv

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alexey-pelykh alexey-pelykh enabled auto-merge (squash) March 8, 2026 08:41
@alexey-pelykh alexey-pelykh merged commit 70c6254 into main Mar 8, 2026
5 checks passed
@alexey-pelykh alexey-pelykh deleted the feat/422-wire-auth-env-injection branch March 8, 2026 08:49
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(runtime): wire per-agent auth profile to CLI env injection

1 participant