Skip to content

feat(config): add explicit provider env-file loading#1668

Merged
kevincodex1 merged 9 commits into
Gitlawb:mainfrom
chioarub:fix/env-example-loading-clarity
Jun 18, 2026
Merged

feat(config): add explicit provider env-file loading#1668
kevincodex1 merged 9 commits into
Gitlawb:mainfrom
chioarub:fix/env-example-loading-clarity

Conversation

@chioarub

@chioarub chioarub commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an explicit --provider-env-file <path> option for users who prefer file-based provider setup while keeping project .env files opt-in.

Problem

.env.example encouraged copying values into .env, but OpenClaude did not automatically load that file. Users could follow the template and still see missing provider key errors.

Chosen solution

  • Load explicitly provided provider env files before provider selection and validation.
  • Support a small, predictable .env syntax: KEY=VALUE, quoted values, comments, and export KEY=VALUE.
  • Preserve existing shell environment values over file values.
  • Update setup docs to clarify that .env is not auto-loaded and that /provider remains the recommended guided setup path.

Security model

  • No automatic loading of project .env files.
  • Only exact provider/setup variable names are accepted by the explicit loader.
  • Process and runtime-control variables such as PATH, NODE_OPTIONS, and LD_PRELOAD are rejected.
  • Error messages include file and line context without printing secret values.

Validation

  • bun test --max-concurrency=1 — 4093 pass, 0 fail, 10100 expectations.
  • bun run typecheck — passed.
  • bun run build — passed; CLI and SDK bundles built and validated.
  • node bin/openclaude --version0.18.0 (OpenClaude).
  • Manual scrubbed-env CLI checks verified explicit loading, no implicit .env loading, unsupported variable rejection, and lowercase env-name rejection.
  • CodeRabbit review ran on the uncommitted diff; valid trivial comments were addressed. A final rerun was rate-limited by the free CLI quota.

Summary by CodeRabbit

  • New Features
    • Added a repeatable --provider-env-file <path> option to explicitly load provider-scoped .env variables from one or more files during startup.
  • Bug Fixes
    • Ensures provider env-file values are preserved by reliably reapplying them after startup/profile/settings merges.
    • Improved behavior for startup hook scheduling when invoked from /fromPr, plus clearer validation and fail-fast errors for malformed/unsupported env lines.
  • Documentation
    • Updated .env.example, README, and Quick Start guides with optional .env usage, ordering notes, and troubleshooting.
  • Tests
    • Added/expanded tests for parsing, validation, CLI flag handling, and env-file value persistence.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5239a862-7efc-41a9-8e45-612b8b6c6526

📥 Commits

Reviewing files that changed from the base of the PR and between 466985f and 886f015.

📒 Files selected for processing (3)
  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
  • src/main.tsx
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (12)
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript with strict mode and ESM imports

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**/*.{ts,tsx,js,jsx,py,json,md}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow the existing code style in the touched files

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow TypeScript strict mode and type safety practices by running typecheck before submitting

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}

⚙️ CodeRabbit configuration file

{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}: Review install, launcher, build, packaging, startup, and entrypoint changes for cross-platform compatibility, tracked-source rewrites, env/config precedence, and release safety. Block on changes that can break Windows/macOS/Linux startup or publish unexpected artifacts.

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.
  • Python exists for legacy/local-provider helper code. Do not add new Python code or expand Python-based features unless a maintainer explicitly approves that direction.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • `src/integration...

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
{src/commands/**/*.ts,src/services/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use chalk for terminal color in CLI code

Files:

  • src/entrypoints/cli.test.ts
{src/commands/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use commander for CLI argument parsing

Files:

  • src/entrypoints/cli.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add or update tests when the change affects behavior

Files:

  • src/entrypoints/cli.test.ts
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Test the exact provider/model path you changed when possible

Files:

  • src/entrypoints/cli.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/entrypoints/cli.test.ts
🔇 Additional comments (3)
src/main.tsx (1)

2353-2356: LGTM!

src/entrypoints/cli.tsx (1)

144-148: LGTM!

Also applies to: 213-218, 240-241, 249-250

src/entrypoints/cli.test.ts (1)

23-27: LGTM!

Also applies to: 151-152, 155-156, 161-162, 180-181, 266-289


📝 Walkthrough

Walkthrough

Adds explicit .env file loading via a new --provider-env-file <path> CLI flag. A new src/utils/envFile.ts module implements an allowlist-based .env parser and loader that writes only undefined keys to process.env. The flag is registered in Commander and handled early in the CLI bootstrap with strategic reapplication after settings and profile merges to maintain provider env precedence. All quick-start guides, README, and .env.example are updated to document the new flag and clarify that .env files are not auto-loaded.

Changes

--provider-env-file feature

Layer / File(s) Summary
envFile utility: allowlist, parser, and loader
src/utils/envFile.ts
New module defining the allowed-key allowlist (fixed keys plus VERTEX_REGION_CLAUDE_* prefix matching), internal quote-parsing helpers for escaped delimiters, parseEnvFile for line-by-line KEY=VALUE parsing with optional export prefix and key validation, parseProviderEnvFileArgs for CLI argument scanning with -- stop support, applyLoadedEnvFileValues for object assignment, and loadEnvFile for allowlist validation and non-overwrite writes to process.env with wrapped error messages. Also tracks loaded values in-memory via rememberLoadedEnvFileValues and reapplyRememberedEnvFileValues for restoration after subsequent env mutations.
envFile test suite
src/utils/envFile.test.ts
Comprehensive Bun test coverage with environment-variable save/restore harness. Tests parseEnvFile for quotes (single and double), escaped quote characters, trimming, optional export prefix, empty values, inner = preservation, duplicate keys (last-value-wins), comment rules, Windows CRLF, and error cases. Tests loadEnvFile for non-overwrite semantics, allowlist enforcement with case sensitivity, multiple files with earliest-value precedence, file read and parse error wrapping (without leaking secrets), and remembering/reapplying loaded values. Tests parseProviderEnvFileArgs for repeatable path extraction, missing-path errors, and -- end-of-options stopping.
CLI option registration and bootstrap integration
src/main.tsx, src/entrypoints/cli.tsx
src/main.tsx registers the repeatable --provider-env-file <path> Commander option with array accumulation. src/entrypoints/cli.tsx adds envFile() to dynamic importers, declares internal reapplication placeholders and a combined reapply helper, and adds an early bootstrap block in main() that dynamically imports env-file utilities, parses flag arguments, loads each env file into remembered values (exits with code 1 on failures), and wires reapply. The combined function is invoked after initial config setup and again after profile/provider routing application to preserve env-file values before validation.
Environment variable precedence in managed flows
src/utils/managedEnv.ts
Imports and invokes reapplyRememberedEnvFileValues() in both applySafeConfigEnvironmentVariables() and applyConfigEnvironmentVariables() flows—after settings merges and before reapplyRememberedProviderFlag()—to prevent settings-derived env from overwriting explicit provider routing/compatibility mappings from CLI/env-file inputs.
CLI ordering regression and managed env test
src/entrypoints/cli.test.ts, src/utils/managedEnv.test.ts
src/entrypoints/cli.test.ts adds environment isolation infrastructure, temp .env file helpers, and regression tests verifying provider env-file values survive both settings and profile env application merges via strategic reapplication. Also adds assertions for correct parseProviderEnvFileArgs and reapplyRememberedEnvFileValues invocation in background routing paths vs. management-command dispatch. src/utils/managedEnv.test.ts adds isolation harness and verifies applyConfigEnvironmentVariables() restores remembered env-file values after merging full settings env values.
Documentation updates
.env.example, README.md, docs/quick-start-mac-linux.md, docs/quick-start-windows.md, docs/non-technical-setup.md
.env.example is rewritten to clarify non-auto-loading, explain --provider-env-file with allowlist semantics (provider/setup accepted; process-control rejected), and refine LOAD ORDER behavior. README.md adds a Quick Start note on auto-loading and credential setup options. Quick-start guides for macOS/Linux and Windows each add "Option E" sections with --provider-env-file command examples, .env hygiene guidance, and runtime/debug variable separation. docs/non-technical-setup.md adds a troubleshooting subsection explaining why provider keys are not picked up after copying .env.example, with explicit causes and multiple remediation paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Gitlawb/openclaude#1560: Both PRs prevent provider environment variables set via CLI/env-file from being overwritten by settings—this PR preserves them via explicit reapplication after settings merges, while #1560 changes startup profile precedence to avoid overwriting them in the first place.

Suggested labels

enhancement

Suggested reviewers

  • jatmn
  • kevincodex1
🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.42% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding an explicit provider env-file loading feature via a new CLI option.
Description check ✅ Passed The description covers problem statement, solution, security model, and comprehensive validation results, matching the template structure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Risk Surface Disclosed ✅ Passed PR touches auth, provider routing, and startup behavior with clear security controls: allowlist-based variable validation, rejection of dangerous vars (NODE_OPTIONS, PATH, LD_PRELOAD), case-sensiti...
No Hidden Policy Change ✅ Passed No hidden policy changes. PR explicitly adds --provider-env-file flag with strict allowlist of provider/setup vars, rejects dangerous process/runtime variables, and requires explicit invocation—n...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/utils/envFile.ts`:
- Around line 125-137: The issue is that the closingQuoteIdx calculation using
value.indexOf(quote, 1) doesn't account for escaped quotes, so it incorrectly
stops at the first escaped quote (like the \" in JSON strings) rather than the
actual closing quote. Modify the logic that finds the closingQuoteIdx to
properly iterate through the string and skip over escaped quotes (quotes
preceded by a backslash), continuing until it finds an unescaped quote character
that matches the opening quote. This will allow valid entries with escaped
quotes like JSON objects to be parsed correctly without triggering the
"unexpected content after quoted value" error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3b785a40-9c82-462f-8260-cbb0a05e156a

📥 Commits

Reviewing files that changed from the base of the PR and between 7be9dce and dd93094.

📒 Files selected for processing (9)
  • .env.example
  • README.md
  • docs/non-technical-setup.md
  • docs/quick-start-mac-linux.md
  • docs/quick-start-windows.md
  • src/entrypoints/cli.tsx
  • src/main.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: typecheck
🧰 Additional context used
📓 Path-based instructions (6)
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • docs/quick-start-mac-linux.md
  • docs/quick-start-windows.md
  • docs/non-technical-setup.md
  • README.md
  • src/entrypoints/cli.tsx
  • src/main.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}

⚙️ CodeRabbit configuration file

{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}: Review docs for accuracy against current code behavior. Flag security or provider claims that overpromise, stale install commands, missing setup caveats, and instructions that could push users toward unsafe credential handling. Keep purely wording-level suggestions non-blocking.

Files:

  • docs/quick-start-mac-linux.md
  • docs/quick-start-windows.md
  • docs/non-technical-setup.md
  • README.md
**

⚙️ CodeRabbit configuration file

**: # Contributing to OpenClaude

Thanks for contributing.

OpenClaude is a fast-moving open-source coding-agent CLI with support for multiple providers, local backends, MCP, and a terminal-first workflow. The best contributions here are focused, well-tested, and easy to review.

Before You Start

  • Search existing issues and discussions before opening a new thread.
  • Check open pull requests for work that overlaps with your contribution. If a PR already exists that addresses the same change, open an issue or discussion first to align on direction — duplicate PRs may be closed without review.
  • Use issues for confirmed bugs and actionable feature work.
  • Use discussions for setup help, ideas, and general community conversation.
  • For larger changes, open an issue first so the scope is clear before implementation.
  • For security reports, follow SECURITY.md.

Pull Requests

Every PR needs a reason. Your PR description must include:

  • what changed and why
  • the user or developer impact
  • the exact checks you ran
  • a linked issue when one exists, using Fixes #123, `Closes `#123, or another clear link
  • screenshots when the PR touches UI, terminal presentation, or the VS Code extension
  • which provider path was tested when the PR changes provider behavior

The PR author is responsible for ensuring their PR is merge-ready. PRs with merge conflicts will not be reviewed or approved until the conflicts are resolved.

Issues are the recommended starting point for anything non-trivial — opening one first helps avoid wasted effort if the change is out of scope or already being worked on. Small fixes, doc corrections, and obvious improvements can stand on their own without a linked issue, as long as the PR description explains the intent.

What Gets Closed Without Review

PRs may be closed without review...

Files:

  • docs/quick-start-mac-linux.md
  • docs/quick-start-windows.md
  • docs/non-technical-setup.md
  • README.md
  • src/entrypoints/cli.tsx
  • src/main.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise in code

Files:

  • src/entrypoints/cli.tsx
  • src/main.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}

⚙️ CodeRabbit configuration file

{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}: Review install, launcher, build, packaging, startup, and entrypoint changes for cross-platform compatibility, tracked-source rewrites, env/config precedence, and release safety. Block on changes that can break Windows/macOS/Linux startup or publish unexpected artifacts.

Files:

  • src/entrypoints/cli.tsx
  • src/main.tsx
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/envFile.test.ts
🪛 ast-grep (0.43.0)
src/utils/envFile.test.ts

[warning] 187-187: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(Failed to load --provider-env-file at ${filePath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}:)
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)

🔇 Additional comments (3)
src/main.tsx (1)

957-960: LGTM!

src/entrypoints/cli.tsx (1)

81-99: LGTM!

src/utils/envFile.test.ts (1)

1-241: LGTM!

Comment thread src/utils/envFile.ts
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 16, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 16, 2026

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I found an issue that needs to be addressed before this is ready.

Findings

  • [P2] Preserve explicit env-file values across saved settings
    src/entrypoints/cli.tsx:83
    The new loader applies --provider-env-file before applySafeConfigEnvironmentVariables() and saved profile startup run, but those later steps can still Object.assign global/user/policy/settings env back over process.env. That means a user who already has a saved /provider profile or settings.env can run openclaude --provider-env-file .env and still get the old saved provider key/model/base URL instead of the file they explicitly passed. --provider already has a remembered/reapplied path to survive the same settings merge; please give --provider-env-file equivalent explicit-CLI precedence, or move its loading to the point where later saved settings/profile hydration cannot clobber it.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/entrypoints/cli.test.ts`:
- Around line 89-109: The test in cli.test.ts currently validates only source
code ordering by searching for function names like Object.assign,
applySafeConfigEnvironmentVariables, reapplyProviderEnvFileValues, and
applyStartupEnvFromProfile using indexOf checks. This tests implementation
details rather than actual runtime behavior. Replace this test with a
behavior-level regression test that exercises the startup merge path by setting
up provider env file values, applying settings environment variables, applying
startup profile environment, and then asserting that the final environment
values still contain the provider env file values with correct precedence after
all merges complete.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 41f3df20-1f0a-48fa-b911-5cd5dcb0dcea

📥 Commits

Reviewing files that changed from the base of the PR and between 880724d and 1ea540d.

📒 Files selected for processing (4)
  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise in code

Files:

  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}

⚙️ CodeRabbit configuration file

{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}: Review install, launcher, build, packaging, startup, and entrypoint changes for cross-platform compatibility, tracked-source rewrites, env/config precedence, and release safety. Block on changes that can break Windows/macOS/Linux startup or publish unexpected artifacts.

Files:

  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/entrypoints/cli.test.ts
  • src/utils/envFile.test.ts
**

⚙️ CodeRabbit configuration file

**: # Contributing to OpenClaude

Thanks for contributing.

OpenClaude is a fast-moving open-source coding-agent CLI with support for multiple providers, local backends, MCP, and a terminal-first workflow. The best contributions here are focused, well-tested, and easy to review.

Before You Start

  • Search existing issues and discussions before opening a new thread.
  • Check open pull requests for work that overlaps with your contribution. If a PR already exists that addresses the same change, open an issue or discussion first to align on direction — duplicate PRs may be closed without review.
  • Use issues for confirmed bugs and actionable feature work.
  • Use discussions for setup help, ideas, and general community conversation.
  • For larger changes, open an issue first so the scope is clear before implementation.
  • For security reports, follow SECURITY.md.

Pull Requests

Every PR needs a reason. Your PR description must include:

  • what changed and why
  • the user or developer impact
  • the exact checks you ran
  • a linked issue when one exists, using Fixes #123, `Closes `#123, or another clear link
  • screenshots when the PR touches UI, terminal presentation, or the VS Code extension
  • which provider path was tested when the PR changes provider behavior

The PR author is responsible for ensuring their PR is merge-ready. PRs with merge conflicts will not be reviewed or approved until the conflicts are resolved.

Issues are the recommended starting point for anything non-trivial — opening one first helps avoid wasted effort if the change is out of scope or already being worked on. Small fixes, doc corrections, and obvious improvements can stand on their own without a linked issue, as long as the PR description explains the intent.

What Gets Closed Without Review

PRs may be closed without review...

Files:

  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
  • src/utils/envFile.test.ts
  • src/utils/envFile.ts
🔇 Additional comments (3)
src/utils/envFile.ts (1)

276-277: LGTM!

Also applies to: 279-297

src/entrypoints/cli.tsx (1)

72-75: LGTM!

Also applies to: 96-96, 130-130, 141-141

src/utils/envFile.test.ts (1)

14-14: LGTM!

Also applies to: 159-159, 163-181

Comment thread src/entrypoints/cli.test.ts Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 16, 2026
@chioarub chioarub requested a review from jatmn June 16, 2026 19:43

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update. I rechecked the changed paths and found a couple of issues that still need to be addressed.

Findings

  • [P2] Preserve env-file values through the full settings apply path
    src/utils/managedEnv.ts:198
    My earlier review request is only partially fixed in the current patch. cli.tsx now reapplies the env-file values after the early safe settings/profile merges, but real startup later calls applyConfigEnvironmentVariables() in both interactive and --print paths, and that function still Object.assigns the merged settings env back into process.env while only restoring --provider via reapplyRememberedProviderFlag(). A user can still run openclaude --provider-env-file .env -p ... from a trusted project with project/user settings.env values and have those later settings replace the file key/model/base URL before the request runs. Please carry the remembered env-file values through the same full settings application path, or otherwise ensure later settings/profile hydration cannot clobber the explicitly loaded file.

  • [P2] Allow the documented Azure API version env var
    src/utils/envFile.ts:22
    The new loader rejects every key not in ALLOWED_ENV_FILE_KEYS, but the documented Azure resource-base setup requires AZURE_OPENAI_API_VERSION, and the OpenAI shim reads that variable when building the Azure chat-completions URL. With this PR, putting the documented Azure env block into a file and running openclaude --provider-env-file .env fails with Unsupported variable AZURE_OPENAI_API_VERSION, so the new file-based workflow does not work for one of the supported provider configurations. Please include the Azure API-version variable in the provider/setup allowlist or adjust the docs/runtime contract accordingly.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 16, 2026

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update. I rechecked the changed paths and found one issue that still needs to be addressed.

Findings

  • [P2] Include the documented setup variables in the env-file allowlist
    src/utils/envFile.ts:5
    The new loader rejects any key missing from ALLOWED_ENV_FILE_KEYS, but it still omits documented setup variables that users reasonably put in the same .env workflow this PR introduces. For example, .env.example and the web-search provider docs document WEB_SEARCH_API, WEB_URL_TEMPLATE, WEB_CUSTOM_ALLOW_PRIVATE, and related custom web-search variables, while docs/advanced-setup.md documents CODEX_AUTH_JSON_PATH for Codex auth-file setup. Running openclaude --provider-env-file .env with either documented block now exits before startup with Unsupported variable WEB_SEARCH_API or Unsupported variable CODEX_AUTH_JSON_PATH. Please either allow the documented provider/setup variables that are safe for this explicit loader, or update the docs so users are not told this file-based setup path supports configurations that it rejects.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 16, 2026
@chioarub chioarub requested a review from jatmn June 16, 2026 23:19
jatmn
jatmn previously approved these changes Jun 17, 2026

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update. I rechecked the previously discussed paths and do not see any remaining actionable issues from my side.

@kevincodex1 LGTM

@kevincodex1

Copy link
Copy Markdown
Contributor

please rebase to main and fix conflicts @chioarub

@chioarub chioarub dismissed stale reviews from jatmn and coderabbitai[bot] via 466985f June 17, 2026 06:03

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/entrypoints/cli.test.ts (1)

226-255: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add a regression for --provider winning over env-file values.

This test covers settings/profile overwrites, but not the conflicting explicit CLI provider case. Add a case that loads an env file for one provider, applies/remembers --provider for another provider, runs both reapply checkpoints, and asserts the provider flag remains authoritative.

As per coding guidelines, “Add or update tests when the change affects behavior” and “Test the exact provider/model path you changed when possible.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/entrypoints/cli.test.ts` around lines 226 - 255, Add a new test case that
validates the precedence of explicit --provider CLI arguments over env-file
values in conflict scenarios. The test should load an env file containing one
provider configuration using loadEnvFile, then apply a different provider via a
--provider CLI argument (simulating the CLI flag), call applyLoadedEnvFileValues
twice to simulate the reapply checkpoints, and finally assert that the
environment variables reflect the CLI provider values rather than the env-file
values, demonstrating that the explicit provider flag remains authoritative
throughout the merging process.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 110-134: The "Background sessions" documentation section in the
README appears to be unrelated to the PR's stated scope of adding the
--provider-env-file CLI option. Either update the PR description to clarify that
background session documentation is intentionally included in the expanded
scope, or move this entire section (the Background sessions heading and all
associated content showing openclaude --bg, ps, logs, kill, and attach commands)
to a separate pull request focused specifically on background sessions feature
documentation.

In `@src/entrypoints/cli.tsx`:
- Line 143: The reapplyProviderEnvFileValues function on line 143 needs to
ensure the --provider flag takes precedence over env-file values. The issue is
that reapplyRememberedEnvFileValues() uses Object.assign to restore env-file
settings, which can overwrite the --provider flag if called after the provider
is set. Modify the reapplyProviderEnvFileValues implementation to reapply the
remembered provider flag value after restoring any env-file values, ensuring
that standalone calls to reapplyRememberedEnvFileValues on lines 231 and 240 do
not override the provider precedence. This ensures that when both --provider and
env-file contain conflicting settings, the --provider flag maintains its
intended precedence.

In `@src/main.tsx`:
- Line 2522: The interactive resume path's hooksPromise guard at line 2353 does
not suppress the startup hooks when fromPr is set, while the headless path at
line 2522 correctly does so. Add `|| options.fromPr` to the condition that
determines whether to call `processSessionStartHooks('startup')` in the
interactive path to mirror the suppression logic from the headless path. This
ensures startup hooks are consistently suppressed for PR-resume flows in both
code paths, preventing duplicate or conflicting resume lifecycle output.

---

Outside diff comments:
In `@src/entrypoints/cli.test.ts`:
- Around line 226-255: Add a new test case that validates the precedence of
explicit --provider CLI arguments over env-file values in conflict scenarios.
The test should load an env file containing one provider configuration using
loadEnvFile, then apply a different provider via a --provider CLI argument
(simulating the CLI flag), call applyLoadedEnvFileValues twice to simulate the
reapply checkpoints, and finally assert that the environment variables reflect
the CLI provider values rather than the env-file values, demonstrating that the
explicit provider flag remains authoritative throughout the merging process.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a90cc4c9-bce2-489b-9cff-e8ffb891f950

📥 Commits

Reviewing files that changed from the base of the PR and between 08b90bd and 466985f.

📒 Files selected for processing (4)
  • README.md
  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
  • src/main.tsx
📜 Review details
🧰 Additional context used
📓 Path-based instructions (13)
**/*.{ts,tsx,js,jsx,py,json,md}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow the existing code style in the touched files

Files:

  • README.md
  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • README.md
  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}

⚙️ CodeRabbit configuration file

{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}: Review docs for accuracy against current code behavior. Flag security or provider claims that overpromise, stale install commands, missing setup caveats, and instructions that could push users toward unsafe credential handling. Keep purely wording-level suggestions non-blocking.

Files:

  • README.md
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.
  • Python exists for legacy/local-provider helper code. Do not add new Python code or expand Python-based features unless a maintainer explicitly approves that direction.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • `src/integration...

Files:

  • README.md
  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript with strict mode and ESM imports

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow TypeScript strict mode and type safety practices by running typecheck before submitting

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}

⚙️ CodeRabbit configuration file

{bin/**,scripts/**,package.json,src/setup.ts,src/main.tsx,src/entrypoints/**}: Review install, launcher, build, packaging, startup, and entrypoint changes for cross-platform compatibility, tracked-source rewrites, env/config precedence, and release safety. Block on changes that can break Windows/macOS/Linux startup or publish unexpected artifacts.

Files:

  • src/main.tsx
  • src/entrypoints/cli.tsx
  • src/entrypoints/cli.test.ts
{src/commands/**/*.ts,src/services/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use chalk for terminal color in CLI code

Files:

  • src/entrypoints/cli.test.ts
{src/commands/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use commander for CLI argument parsing

Files:

  • src/entrypoints/cli.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add or update tests when the change affects behavior

Files:

  • src/entrypoints/cli.test.ts
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Test the exact provider/model path you changed when possible

Files:

  • src/entrypoints/cli.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/entrypoints/cli.test.ts
🔇 Additional comments (4)
README.md (1)

108-108: Documentation note for --provider-env-file is accurate and well-positioned.

The new note correctly documents the non-auto-loading behavior, recommends the secure /provider path first, and properly guides users toward environment-based setup with allowlist semantics. The guidance to export runtime/debug variables separately aligns with the implementation's rejection of process-control variables.

src/main.tsx (1)

958-960: LGTM!

Also applies to: 2749-2749, 3751-3758

src/entrypoints/cli.tsx (1)

70-142: LGTM!

Also applies to: 153-203, 221-230, 246-300, 310-315, 320-320, 535-541, 547-550

src/entrypoints/cli.test.ts (1)

6-23: LGTM!

Also applies to: 25-96, 257-287, 289-449

@coderabbitai coderabbitai 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/entrypoints/cli.test.ts (1)

226-255: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add a regression for --provider winning over env-file values.

This test covers settings/profile overwrites, but not the conflicting explicit CLI provider case. Add a case that loads an env file for one provider, applies/remembers --provider for another provider, runs both reapply checkpoints, and asserts the provider flag remains authoritative.

As per coding guidelines, “Add or update tests when the change affects behavior” and “Test the exact provider/model path you changed when possible.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/entrypoints/cli.test.ts` around lines 226 - 255, Add a new test case that
validates the precedence of explicit --provider CLI arguments over env-file
values in conflict scenarios. The test should load an env file containing one
provider configuration using loadEnvFile, then apply a different provider via a
--provider CLI argument (simulating the CLI flag), call applyLoadedEnvFileValues
twice to simulate the reapply checkpoints, and finally assert that the
environment variables reflect the CLI provider values rather than the env-file
values, demonstrating that the explicit provider flag remains authoritative
throughout the merging process.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 110-134: The "Background sessions" documentation section in the
README appears to be unrelated to the PR's stated scope of adding the
--provider-env-file CLI option. Either update the PR description to clarify that
background session documentation is intentionally included in the expanded
scope, or move this entire section (the Background sessions heading and all
associated content showing openclaude --bg, ps, logs, kill, and attach commands)
to a separate pull request focused specifically on background sessions feature
documentation.

In `@src/entrypoints/cli.tsx`:
- Line 143: The reapplyProviderEnvFileValues function on line 143 needs to
ensure the --provider flag takes precedence over env-file values. The issue is
that reapplyRememberedEnvFileValues() uses Object.assign to restore env-file
settings, which can overwrite the --provider flag if called after the provider
is set. Modify the reapplyProviderEnvFileValues implementation to reapply the
remembered provider flag value after restoring any env-file values, ensuring
that standalone calls to reapplyRememberedEnvFileValues on lines 231 and 240 do
not override the provider precedence. This ensures that when both --provider and
env-file contain conflicting settings, the --provider flag maintains its
intended precedence.

In `@src/main.tsx`:
- Line 2522: The interactive resume path's hooksPromise guard at line 2353 does
not suppress the startup hooks when fromPr is set, while the headless path at
line 2522 correctly does so. Add `|| options.fromPr` to the condition that
determines whether to call `processSessionStartHooks('startup')` in the
interactive path to mirror the suppression logic from the headless path. This
ensures startup hooks are consistently suppressed for PR-resume flows in both
code paths, preventing duplicate or conflicting resume lifecycle output.

---

Outside diff comments:
In `@src/entrypoints/cli.test.ts`:
- Around line 226-255: Add a new test case that validates the precedence of
explicit --provider CLI arguments over env-file values in conflict scenarios.
The test should load an env file containing one provider configuration using
loadEnvFile, then apply a different provider via a --provider CLI argument
(simulating the CLI flag), call applyLoadedEnvFileValues twice to simulate the
reapply checkpoints, and finally assert that the environment variables reflect
the CLI provider values rather than the env-file values, demonstrating that the
explicit provider flag remains authoritative throughout the merging process.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a90cc4c9-bce2-489b-9cff-e8ffb891f950

📥 Commits

Reviewing files that changed from the base of the PR and between 08b90bd and 466985f.

📒 Files selected for processing (4)
  • README.md
  • src/entrypoints/cli.test.ts
  • src/entrypoints/cli.tsx
  • src/main.tsx
📜 Review details
🔇 Additional comments (4)
README.md (1)

108-108: Documentation note for --provider-env-file is accurate and well-positioned.

The new note correctly documents the non-auto-loading behavior, recommends the secure /provider path first, and properly guides users toward environment-based setup with allowlist semantics. The guidance to export runtime/debug variables separately aligns with the implementation's rejection of process-control variables.

src/main.tsx (1)

958-960: LGTM!

Also applies to: 2749-2749, 3751-3758

src/entrypoints/cli.tsx (1)

70-142: LGTM!

Also applies to: 153-203, 221-230, 246-300, 310-315, 320-320, 535-541, 547-550

src/entrypoints/cli.test.ts (1)

6-23: LGTM!

Also applies to: 25-96, 257-287, 289-449

🛑 Comments failed to post (3)
README.md (1)

110-134: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Scope concern: "Background sessions" documentation appears unrelated to --provider-env-file feature.

Lines 110–134 document openclaude --bg, ps, logs, kill, and attach commands for background session management. Per the PR objectives and review stack context, this PR is scoped to adding the --provider-env-file CLI option and related docs updates. The background sessions feature is not mentioned in the PR summary, and appears to be bundled as an unrelated change.

Per CONTRIBUTING.md, bundling unrelated features without prior discussion may trigger closure without review. If background sessions are intentional, update the PR description to clarify the expanded scope; if not, consider moving this documentation to a separate PR.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 110 - 134, The "Background sessions" documentation
section in the README appears to be unrelated to the PR's stated scope of adding
the --provider-env-file CLI option. Either update the PR description to clarify
that background session documentation is intentionally included in the expanded
scope, or move this entire section (the Background sessions heading and all
associated content showing openclaude --bg, ps, logs, kill, and attach commands)
to a separate pull request focused specifically on background sessions feature
documentation.
src/entrypoints/cli.tsx (1)

143-143: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve --provider precedence after env-file reapply.

reapplyRememberedEnvFileValues() overwrites via Object.assign, and the standalone calls on Lines 231 and 240 run after the managed-env path that reapplies the remembered --provider flag last. With both flags, an env file containing CLAUDE_CODE_USE_OPENAI=1 can be restored after --provider gemini, so validation or background spawn can see the wrong provider. Reapply the remembered provider flag after these restores, or share one env-file-then-provider helper.

Proposed fix
-  let reapplyProviderEnvFileValues = () => {}
+  let reapplyProviderEnvFileValues = () => {}
+  let reapplyProviderFlagValues = () => {}
+  const reapplyExplicitProviderInputs = () => {
+    reapplyProviderEnvFileValues()
+    reapplyProviderFlagValues()
+  }
@@
-    const { applyProviderFlagFromArgs } = await importers.providerFlag();
+    const {
+      applyProviderFlagFromArgs,
+      reapplyRememberedProviderFlag,
+    } = await importers.providerFlag()
+    reapplyProviderFlagValues = reapplyRememberedProviderFlag
@@
-  reapplyProviderEnvFileValues()
+  reapplyExplicitProviderInputs()
@@
-  reapplyProviderEnvFileValues()
+  reapplyExplicitProviderInputs()

Also applies to: 208-208, 231-240

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/entrypoints/cli.tsx` at line 143, The reapplyProviderEnvFileValues
function on line 143 needs to ensure the --provider flag takes precedence over
env-file values. The issue is that reapplyRememberedEnvFileValues() uses
Object.assign to restore env-file settings, which can overwrite the --provider
flag if called after the provider is set. Modify the
reapplyProviderEnvFileValues implementation to reapply the remembered provider
flag value after restoring any env-file values, ensuring that standalone calls
to reapplyRememberedEnvFileValues on lines 231 and 240 do not override the
provider precedence. This ensures that when both --provider and env-file contain
conflicting settings, the --provider flag maintains its intended precedence.
src/main.tsx (1)

2522-2522: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Mirror fromPr hook suppression in the interactive resume path.

Line 2522 handles the headless path, but the interactive hooksPromise guard at Line 2353 still starts processSessionStartHooks('startup') before the options.fromPr resume branch at Line 3263. That can fire startup hooks for a PR-resume flow and duplicate or clobber resume lifecycle output.

Proposed fix
-    const hooksPromise = initOnly || init || maintenance || isNonInteractiveSession || options.continue || options.resume ? null : processSessionStartHooks('startup', {
+    const hooksPromise = initOnly || init || maintenance || isNonInteractiveSession || options.continue || options.resume || options.fromPr ? null : processSessionStartHooks('startup', {
       agentType: mainThreadAgentDefinition?.agentType,
       model: resolvedInitialModel
     });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main.tsx` at line 2522, The interactive resume path's hooksPromise guard
at line 2353 does not suppress the startup hooks when fromPr is set, while the
headless path at line 2522 correctly does so. Add `|| options.fromPr` to the
condition that determines whether to call `processSessionStartHooks('startup')`
in the interactive path to mirror the suppression logic from the headless path.
This ensures startup hooks are consistently suppressed for PR-resume flows in
both code paths, preventing duplicate or conflicting resume lifecycle output.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@kevincodex1 kevincodex1 merged commit 5af6f95 into Gitlawb:main Jun 18, 2026
4 checks passed
@chioarub chioarub deleted the fix/env-example-loading-clarity branch June 18, 2026 05:48
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.

3 participants