Skip to content

feat: add per-session directory and /new <path> switching#12015

Closed
MrTravisB wants to merge 9 commits intoanomalyco:devfrom
MrTravisB:travis/new_session_directory
Closed

feat: add per-session directory and /new <path> switching#12015
MrTravisB wants to merge 9 commits intoanomalyco:devfrom
MrTravisB:travis/new_session_directory

Conversation

@MrTravisB
Copy link

@MrTravisB MrTravisB commented Feb 3, 2026

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:

  • Tools now resolve paths from session.directory via Tool.Context instead of the global Instance.directory. This is concurrency-safe and follows the existing context-passing pattern.
  • The TUI prompt intercepts /new <path>, validates the target, restarts the worker event stream, recreates the SDK client, and re-bootstraps all project data for the new directory.
  • Error recovery rolls back to the previous directory on failure.

/new with no args still works as before.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

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
@MrTravisB MrTravisB force-pushed the travis/new_session_directory branch from 7b6f48d to ce4ce7e Compare February 3, 2026 21:12
@MrTravisB MrTravisB changed the title feat: add per-session working directory and /new <path> directory switching feat: add per-session directory and /new <path> switching Feb 3, 2026
…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.
@MrTravisB MrTravisB force-pushed the travis/new_session_directory branch from e9825d5 to f8e5f83 Compare February 3, 2026 21:22
@MrTravisB MrTravisB closed this Feb 3, 2026
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.

Allow explicitly changing working directory

1 participant

Comments