Skip to content

external_directory permission triggered for .opencode/state within git worktree #7758

Closed

Description

@dmmulroy

Summary

When running opencode from a subdirectory (e.g., packages/lib-relay in a monorepo), accessing .opencode/state/ at the project root triggers external_directory permission prompts—even though the path is within the git worktree.

Reproduction

cd ~/Code/project/packages/some-package  # subdirectory of git repo
opencode run --command some-command feature-name
# Prompts for external_directory permission to access:
# /path/to/project/.opencode/state/feature-name

Root Cause

In packages/opencode/src/file/read.ts:30:

if (!Filesystem.contains(Instance.directory, filepath))
  • Instance.directory = CWD (packages/some-package)
  • Instance.worktree = git root (correctly identified)
  • Containment check uses CWD, not worktree

Paths within the git worktree but outside CWD are treated as external.

Expected Behavior

Paths within Instance.worktree (especially .opencode/ directories) should not trigger external_directory permission. Similar to how Truncate.DIR is auto-allowed in agent.ts:223.

Suggested Fix

Either:

  1. Check containment against both Instance.directory and Instance.worktree
  2. Auto-allow .opencode/** paths within the worktree (like Truncate.DIR)

Workarounds

  • Run from project root
  • Add to project opencode.json:
{
  "permission": {
    "external_directory": {
      "**/.opencode/**": "allow"
    }
  }
}

Activity

  1. github-actions commented on Jan 11, 2026

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

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