Skip to content

feat(tui): add /cd directory switching command and change_directory agent tool - #43238

Closed
AndyS77 wants to merge 4 commits into
anomalyco:devfrom
AndyS77:dir-switch
Closed

AndyS77 wants to merge 4 commits into
anomalyco:devfrom
AndyS77:dir-switch

Conversation

@AndyS77

@AndyS77 AndyS77 commented Aug 18, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #43223

Type of change

  • New feature

What does this PR do?

Adds a /cd TUI slash command and a change_directory agent tool that lets users and agents switch the session working directory without restarting. This supports worktree-based workflows where you move between git worktrees of the same project.

/cd TUI command: Opens a dialog with inline path input, resolves relative paths against the current directory, calls moveSession, sends a synthetic system-reminder to the session, refreshes VCS state, and shows a toast.

change_directory agent tool: Resolves relative paths against instance.directory (not process.cwd()), calls MoveSession.Service.moveSession, and returns success/error output. Agents currently have no way to switch directories — this fills that gap.

Both use the existing experimental.controlPlane.moveSession API.

Files:

  • packages/tui/src/feature-plugins/home/change-directory.tsx — TUI command
  • packages/tui/src/feature-plugins/home/change-directory.test.tsx — TUI tests
  • packages/tui/src/feature-plugins/builtins.ts — plugin registration
  • packages/opencode/src/tool/change-directory.ts — agent tool
  • packages/opencode/src/tool/change-directory.txt — tool description
  • packages/opencode/src/tool/registry.ts — tool registry entry
  • packages/opencode/test/tool/change-directory.test.ts — agent tool tests

How did you verify your code works?

TUI: 10 tests covering plugin registration, command properties, submit flow (moveSession call, promptAsync system-reminder, VCS refresh, success toast), and error handling (moveSession failure, no active session).

Agent tool: 6 tests covering tool ID, description, parameter schema, successful execution, missing parameter error, and DestinationProjectMismatchError.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

AndyS77 and others added 3 commits August 18, 2026 09:44
Add a /cd slash command that allows switching the working directory
of a running session to a different worktree path. Uses the existing
experimental controlPlane.moveSession API to move the session and
refreshes VCS state after the switch.

This enables parallel worktree workflows where multiple sessions
work on different branches without restarting opencode.

Co-Authored-By: glm/zai-glm-52 <[email protected]>
Co-Authored-By: glm/zai-glm-52 <[email protected]>
Agent: @tdd
Scope: dir-switch
Co-Authored-By: glm/zai-glm-52 <[email protected]>
Agent: @tdd
Scope: dir-switch
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@IvanovCosmin

Copy link
Copy Markdown

This is really exciting! thanks @AndyS77

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/tui/src/feature-plugins/home/change-directory.tsx:47 — promptAsync(...).catch(() => undefined) swallows failures of the system-reminder prompt while the success toast still shows; if that call fails the agent never learns about the directory change. Consider at least logging or a distinct toast.
  • packages/tui/src/feature-plugins/home/change-directory.tsx:41 — moveChanges: false is hardcoded; users with uncommitted changes in the old worktree get no warning that changes won't follow the session. Consider surfacing this in the dialog.
  • packages/opencode/test/tool/change-directory.test.ts — MoveSession is fully mocked, so there's no coverage of real path resolution/validation (e.g. nonexistent target, relative-path resolution base, permission checks). Worth one integration-style test for the failure surface the tool claims to handle.
  • packages/tui/src/feature-plugins/home/change-directory.tsx:60 — vcs.get(...).then((res) => sync.setStore("vcs", res.data)) writes undefined into the store if res.data is absent; consider guarding before overwriting existing VCS state.
  • Test file header says "TDD RED tests" — leftover scaffolding language worth cleaning up before merge.

- promptAsync failure shows warning toast (not silent catch)
- vcs.get with no data does not call setStore('vcs')
- Fix VCS test assertion for reconcile-wrapped data
- Add change-directory tool implementation and tests

Co-Authored-By: zai-glm-52 <[email protected]>
Agent: @bug-fix
Scope: anomalyco#43238
@AndyS77

AndyS77 commented Sep 14, 2026

Copy link
Copy Markdown
Author

Added tests for the review fixes:

  • promptAsync failure → warning toast: Mocks promptAsync to reject, verifies a warning toast is shown with the error message (not silently swallowed)
  • vcs.get with no data → no setStore call: Mocks vcs.get to return { data: undefined }, verifies setStore is NOT called with 'vcs' and a success toast is still shown
  • Fixed existing VCS test: Adjusted assertion to handle reconcile-wrapped data from solid-js/store

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 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.

[FEATURE]: Add /cd directory switching command and change_directory agent tool

4 participants