Skip to content

Saved bash “Always” approval is reused across different working directories within the same project #51279

Closed as not planned

Description

@altrudev

Description

In the current V2 permission flow, persistent bash approval appears to be bound to the command string, but not to the working directory where that command executes.

In "packages/core/src/tool/bash.ts", bash permission is requested with:

action: "bash",
resources: [input.command],
save: [input.command],

"workdir" is resolved separately and is not part of the saved bash resource.

This means an approval such as:

npm test

can be saved once and then reused in another directory inside the same project, even though that second directory may have a different "package.json" and execute completely different code.

Minimal reproduction

Project:

repo/
a/
package.json
b/
package.json

Give "a/package.json" and "b/package.json" different "test" scripts.

  1. Run "npm test" with "workdir=a"
  2. Choose Always
  3. Run "npm test" with "workdir=b"
  4. Observe whether OpenCode asks again

If it does not, the saved permission is authorizing by command text alone, even though execution context changed.

Expected

Persistent bash approval should be scoped to enough execution context to preserve the meaning of the original authorization.

At minimum, that likely means binding the saved approval to:

project + command + canonical cwd

rather than only:

project + command

Why this matters

Commands such as:

npm test
npm run build
bun test
make
cargo run
./build.sh

can execute different code depending on "cwd".

So two identical command strings are not necessarily the same operation.

I found this while reviewing the authorization-to-execution binding in the current V2 permission path.

Valentyn Rukhaylo
Altru.dev

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. opencode-agent commented on Oct 22, 2026

    @opencode-agent
    Contributor

    Closing as working as intended.

    Persistent shell approvals in V2 are scoped to the project and keyed by command pattern, not by working directory. This matches the documented model: always approves future requests matching the suggested patterns, and for shell those are command prefixes like git status*. Configured shell permission rules are directory-agnostic in the same way.

    The code referenced here has also changed. Current dev saves a parsed prefix pattern from the shell parser (in packages/core/src/tool/plugin/shell.ts), not the exact command string. Commands that reach outside the project still go through the separate external_directory check.

    If you want per-directory control, keep the command on ask, or use the config rules to limit what can be approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions