forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Problem
Subagents sometimes request ~/git/Claude instead of the actual working directory.
Root Cause (Investigated)
Tool descriptions are initialized once at tool creation time, containing a static Instance.directory value. When tools are shared with subagents, they carry the parent session's directory in their description, not the subagent's actual working directory.
Evidence
packages/opencode/src/tool/bash.ts:
- Line 2-8:
description = DESCRIPTION.replaceAll("${directory}", Instance.directory)— evaluated at tool initialization - Line 14: workdir parameter description contains static captured directory
packages/opencode/src/tool/task.ts:
- Line 177:
Session.createNext({ directory: parentSession.directory })— subagent correctly inherits directory - But tools passed to subagent still have old descriptions
Why It Happens
- Parent session starts in
/Users/janni/git/opencode - Tools initialize with descriptions containing this directory
- Task tool spawns subagent with correct directory in session metadata
- Subagent's prompt includes tools (with OLD descriptions) + system prompt (with correct directory)
- Subagent sees conflicting directory info → confusion
Fix Options
- Lazily evaluate tool descriptions — Replace static
Instance.directorycapture with function that reads current context - Rewrite tool descriptions — When passing tools to subagents, replace directory in descriptions
- Move directory info to system prompt only — Remove from tool descriptions entirely
Recommended Fix
Make tool descriptions dynamic by lazily evaluating Instance.directory when description is requested.
Files
packages/opencode/src/tool/bash.ts— Static directory in descriptionpackages/opencode/src/tool/*.ts— Other tools may have same issuepackages/opencode/src/tool/tool.ts— Tool definition interface
Metadata
Metadata
Assignees
Labels
No labels