Skip to content

feat(config): add OPENCODE_NO_PARENT_CONFIG env var#10024

Open
kynnyhsap wants to merge 3 commits intoanomalyco:devfrom
kynnyhsap:feat/no-parent-config
Open

feat(config): add OPENCODE_NO_PARENT_CONFIG env var#10024
kynnyhsap wants to merge 3 commits intoanomalyco:devfrom
kynnyhsap:feat/no-parent-config

Conversation

@kynnyhsap
Copy link
Contributor

@kynnyhsap kynnyhsap commented Jan 22, 2026

Add environment variable flag to prevent findUp from walking up parent directories when loading project config. Only loads config from the current working directory.

Fixes #10025

This is a logical continuation of #10013 (OPENCODE_DISABLE_GLOBAL_CONFIG), providing more granular control over config loading.

Use Case

Running opencode in a subdirectory that has its own opencode.json, without inheriting/merging config from parent directories.

Example structure:

~/project/opencode.json          # parent config with MCP servers A, B, C
~/project/agent/opencode.json    # child config with MCP server D

Without flag (current behavior): Running from ~/project/agent/ loads both configs, sees A, B, C, D.

With flag: Running from ~/project/agent/ only loads the local config, sees only D.

What Gets Disabled

When OPENCODE_NO_PARENT_CONFIG=true:

  • opencode.json / opencode.jsonc from parent directories
  • .opencode/ directories from parent directories
  • AGENTS.md / CLAUDE.md / CONTEXT.md from parent directories

Note: Global config (~/.config/opencode/) is still loaded. Use OPENCODE_DISABLE_GLOBAL_CONFIG=true (from #10013) to disable that as well.

Usage

# Only load config from current directory
OPENCODE_NO_PARENT_CONFIG=true opencode

# Full isolation - current directory only, no global
OPENCODE_NO_PARENT_CONFIG=true OPENCODE_DISABLE_GLOBAL_CONFIG=true opencode

Test Plan

  • Added 5 tests for OPENCODE_NO_PARENT_CONFIG
  • Verified existing OPENCODE_DISABLE_PROJECT_CONFIG tests still pass
  • Manual testing with built binary

Related

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Add environment variable flag to prevent findUp from walking up parent
directories when loading project config. Only loads config from the
current working directory.

When set, this prevents loading:
- opencode.json from parent directories
- .opencode/ directories from parent directories
- AGENTS.md/CLAUDE.md from parent directories

Useful for running opencode in a subdirectory that has its own config,
without inheriting config from parent directories.
Convert GLOBAL_RULE_FILES from module-level constant to a function
that evaluates at runtime. This ensures Flag.OPENCODE_CONFIG_DIR
is read when the function is called, not when the module loads.
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.

[FEATURE]: add OPENCODE_NO_PARENT_CONFIG to disable parent directory config inheritance

1 participant