[PR #8190] fix: don't ask for permission for cd within project #12652

Open
opened 2026-02-16 18:17:33 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8190

State: open
Merged: No


What does this PR do?

Fixes #8192.

Fixes false permission requests when chained cd commands navigate within the project directory. Previously, commands like cd subdir && do something && cd .. would incorrectly trigger an external_directory permission request because all paths were resolved relative to the initial working directory rather than tracking the effective directory after each cd.

image

The fix tracks an effectiveCwd variable that updates after each cd command, so subsequent path resolutions use the correct context.

How did you verify your code works?

Added three tests in test/tool/bash.test.ts:

  • cd subdir && ls && cd .. does not request external_directory permission
  • cd a && cd b && cd c && cd .. && cd .. && cd .. (nested navigation) does not request permission
  • cd subdir && cd ../.. (actually escapes project) still correctly requests permission

Verified tests fail before the fix and pass after.


WIP: Not all combinations of commands are &&s, so cd shouldn't always change the effective working directory of the next command. We should instead use the AST provided by the tree-sitter and track the working directory along its paths.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8190 **State:** open **Merged:** No --- ### What does this PR do? Fixes #8192. Fixes false permission requests when chained `cd` commands navigate within the project directory. Previously, commands like `cd subdir && do something && cd ..` would incorrectly trigger an `external_directory` permission request because all paths were resolved relative to the initial working directory rather than tracking the effective directory after each `cd`. <img width="386" height="242" alt="image" src="https://github.com/user-attachments/assets/05e04a77-8ede-416b-a5bf-abd3c1c65f5a" /> The fix tracks an `effectiveCwd` variable that updates after each `cd` command, so subsequent path resolutions use the correct context. ### How did you verify your code works? Added three tests in `test/tool/bash.test.ts`: - `cd subdir && ls && cd ..` does not request external_directory permission - `cd a && cd b && cd c && cd .. && cd .. && cd ..` (nested navigation) does not request permission - `cd subdir && cd ../..` (actually escapes project) still correctly requests permission Verified tests fail before the fix and pass after. --- **WIP:** Not all combinations of commands are `&&`s, so `cd` shouldn't always change the effective working directory of the next command. We should instead use the AST provided by the tree-sitter and track the working directory along its paths.
yindo added the pull-request label 2026-02-16 18:17:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12652