[PR #12999] feat(config): add configBoundary option for parent config traversal #14473

Open
opened 2026-02-16 18:19:15 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12999

State: open
Merged: No


Summary

Adds a configBoundary config field to control how far up the filesystem OpenCode searches for parent configs and instruction files (AGENTS.md, etc.).

Motivation

Currently, findUp for config files stops at the git root (Instance.worktree). This prevents hierarchical config inheritance for multi-project structures like:

~/Projects/
├── ClientA/                    # Want opencode.jsonc here for all ClientA projects
│   ├── opencode.jsonc          # <-- Currently ignored when inside git repos!
│   ├── project-alpha/.git/
│   └── project-beta/.git/
└── ClientB/
    ├── opencode.jsonc          # Different MCP servers, different settings
    └── project-gamma/.git/

Solution

Add configBoundary config field with env var override OPENCODE_CONFIG_BOUNDARY:

{
  "configBoundary": "current" | "home" | "root" | "none"
}
Value Behavior Use Case
"current" Default. Stop at git worktree root, or / if no git Backward compatible
"home" Walk up to $HOME Multi-client hierarchies
"root" Walk up to / Explicit full traversal
"none" Stop immediately after current directory Isolation

Precedence

  • Env var OPENCODE_CONFIG_BOUNDARY overrides jsonc config
  • Global config sets the policy (read before project config discovery)

Examples

# Default (backward compatible) - no configBoundary set
/d/cA/repo/subdir $ opencode  # loads: global + repo configs only

# Full hierarchy
# ~/.config/opencode/opencode.jsonc: { "configBoundary": "home" }
/d/cA/repo/subdir $ opencode  # loads: global + clientA + repo + subdir configs

# Isolation - override via env var
OPENCODE_CONFIG_BOUNDARY=none opencode  # loads: global + current dir only

Related Issues

  • Closes #10707 - Parent folder config scope (exact use case)
  • Addresses #10025 - "none" boundary provides the isolation requested
  • Related to #4479 - Configurable instruction file search boundary (similar proposal)
  • Related to #6479 - Parent directory AGENTS.md discovery

Changes

  • packages/opencode/src/flag/flag.ts: Add OPENCODE_CONFIG_BOUNDARY env var
  • packages/opencode/src/config/config.ts: Add configBoundary schema field and getConfigStop() helper
  • packages/opencode/src/session/instruction.ts: Use getConfigStop() for instruction discovery

Testing

  • All existing tests pass (903 pass, 1 skip)
  • Typecheck passes
  • Default behavior ("current") preserves existing functionality
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12999 **State:** open **Merged:** No --- ## Summary Adds a `configBoundary` config field to control how far up the filesystem OpenCode searches for parent configs and instruction files (AGENTS.md, etc.). ## Motivation Currently, `findUp` for config files stops at the git root (`Instance.worktree`). This prevents hierarchical config inheritance for multi-project structures like: ``` ~/Projects/ ├── ClientA/ # Want opencode.jsonc here for all ClientA projects │ ├── opencode.jsonc # <-- Currently ignored when inside git repos! │ ├── project-alpha/.git/ │ └── project-beta/.git/ └── ClientB/ ├── opencode.jsonc # Different MCP servers, different settings └── project-gamma/.git/ ``` ## Solution Add `configBoundary` config field with env var override `OPENCODE_CONFIG_BOUNDARY`: ```jsonc { "configBoundary": "current" | "home" | "root" | "none" } ``` | Value | Behavior | Use Case | |-------|----------|----------| | `"current"` | **Default**. Stop at git worktree root, or `/` if no git | Backward compatible | | `"home"` | Walk up to `$HOME` | Multi-client hierarchies | | `"root"` | Walk up to `/` | Explicit full traversal | | `"none"` | Stop immediately after current directory | Isolation | ### Precedence - Env var `OPENCODE_CONFIG_BOUNDARY` overrides jsonc config - Global config sets the policy (read before project config discovery) ## Examples ```bash # Default (backward compatible) - no configBoundary set /d/cA/repo/subdir $ opencode # loads: global + repo configs only # Full hierarchy # ~/.config/opencode/opencode.jsonc: { "configBoundary": "home" } /d/cA/repo/subdir $ opencode # loads: global + clientA + repo + subdir configs # Isolation - override via env var OPENCODE_CONFIG_BOUNDARY=none opencode # loads: global + current dir only ``` ## Related Issues - Closes #10707 - Parent folder config scope (exact use case) - Addresses #10025 - `"none"` boundary provides the isolation requested - Related to #4479 - Configurable instruction file search boundary (similar proposal) - Related to #6479 - Parent directory AGENTS.md discovery ## Changes - `packages/opencode/src/flag/flag.ts`: Add `OPENCODE_CONFIG_BOUNDARY` env var - `packages/opencode/src/config/config.ts`: Add `configBoundary` schema field and `getConfigStop()` helper - `packages/opencode/src/session/instruction.ts`: Use `getConfigStop()` for instruction discovery ## Testing - All existing tests pass (903 pass, 1 skip) - Typecheck passes - Default behavior (`"current"`) preserves existing functionality
yindo added the pull-request label 2026-02-16 18:19:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14473