Skip to content

Non-git projects use "/" as worktree, breaking permission path resolution #24694

Closed as not planned

Description

@d7pow

Description

Problem

When running in a non-git directory, Project.fromDirectory sets:

worktree: "/"
sandbox: "/"

This causes permission path resolution to break.

Example:

path.relative("/", "/home/.../artifacts/dry_run/file.md")
→ "home/.../artifacts/dry_run/file.md"

This does not match patterns like:

artifacts/dry_run/*

Impact

Even with a typical ruleset like:

edit:
"": "deny"
"artifacts/dry_run/
": "allow"

the allow rule never matches, because the evaluated path becomes:

home/.../artifacts/dry_run/...

So the final result is a deny, even though the config is correct.

Expected behavior

Non-git directories should treat the current directory as the project root:

worktree: directory
sandbox: directory

Plugins

None

OpenCode version

1.14.28

Steps to reproduce

Steps to reproduce

  1. Create a non-git directory (no .git folder)

  2. Create an opencode config with path-scoped permissions, for example:

edit:
"": "deny"
"artifacts/dry_run/
": "allow"

  1. Start opencode in that directory

  2. Attempt to create a file:

Create artifacts/dry_run/test.md

  1. Observe that the operation is denied

What happens

The evaluated path becomes:

home/.../artifacts/dry_run/test.md

instead of:

artifacts/dry_run/test.md

So the allow rule does not match and the deny rule applies.

Expected

The file should be created successfully because it matches the allow rule.

Screenshot and/or share link

No response

Operating System

Debian GNU/Linux 13 (trixie)

Terminal

Konsole Version 25.04.2

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 28, 2026
  2. github-actions commented on Apr 28, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If either of those captures your issue, please consider adding a comment there rather than opening a new one. If your report covers a distinct aspect not addressed in those issues, feel free to leave this open and clarify the difference.

  3. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. BennD commented on May 10, 2026

    @BennD

    Opened #26694 for this. Adds a workspaceRoot(ctx) helper next to containsPath (same file, same worktree === "/" sentinel) and uses it everywhere path.relative(instance.worktree, …) was anchoring on the worktree, including the file tools, tool/lsp.ts, and agent.ts's referencePath. Approach is similar to #18761 but consolidates the helper at the project layer rather than under tool/, and matches each test file's existing style instead of mixing patterns.

  5. added a commit that references this issue on May 10, 2026
    faa501b
  6. mattcoleanderson commented on Jun 22, 2026

    @mattcoleanderson

    The PR for this was closed automatically. Commenting for attention to this since opencode should never automatically get full privileges of my systems root directory without the user explicitly giving it

  7. github-actions commented on Aug 22, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  8. dimon222 commented on Aug 22, 2026

    @dimon222

    Reopen please, thus should never be fallback behavior

  9. gwerbin commented on Sep 4, 2026

    @gwerbin

    +1, I was really surprised when I saw this. What can be done to help?

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