Skip to content

feat: add runtime environment variable configuration support#6

Open
YoungSx wants to merge 1 commit into
shantoislamdev:mainfrom
YoungSx:feat/env-conf
Open

feat: add runtime environment variable configuration support#6
YoungSx wants to merge 1 commit into
shantoislamdev:mainfrom
YoungSx:feat/env-conf

Conversation

@YoungSx

@YoungSx YoungSx commented Apr 29, 2026

Copy link
Copy Markdown

Description

This PR adds runtime environment variable support for adapter startup configuration.

The adapter now resolves config in this priority order:

ANTHROPIC_* environment variables > ~/.claude-adapter/config.json > interactive prompt

Environment variable overrides are runtime-only and are not persisted back to config.json.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Related Issues

N/A

Changes Made

  • Added resolveRuntimeConfig to centralize runtime config resolution.
  • Added environment variable mappings for:
    • ANTHROPIC_BASE_URL
    • ANTHROPIC_API_KEY
    • ANTHROPIC_AUTH_TOKEN
    • ANTHROPIC_DEFAULT_MODEL
    • ANTHROPIC_DEFAULT_OPUS_MODEL
    • ANTHROPIC_DEFAULT_SONNET_MODEL
    • ANTHROPIC_DEFAULT_HAIKU_MODEL
  • Added conflict warning when both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN are set.
  • Added URL validation in startup path to ensure invalid runtime base URLs fall back to prompt flow.
  • Wired runtime resolver into CLI startup while preserving existing persistence behavior.
  • Added dedicated unit tests for runtime config priority/fallback behavior.
  • Added @types/commander dev dependency to fix TypeScript declaration issues in editor/TS server.
  • Updated README with runtime priority and environment variable mapping examples.

Testing

Verified with:

  • npm run build
  • npm test -- runtimeConfig.test.ts cli.test.ts config.test.ts server.test.ts handlers.test.ts
  • npm test

Checklist:

  • Unit tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • I have updated the documentation accordingly
  • I have added tests that prove my fix/feature works
  • New and existing unit tests pass locally
  • I have updated CHANGELOG.md

Screenshots (if applicable)

N/A (CLI/runtime/config behavior changes only).

Additional Notes

  • --no-claude-settings is optional and only skips writing Claude settings files.
  • Runtime source summary logging was added to improve observability without exposing secret values.

- introduce `resolveRuntimeConfig` to prioritize env vars over file config
- add comprehensive environment variable mapping for baseUrl, apiKey, and model tiers
- include validation for URL and API key presence
- add warning system for conflicting environment variables
- update README with configuration priority and environment variable documentation
- add unit tests for runtime configuration resolution
- add `@types/commander` as dev dependency for type support

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 876fe336c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli.ts
Comment on lines 83 to 84
UI.log(''); // Spacing
const toolStyle = await promptForToolCallingStyle();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid forcing tool-style prompt for env-only startup

When runtime env vars provide a complete config but ~/.claude-adapter/config.json is absent, this branch still prompts for toolFormat because config.toolFormat is undefined. That makes the new env-driven startup path interactive-only, so headless runs (CI/scripts/non-TTY) will block or fail despite having ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY, and model env vars set. Since server code already defaults missing toolFormat to 'native', this prompt should be skipped (or defaulted) when no file-backed config exists.

Useful? React with 👍 / 👎.

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.

1 participant