Skip to content

fix(agent-connector): run opencode in the configured working directory (#435)#559

Open
nolanchic wants to merge 1 commit into
openagents-org:developfrom
nolanchic:fix/issue-435-opencode-workingdir
Open

fix(agent-connector): run opencode in the configured working directory (#435)#559
nolanchic wants to merge 1 commit into
openagents-org:developfrom
nolanchic:fix/issue-435-opencode-workingdir

Conversation

@nolanchic

Copy link
Copy Markdown

Fixes #435

agn create <name> --type opencode --path <project> ignored the configured path: the opencode adapter documented opts.workingDir but never used it, hardcoding --dir and cwd to the per-agent scratch dir (~/.openagents/agents/<name>).

opencode confines an agent's file access to its --dir worktree root, so in headless mode any read/edit tool call against a real project file is auto-rejected with "The user rejected permission to use this specific tool call." — on every platform, not only Windows.

Fix

  • Run opencode in the configured workingDir (both --dir and the spawn cwd) via a new _resolveCwd() helper. When no path is configured it falls back to agentHome, so pre-existing agents keep running exactly where they always did.
  • Scope the persisted session store per working directory (sessions-<sha256[:16]>.json). An opencode session ID is only resumable against the --dir it was created under, so without scoping a path change (or an agent that previously ran in agentHome getting a path configured) would poison the next run with a stale ID that 404s. The default (no workingDir) keeps the legacy sessions.json so existing agents retain their context. Files always live under agentHome, never inside the project tree. This mirrors the sha256[:16] per-cwd idiom already used by the goose and nanoclaw adapters.
  • Preflight now access-checks the resolved working dir and surfaces cwd_unavailable (naming the configured path) when it is missing or unreadable, instead of silently running in agentHome.

this.workingDir is already populated by BaseAdapter and passed by daemon.js (workingDir: agentCfg.path || defaultAgentWorkdir(name)), so no daemon changes are needed — the adapter just had to use it.

Test plan

  • node --test test/opencode-workingdir.test.js — 7/7 new tests pass. Covers _resolveCwd (configured vs fallback), --dir/cwd passed to the real subprocess (asserted via a child_process.spawn shim installed before require, same pattern as test/aider.test.js), per-working-dir session-store scoping, and the preflight cwd_unavailable/pass cases.
  • node --test test/opencode.test.js — existing 8.1–8.5 suites pass. (Two preflight credential tests are non-hermetic — they inspect the real home dir and fail when a real ~/.config/opencode/opencode.json exists on the machine; identical failures occur on develop, unrelated to this change.)
  • Manual: agn create demo --type opencode --path /path/to/project; connect to a workspace; @mention it to read or edit a project file and confirm the "user rejected permission" error is gone; send a second message in the same channel and confirm context is retained.

opencode confines an agent's file access to its `--dir` worktree root; in
headless mode a tool call outside it is auto-rejected ("user rejected
permission"). The opencode adapter hardcoded `--dir`/`cwd` to the per-agent
scratch dir (agentHome) and ignored the configured `path` (workingDir), so
opencode ran in an empty dir and could never reach the project it was
created for.

Run opencode in the configured workingDir, falling back to agentHome when
none is set so pre-existing agents keep running where they always did.
Preflight now access-checks the resolved working dir and surfaces
cwd_unavailable (naming the configured path) when it is missing.

Because an opencode session ID is only resumable against the --dir it was
created under, scope the persisted session store per working dir
(sha256[:16], matching the goose and nanoclaw adapters) so a path change
can't poison a run with a stale, unresumable ID. The default (no workingDir)
keeps the legacy sessions.json so existing agents retain their context.

Closes openagents-org#435
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@nolanchic is attempting to deploy a commit to the Raphael's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

opencode adapter ignores configured agent path (workingDir) — runs in empty scratch dir, can't access project files

1 participant