Skip to content

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

Closed

Description

@ndrwstn

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.

Activity

  1. rekram1-node commented on Dec 28, 2025

    @rekram1-node
    Collaborator

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

  2. misterdojo777 commented on Jan 11, 2026

    @misterdojo777

    yes this would be useful for cleaner context worfklows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions