Skip to content

OPENCODE_CONFIG_DIR overrides global AGENTS.md path instead of adding to it #28658

Closed as not planned

Description

@rcdailey

Setting OPENCODE_CONFIG_DIR prevents the global AGENTS.md from loading because the global instructions path and the config directory scan use different resolution strategies.

ConfigPaths.directories() in packages/opencode/src/config/paths.ts:26 always includes Global.Path.config (the static XDG path, ~/.config/opencode) in the directory list, so agents, commands, and skills from the XDG config dir are always discovered regardless of OPENCODE_CONFIG_DIR.

But instruction.ts:64 builds the global AGENTS.md path from global.config (the Service property), which resolves to OPENCODE_CONFIG_DIR when set. So the global instructions lookup skips ~/.config/opencode/AGENTS.md entirely.

The result: setting OPENCODE_CONFIG_DIR to add a secondary config directory (e.g. a workspace-level .opencode/) correctly picks up agents/commands/skills from both locations, but silently drops the global AGENTS.md unless you duplicate it into the override directory.

Steps to reproduce

  1. Have a global AGENTS.md at ~/.config/opencode/AGENTS.md
  2. Set OPENCODE_CONFIG_DIR to a different directory (e.g. /path/to/workspace/.opencode)
  3. Start opencode
  4. The global AGENTS.md is not loaded; only $OPENCODE_CONFIG_DIR/AGENTS.md is checked

Expected behavior

instruction.ts should use Global.Path.config (the static XDG path) for the global AGENTS.md, consistent with how ConfigPaths.directories() handles config directory scanning. OPENCODE_CONFIG_DIR should add to the search path, not replace the global instructions source.

Relevant code

  • packages/core/src/global.ts:63 -- config: Flag.OPENCODE_CONFIG_DIR ?? Path.config
  • packages/opencode/src/session/instruction.ts:64 -- path.join(global.config, "AGENTS.md")
  • packages/opencode/src/config/paths.ts:26 -- Global.Path.config (static, not overridden)

Version

opencode 1.15.6, Linux

Activity

  1. eminfedar commented on Jul 20, 2026

    @eminfedar

    Yeah, can't define global AGENTS.md in opencode, doesn't read the file. Global AGENTS.md should always be added in every chat.

  2. minutechreview commented on Sep 5, 2026

    @minutechreview

    Opened #47468 for this — instruction.ts and instruction-context.ts both build the global AGENTS.md path from the flag-overridden Global.Service.config instead of Global.Path.config, same root cause you described.

  3. hotzen commented on Sep 26, 2026

    @hotzen

    this needs to be resolved asap, please!

  4. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

  5. cbrachem commented on Oct 13, 2026

    @cbrachem

    @thdxr The issue is still present in v2. There's already another open issue tagged with 2.0, #32825. The intended meaning of OPENCODE_CONFIG_DIR in v2 is still unclear to me (see my comment in the other issue), but I would like to bring the previous behaviour back if that's in any way possible.

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