fix(session): inject directory into session API calls for worktree support#1382
Open
gburch wants to merge 1 commit intocode-yeongyu:devfrom
Open
fix(session): inject directory into session API calls for worktree support#1382gburch wants to merge 1 commit intocode-yeongyu:devfrom
gburch wants to merge 1 commit intocode-yeongyu:devfrom
Conversation
…pport When using OpenCode with git worktrees, session API calls fail with NotFoundError because the server can't resolve the correct project directory. The server falls back to process.cwd() which resolves to 'global' instead of the actual worktree's project ID. This fix wraps ctx.client.session with a Proxy that automatically injects query.directory into every session method call, ensuring session operations are correctly scoped to the worktree's project. Fixes session.get, session.messages, session.prompt, and other session APIs when running from git worktrees or alternate workspaces.
Contributor
|
All contributors have signed the CLA. Thank you! ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
nludd25
pushed a commit
to nludd25/oh-my-opencode
that referenced
this pull request
Feb 2, 2026
A1pha3
pushed a commit
to A1pha3/oh-my-opencode
that referenced
this pull request
Feb 2, 2026
leoisadev1
pushed a commit
to leoisadev1/oh-my-opencode
that referenced
this pull request
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using OpenCode with git worktrees (or any workspace where
process.cwd()differs from the project directory), session API calls fail withNotFoundError:The session file exists under the correct project directory, but the server looks in
global/because it doesn't receive the directory context.Root Cause
OpenCode's session APIs accept an optional
query: { directory }parameter to resolve which project's session storage to use. Without it, the server falls back toprocess.cwd(), which resolves to project IDglobalinstead of the actual worktree's project ID.The plugin has access to the correct directory via
ctx.directory, but this wasn't being passed to session API calls.Solution
Wrap
ctx.client.sessionwith a Proxy at plugin initialization that automatically injectsquery: { directory: ctx.directory }into every session method call. This ensures all session operations (.get(),.messages(),.prompt(), etc.) are correctly scoped to the workspace's project.Changes
withDirectoryArgs()helper to merge directory into query parameterswrapSession()to create a Proxy that intercepts session method callsinjectDirectoryClient()to apply the wrapper at startupinjectDirectoryClient(ctx.client, ctx.directory)during plugin initializationTesting
Verified that
delegate_taskand other session-dependent tools now work correctly when running OpenCode from a git worktree.Summary by cubic
Fixes session API failures in git worktrees by injecting the workspace directory into all session calls. Ensures session reads/writes target the correct project and removes NotFoundError.
Written for commit 05d00c8. Summary will update on new commits.