Skip to content

config: agent-body edits through directory symlinks do not load in new sessions #58904

Open

Description

@iceteaSA

What occurs

OpenCode 2.1.4 reads agent files through a directory symlink at startup, but it misses subsequent edits to the external target.
A new session then sends the previous agent body to the model.
The same test works when the agent directory is a non-symlink directory in the configuration directory.

The test used Linux, isolated HOME and XDG directories, and a local OpenAI-compatible HTTP server.
The HTTP server recorded each request and sent the same streamed response.
The configuration had no third-party extensions.

Steps with the clean reproduction

  1. Make isolated configuration, data, state, cache, home, and external directories.
  2. Set HOME, XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_STATE_HOME, and XDG_CACHE_HOME to these isolated directories.
  3. Make an agents directory in the external directory.
  4. Make this agent file at external/agents/probe.md:
---
mode: primary
description: Reload probe
---
AGENT_BASELINE_814.
  1. Make config/opencode/agents a symlink to external/agents.
  2. Configure a local OpenAI-compatible provider in config/opencode/opencode.json.
  3. Use aisdk:@ai-sdk/openai-compatible as its package and the local HTTP server URL as settings.baseURL.
  4. Start one opencode serve --service process.
  5. Run opencode run --agent probe with a short message in a new session.
  6. Make sure the primary provider request contains AGENT_BASELINE_814.
  7. Append LINKED_AGENT_EDIT_814 to the external agent file without a rename.
  8. Wait 15 seconds.
  9. Run opencode run --agent probe with a different message in a new session.
  10. Examine the primary provider request, not the different request for the session title.

Correct result

The new primary request contains the updated agent body with LINKED_AGENT_EDIT_814.

Actual

The primary request keeps AGENT_BASELINE_814 but does not contain LINKED_AGENT_EDIT_814.
The model itself does not control this result. The recorded request body shows it.

Controls in the same clean environment:

Source Result after an in-place edit
Agent file in a non-symlink configuration subdirectory The new session receives the edit.
Agent file through an external directory symlink The new session keeps the previous body.
Explicit instruction file through an external directory symlink The new session receives the edit.
Skill description through an external directory symlink The new session receives the edit.

The instruction and skill controls used dedicated watcher subscriptions on their resolved targets.
The log showed no watcher subscription on the external agent target.

Source locations on dev

Source snapshot: 17b79f4e0c16dcff200b0417567ed22aeb2d7166.
The runtime test used 2.1.4. This dev snapshot contains the same agent and watch-plan code.
These files have no changes from that snapshot to dev at 32b57015e5b491a789fba1534ecb472e676c9d8e.

Related reports: #51936, #53920, and #54933 (different symlink positions).
PR #54093 monitors symlinked watcher roots, not a symlinked child directory in a non-symlink configuration root.

Activity

  1. opencode-agent commented on Oct 25, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I reproduced this on 2.1.4, and it still happens on the latest dev (32b57015e).

    I used an isolated HOME and XDG directories and a mock OpenAI-compatible server that records each request:

    • Symlinked agents/: $XDG_CONFIG_HOME/opencode/agents pointed to an external directory containing probe.md. The first opencode run --agent probe sent AGENT_BASELINE_814. I then appended LINKED_AGENT_EDIT_814 to the target file in place, waited 15s and ran a new session. Its request still had only the old body.
    • Control: with agents/ as a normal directory, the same edit showed up in the next session.

    The script below reproduces both cases (MODE=symlink or MODE=plain). It starts opencode serve --port and passes --server to opencode run, instead of using serve --service.

    The code agrees with your analysis. Agent discovery follows the symlink when it first loads the files, but nothing watches the symlink's target. Skills and instructions do watch their resolved targets. Related: #53920 / #53932 (symlinked config files), #54933 and #55119 (symlinked config root), #54093 (symlinked watcher roots).

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #58904: agent edits through a symlinked agents/ directory are not reloaded.
    # Usage: bash repro.sh            (uses `opencode` from PATH)
    #        OC_DEV=/path/to/checkout bash repro.sh   (runs from source)
    set -u
    HERE=$(cd "$(dirname "$0")" && pwd)
    if [ -n "${OC_DEV:-}" ]; then
      OC=(bun --conditions=browser --preload=$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js $OC_DEV/packages/cli/src/index.ts)
    else OC=(opencode); fi
    MODE=${MODE:-symlink}   # symlink | plain
    R=$(mktemp -d /tmp/opencode/r58904.XXXX)
    mkdir -p $R/{home,config/opencode,data,state,cache,external/agents,project,reqs}
    export HOME=$R/home XDG_CONFIG_HOME=$R/config XDG_DATA_HOME=$R/data XDG_STATE_HOME=$R/state XDG_CACHE_HOME=$R/cache
    export OPENCODE_PASSWORD=repro58904
    MOCK_PORT=$((20000 + RANDOM % 20000)); SRV_PORT=$((MOCK_PORT+1))
    if [ "$MODE" = symlink ]; then AG=$R/external/agents; ln -s $AG $R/config/opencode/agents
    else AG=$R/config/opencode/agents; mkdir -p $AG; fi
    printf -- '---\nmode: primary\ndescription: Reload probe\n---\nAGENT_BASELINE_814.\n' > $AG/probe.md
    cat > $R/config/opencode/opencode.json <<J
    { "model": "mock/m", "providers": { "mock": { "package": "aisdk:@ai-sdk/openai-compatible",
      "settings": { "baseURL": "http://127.0.0.1:$MOCK_PORT/v1", "apiKey": "x" }, "models": { "m": {} } } } }
    J
    cat > $R/mock.ts <<'M'
    // Minimal OpenAI-compatible streaming mock that records request bodies
    const out = process.env.REQLOG!
    Bun.serve({ port: Number(process.env.MOCK_PORT), async fetch(req) {
      const body = await req.text()
      await Bun.write(out + "/" + Date.now() + "-" + Math.random().toString(36).slice(2) + ".json", body)
      const chunk = (d: any) => `data: ${JSON.stringify(d)}\n\n`
      const base = { id: "x", object: "chat.completion.chunk", created: 0, model: "m" }
      const s = chunk({ ...base, choices: [{ index: 0, delta: { role: "assistant", content: "ok" } }] }) +
        chunk({ ...base, choices: [{ index: 0, delta: {}, finish_reason: "stop" }], usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 } }) + "data: [DONE]\n\n"
      return new Response(s, { headers: { "content-type": "text/event-stream" } })
    }})
    M
    REQLOG=$R/reqs MOCK_PORT=$MOCK_PORT bun $R/mock.ts & MOCK=$!
    cd $R/project
    "${OC[@]}" serve --port $SRV_PORT > $R/serve.log 2>&1 & SRV=$!
    sleep 6
    run() { "${OC[@]}" run --server http://127.0.0.1:$SRV_PORT --agent probe "$1" > $R/run.log 2>&1 || cat $R/run.log; }
    run "first message"
    echo "first run: requests with BASELINE: $(grep -l AGENT_BASELINE_814 $R/reqs/* | wc -l)"
    echo "LINKED_AGENT_EDIT_814." >> $AG/probe.md   # in-place append, no rename
    sleep 15
    rm -f $R/reqs/*
    run "second message"
    echo "second run: requests with BASELINE: $(grep -l AGENT_BASELINE_814 $R/reqs/* | wc -l), with EDIT: $(grep -l LINKED_AGENT_EDIT_814 $R/reqs/* | wc -l)"
    grep -l "second message" $R/reqs/* | xargs grep -o 'AGENT_BASELINE_814[^#]*' | head -1
    kill $SRV $MOCK 2>/dev/null

    Run it: bash repro.sh

  2. ngbrown commented on Nov 12, 2026

    @ngbrown

    Potentially related reproduction on Windows, OpenCode v2.2.6, affecting commands rather than agents.

    My project’s .opencode/commands is a directory symlink to ..\.agents\commands.

    While OpenCode already had an active session in a repository, I created .agents/commands/make-it-so.md. The new command did not appear in slash-command autocomplete.

    Running /reload made /make-it-so appear without changing the file. This suggests manual discovery follows the symlink, but automatic watching misses newly added files in its target.

    Is this covered by this issue, or would you prefer a separate report for commands on Windows?

  3. georgernstgraf commented on Nov 28, 2026

    @georgernstgraf

    Confirmed still present on v2.4.2 (Linux, inotify backend) — and this hits a very practical real-world pattern: the dotfiles-style setup where ~/.config/opencode/{skills,agents,commands} are symlinks into a shared git repo that several hosts pull. Discovery follows the links fine at startup; hot-reload does not.

    Reproduction results (service running, changes made inside the symlinked targets; identical actions with non-symlinked config subdirectories all pass):

    While service runs… real dirs symlinked dirs
    edit existing skill file picked up picked up
    new skill directory picked up picked up
    new flat agent file (agents/probe.md) picked up not picked up
    new agent subdirectory picked up not picked up
    new flat command file (commands/probe.md) picked up not picked up

    Two additions to the report:

    1. New files, not only edits. Newly added agent/command .md files inside symlinked global config subdirs never appear while the service runs (matches ngbrown's Windows commands observation above, now confirmed on Linux and for the global config dirs, not only project .opencode).

    2. The asymmetry is the bug. In the very same symlinked setup, skills hot-reload correctly — including brand-new skill directories — because the skill plugin watches the resolved target recursively plus the link itself as a file (config/plugin/skill.ts:62-66):

      watcher started path=…/xdg/opencode/skills type=file backend=node
      watcher started path=…/target/skills        type=directory backend=inotify ignores=8
      

      No equivalent subscription is ever created for the agents/commands targets — their reload path is config.changes() filtered by isDirectorySource (config/plugin/agent.ts, config/plugin/command.ts), which misses events arriving under the resolved path. Applying the skill plugin's dual-watch pattern (resolved directory watch + link-as-file watch) to agent/command sources would cover this class.

    Isolated repro (temp XDG dirs, symlink vs real control, tested on v2.4.2):

    #!/usr/bin/env bash
    # Usage: repro58904.sh symlink|real   (OPENCODE_CMD overrides the opencode binary)
    set -u
    MODE=${1:-symlink}
    OC=${OPENCODE_CMD:-opencode}
    PORT=$((25000 + RANDOM % 20000))
    R=$(mktemp -d /tmp/opencode/repro58904-XXXX)
    mkdir -p $R/target/skills $R/target/agents $R/target/commands \
             $R/xdg/opencode $R/data $R/state $R/cache $R/proj
    
    SKILL_ROOT=$R/target/skills
    AGENT_ROOT=$R/target/agents
    CMD_ROOT=$R/target/commands
    
    mkdir -p $SKILL_ROOT/base-skill $AGENT_ROOT/base-agent
    cat > $SKILL_ROOT/base-skill/SKILL.md <<MD
    ---
    name: base-skill
    description: baseline skill present at startup
    ---
    Body v1.
    MD
    cat > $AGENT_ROOT/base-agent/agent.md <<MD
    ---
    description: baseline agent present at startup
    mode: primary
    ---
    Body v1.
    MD
    
    if [ "$MODE" = symlink ]; then
      ln -s $SKILL_ROOT $R/xdg/opencode/skills
      ln -s $AGENT_ROOT $R/xdg/opencode/agents
      ln -s $CMD_ROOT   $R/xdg/opencode/commands
    else
      cp -r $SKILL_ROOT $R/xdg/opencode/skills
      cp -r $AGENT_ROOT $R/xdg/opencode/agents
      cp -r $CMD_ROOT   $R/xdg/opencode/commands
      SKILL_ROOT=$R/xdg/opencode/skills
      AGENT_ROOT=$R/xdg/opencode/agents
      CMD_ROOT=$R/xdg/opencode/commands
    fi
    echo '{"$schema":"https://opencode.ai/config.json"}' > $R/xdg/opencode/opencode.json
    
    cd $R/proj
    XDG_CONFIG_HOME=$R/xdg XDG_DATA_HOME=$R/data XDG_STATE_HOME=$R/state XDG_CACHE_HOME=$R/cache \
      OPENCODE_SERVER_PASSWORD=repro $OC serve --hostname 127.0.0.1 --port $PORT --print-logs > $R/log 2>&1 &
    PID=$!
    api() { curl -s -u opencode:repro "http://127.0.0.1:$PORT$1"; }
    for i in $(seq 1 40); do api /api/skill >/dev/null 2>&1 && break; sleep 1; done
    sleep 2
    
    echo "=== mode=$MODE  1) edit EXISTING skill file"
    sed -i 's/Body v1./Body v2/' $SKILL_ROOT/base-skill/SKILL.md; sleep 8
    api /api/skill | grep -o 'Body v2' | head -1 || echo "   skill edit NOT picked up"
    
    echo "=== mode=$MODE  2) NEW skill directory"
    mkdir -p $SKILL_ROOT/probe-skill
    cat > $SKILL_ROOT/probe-skill/SKILL.md <<MD
    ---
    name: probe-skill
    description: added while service runs
    ---
    Probe.
    MD
    sleep 8
    api /api/skill | grep -o '"name":"probe-skill"' || echo "   new skill dir NOT picked up"
    
    echo "=== mode=$MODE  3) NEW flat agent file"
    cat > $AGENT_ROOT/probe-flat.md <<MD
    ---
    description: flat probe agent
    mode: primary
    ---
    Flat.
    MD
    sleep 8
    api "/api/agent?directory=$R/proj" | grep -o '"description":"flat probe agent"' || echo "   new flat agent NOT picked up"
    
    echo "=== mode=$MODE  4) NEW agent subdirectory"
    mkdir -p $AGENT_ROOT/probe-agent
    cat > $AGENT_ROOT/probe-agent/agent.md <<MD
    ---
    description: nested probe agent
    mode: primary
    ---
    Nested.
    MD
    sleep 8
    api "/api/agent?directory=$R/proj" | grep -o '"description":"nested probe agent"' || echo "   new agent subdir NOT picked up"
    
    echo "=== mode=$MODE  5) NEW flat command file"
    cat > $CMD_ROOT/probe-cmd.md <<MD
    ---
    description: probe command
    ---
    echo hi
    MD
    sleep 8
    api "/api/command?directory=$R/proj" > $R/cmds.json
    grep -o 'probe-cmd' $R/cmds.json | head -1
    grep -q 'probe-cmd' $R/cmds.json || echo "   new flat command NOT picked up"
    
    echo "=== mode=$MODE  watcher subscriptions for the skills/agents/commands targets"
    grep -E 'watcher started' $R/log | grep -E 'skills|agents|commands' | sed 's/^timestamp=[^ ]* //'
    kill $PID 2>/dev/null; wait $PID 2>/dev/null

    Side note: in repeated runs, in-place edits to an existing agent file through the link loaded only intermittently, depending on how the file is modified (append vs atomic replace) — consistent with events silently being dropped rather than a hard failure. Related but distinct positions are already tracked separately (#54933 = config root itself symlinked, watch subscription fails outright; PR #54093 resolves watch roots but explicitly does not cover symlinked child directories).

    Duplicate check (2026-11-28): reused this issue instead of filing a new one. Checked: #54933, #52701, #52240, #53763, #53920, #53811 and searches for "symlink", "watch reload config", "skills reload" — all cover different symlink positions or platforms.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions