Skip to content

fix: opencode plugin projectPath falls back to hash ID instead of filesystem path #987

Description

@Wermeling

Bug

In the opencode capture plugin (plugins/opencode/agentmemory-capture.ts), projectPath is resolved as:

projectPath = ctx.worktree || ctx.project?.id || process.cwd();

When ctx.worktree is null (which happens for Subagent sessions, e.g. @explore, @code-reviewer, @test-runner), the fallback is ctx.project?.id — a hash like 0f93c5906cef66e3257256da13750ddc9fee4e84 — instead of the actual filesystem path.

Impact

Sessions from subagents (and any session where ctx.worktree is not set) get stored in agentmemory under the wrong project identifier. They are invisible to agentmemory_memory_profile and filtered out when querying by project path. In our stock_brawl2 project, 388 out of 983 sessions (39%) were affected.

Fix

Add ctx.project?.worktree as an intermediate fallback:

projectPath = ctx.worktree || ctx.project?.worktree || ctx.project?.id || process.cwd();

ctx.project?.worktree contains the canonical filesystem path (from the OpenCode project table's worktree column) and is set even when the per-session ctx.worktree is null. The hash ID remains as the final fallback.

Plugin file location

plugins/opencode/agentmemory-capture.ts, line 209 (or similar — the file may be at ~/.config/opencode/plugins/agentmemory-capture.ts in local installations).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions