Feat: Add --config CLI flag to specify custom config file path #1377

Closed
opened 2026-02-16 17:30:41 -05:00 by yindo · 2 comments
Owner

Originally created by @ndrwstn on GitHub (Aug 19, 2025).

Originally assigned to: @thdxr on GitHub.

Summary

Currently, opencode supports specifying a custom config file path via the OPENCODE_CONFIG environment variable. It would be more convenient and intuitive to also support this functionality through a CLI flag like --config.

Current Behavior

To use a custom config file, users must set an environment variable:

export OPENCODE_CONFIG=/path/to/my/custom-config.json
opencode run "Hello world"

Proposed Enhancement

Add a --config CLI flag that accepts a file path:

opencode --config /path/to/my/custom-config.json run "Hello world"
opencode --config ./project-specific-config.jsonc run "Implement feature X"

Benefits

  1. Better UX: More discoverable through --help and follows common CLI conventions
  2. Per-command flexibility: Easier to use different configs for different commands without managing environment variables
  3. Script-friendly: Cleaner in shell scripts and CI/CD pipelines
  4. Consistency: Aligns with how most CLI tools handle config file specification

Implementation Notes

• The CLI flag should take precedence over the OPENCODE_CONFIG environment variable (or have the same precedence)
• Should maintain backward compatibility with the existing environment variable approach
• The flag should accept both absolute and relative paths
• Should support both .json and .jsonc formats like the current implementation

Current Config Loading Hierarchy

For reference, the current precedence order is:

  1. OPENCODE_CONFIG environment variable (highest)
  2. Project-level configs (.opencode/opencode.jsonc, etc.)
  3. Global configs (~/.config/opencode/opencode.jsonc, etc.)

The new --config flag should either match the precedence of OPENCODE_CONFIG or take even higher precedence.

Related Files

• packages/tui/cmd/opencode/main.go - CLI flag definitions
• packages/opencode/src/config/config.ts - Config loading logic
• packages/opencode/src/flag/flag.ts - Flag processing

Notes

Letting AI write my issues seems like cheating, but also appropriate in this repo. If not, sorry.

Originally created by @ndrwstn on GitHub (Aug 19, 2025). Originally assigned to: @thdxr on GitHub. ## Summary Currently, opencode supports specifying a custom config file path via the OPENCODE_CONFIG environment variable. It would be more convenient and intuitive to also support this functionality through a CLI flag like --config. ## Current Behavior To use a custom config file, users must set an environment variable: export OPENCODE_CONFIG=/path/to/my/custom-config.json opencode run "Hello world" ## Proposed Enhancement Add a --config CLI flag that accepts a file path: opencode --config /path/to/my/custom-config.json run "Hello world" opencode --config ./project-specific-config.jsonc run "Implement feature X" ## Benefits 1. Better UX: More discoverable through --help and follows common CLI conventions 2. Per-command flexibility: Easier to use different configs for different commands without managing environment variables 3. Script-friendly: Cleaner in shell scripts and CI/CD pipelines 4. Consistency: Aligns with how most CLI tools handle config file specification ## Implementation Notes • The CLI flag should take precedence over the OPENCODE_CONFIG environment variable (or have the same precedence) • Should maintain backward compatibility with the existing environment variable approach • The flag should accept both absolute and relative paths • Should support both .json and .jsonc formats like the current implementation ## Current Config Loading Hierarchy For reference, the current precedence order is: 1. OPENCODE_CONFIG environment variable (highest) 2. Project-level configs (.opencode/opencode.jsonc, etc.) 3. Global configs (~/.config/opencode/opencode.jsonc, etc.) The new --config flag should either match the precedence of OPENCODE_CONFIG or take even higher precedence. ## Related Files • packages/tui/cmd/opencode/main.go - CLI flag definitions • packages/opencode/src/config/config.ts - Config loading logic • packages/opencode/src/flag/flag.ts - Flag processing ## Notes Letting AI write my issues seems like cheating, but also appropriate in this repo. If not, sorry.
yindo closed this issue 2026-02-16 17:30:41 -05:00
Author
Owner

@rekram1-node commented on GitHub (Dec 27, 2025):

[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!

@rekram1-node commented on GitHub (Dec 27, 2025): [automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!
Author
Owner

@misterdojo777 commented on GitHub (Jan 11, 2026):

yes this would be useful for cleaner context worfklows

@misterdojo777 commented on GitHub (Jan 11, 2026): yes this would be useful for cleaner context worfklows
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1377