Skip to content

docs: agents and skills pages say discovery stops at the project root #64289

Done

Description

@em1nx

Description

The agents and skills docs say project discovery stops at the project root:

  • agents.mdx: "OpenCode discovers project .opencode directories from the current directory up to the project root."
  • skills.mdx: "For project sources, OpenCode searches from the current directory up to the project root …"

It doesn't. ConfigDiscovery.discover (packages/core/src/config/discovery.ts) walks fs.up from the current directory with no stop, so .opencode, .claude and .agents directories above the repo root are loaded too. config.mdx already says "to the filesystem root", so the pages contradict each other. Instruction discovery does stop at the project root, so instructions.mdx is fine.

I'd assume the docs are what's wrong here, not the code — happy to send a PR fixing the two sentences.

Plugins

none

OpenCode version

2.3.0

Steps to reproduce

  1. Put an agent at ~/code/.opencode/agents/demo.md (mode: subagent).
  2. Have a separate git repo at ~/code/some-repo.
  3. opencode api get "/api/agent?location[directory]=$HOME/code/some-repo" — demo is listed, although it's above that project's root.

Screenshot

No response

Operating System

macOS (Darwin 25.2.0, arm64)

Terminal

tmux

Activity

  1. added
    area/core
    type/bug
    version/v2
    on Nov 16, 2026
  2. opencodejr commented on Nov 16, 2026

    @opencodejr
    Contributor

    Thanks for the clear report. I reproduced this on 2.3.0 with the released CLI.

    I used an isolated HOME with:

    • $HOME/code/.opencode/agents/demo.md (mode: subagent)
    • $HOME/code/.opencode/skills/demo-skill/SKILL.md
    • a separate git repo at $HOME/code/some-repo

    opencode api get "/api/agent?location[directory]=$HOME/code/some-repo" lists demo, and /api/skill lists demo-skill, although both are above that repo's root. The first request can come back before the location has loaded, so the script below polls and waits a few seconds before reading the lists.

    It still happens on the latest dev (7745079). There, agents.mdx and skills.mdx still say discovery runs "up to the project root", while config.mdx says "to the filesystem root". ConfigDiscovery still walks up with no stop, so the agents and skills pages don't match the code or the config page.

    The script below reproduces it. Maintainers will decide whether the docs or the behaviour should change.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #64289: project agents/skills are discovered above the git project root.
    # Usage: ./repro.sh                       (uses `opencode` from PATH)
    #        OC="bun --conditions=browser --preload=<repo>/packages/tui/node_modules/@opentui/solid/scripts/preload.js <repo>/packages/cli/src/index.ts" ./repro.sh
    set -u
    OC=${OC:-opencode}
    export HOME=$(mktemp -d /tmp/opencode/home.XXXX)
    export XDG_CONFIG_HOME=$HOME/.config XDG_DATA_HOME=$HOME/.local/share XDG_STATE_HOME=$HOME/.local/state XDG_CACHE_HOME=$HOME/.cache
    mkdir -p "$HOME/code/.opencode/agents" "$HOME/code/.opencode/skills/demo-skill" "$HOME/code/some-repo"
    printf -- '---\ndescription: Demo agent above the repo root\nmode: subagent\n---\nYou are demo.\n' > "$HOME/code/.opencode/agents/demo.md"
    printf -- '---\nname: demo-skill\ndescription: Demo skill above the repo root\n---\nBody\n' > "$HOME/code/.opencode/skills/demo-skill/SKILL.md"
    git -C "$HOME/code/some-repo" init -q
    git -C "$HOME/code/some-repo" -c user.email=a@b -c user.name=a commit -q --allow-empty -m init
    cd "$HOME/code/some-repo"
    $OC --version
    DIR="$HOME/code/some-repo"
    # The first request can return before the location has loaded; poll until built-ins appear.
    for i in $(seq 1 30); do $OC api get "/api/agent?location[directory]=$DIR" 2>/dev/null | grep -q '"id":"build"' && break; sleep 1; done
    sleep 5
    echo "== git project root: $(git rev-parse --show-toplevel)"
    echo "== agents:"
    $OC api get "/api/agent?location[directory]=$DIR" 2>&1 | grep -o '"id":"[^"]*"' | tr '\n' ' '; echo
    echo "== skills:"
    $OC api get "/api/skill?location[directory]=$DIR" 2>&1 | grep -o '"name":"[^"]*"' | tr '\n' ' '; echo
    pkill -f "serve --service" >/dev/null 2>&1 || true

    Run it: bash repro.sh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreplatform/macosreproducedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions