feat: add per-session directory and /new <path> switching#12015
Closed
MrTravisB wants to merge 9 commits intoanomalyco:devfrom
Closed
feat: add per-session directory and /new <path> switching#12015MrTravisB wants to merge 9 commits intoanomalyco:devfrom
MrTravisB wants to merge 9 commits intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
MrTravisB
added a commit
to MrTravisB/opencode
that referenced
this pull request
Feb 3, 2026
7b6f48d to
ce4ce7e
Compare
…rking directory Thread session.directory through the Tool.Context so every tool invocation receives the session's stored directory instead of relying on Instance.directory. This is concurrency-safe and follows the existing context-passing pattern.
…ools Update bash, edit, write, read, grep, glob, ls, lsp, and apply_patch to resolve paths from the session's directory via Tool.Context rather than the global Instance.directory. This enables per-session directory scoping without shared mutable state.
…d shell spawn Update SystemPrompt.environment() to accept a directory parameter, replace Instance.directory in assistant message path.cwd metadata, compaction context, and shell process spawn with session.directory.
…ory-aware Add switchDirectory RPC method to the worker that restarts the event stream for a new directory. Make SDKProvider's directory reactive via SolidJS signals so the SDK client can be re-created at runtime when switching directories. Expose setDirectory() from the SDK context.
… switching Add reset() to SyncProvider that clears stale session-keyed data (messages, parts, permissions, todos, diffs, status) before re-bootstrapping with data from a new directory.
Intercept /new <path> and /clear <path> in the prompt's submit handler to switch the TUI's working directory. Resolves paths (tilde expansion, relative), validates the target is a directory, then orchestrates: worker event stream restart, SDK client re-creation, sync reset and re-bootstrap, and navigation to home screen. Adds switchDirectory to SDK context and onSwitchDirectory callback from thread to worker RPC.
Add missing directory field to Tool.Context in all test mocks and debug code (40 type errors fixed). Add error recovery with rollback and locking to prevent concurrent directory switches in the prompt submit handler.
Update bash.test.ts and apply_patch.test.ts to set ctx.directory to match the test's Instance.directory instead of process.cwd(). This fixes 20 CI failures where the external_directory permission check or file path resolution failed due to directory context mismatch.
e9825d5 to
f8e5f83
Compare
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.
Fixes #2177
Adds the ability to switch working directories from the TUI without restarting. Type
/new ~/other-project(or/clear ~/other-project) and press Enter to switch.What changed:
session.directoryviaTool.Contextinstead of the globalInstance.directory. This is concurrency-safe and follows the existing context-passing pattern./new <path>, validates the target, restarts the worker event stream, recreates the SDK client, and re-bootstraps all project data for the new directory./newwith no args still works as before.