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

Closed
opened 2026-02-16 17:45:08 -05:00 by yindo · 1 comment
Owner

Originally created by @dmmulroy on GitHub (Jan 11, 2026).

Originally assigned to: @rekram1-node on GitHub.

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"
    }
  }
}
Originally created by @dmmulroy on GitHub (Jan 11, 2026). Originally assigned to: @rekram1-node on GitHub. ## 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 ```bash 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`: ```typescript 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`: ```json { "permission": { "external_directory": { "**/.opencode/**": "allow" } } } ```
yindo closed this issue 2026-02-16 17:45:08 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 11, 2026):

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

  • #4479: Configurable instruction file search boundary - Related to file search behavior when running from subdirectories in monorepos
  • #5910: Undo previous message incorrectly restores project state - Uses similar Instance.directory vs Instance.worktree logic that may have related issues
  • #6316: Context Auto-Discovery for AGENTS.md - Addresses similar monorepo subdirectory file access patterns
  • #3321: Add cwd option to createOpencodeServer - Monorepo issue with subdirectory access to parent directories
  • #3603: Display warning when agents.md is not accessible - Related to sandboxing when running from subdirectories

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

@github-actions[bot] commented on GitHub (Jan 11, 2026): This issue might be a duplicate of existing issues. Please check: - #4479: Configurable instruction file search boundary - Related to file search behavior when running from subdirectories in monorepos - #5910: Undo previous message incorrectly restores project state - Uses similar Instance.directory vs Instance.worktree logic that may have related issues - #6316: Context Auto-Discovery for AGENTS.md - Addresses similar monorepo subdirectory file access patterns - #3321: Add `cwd` option to `createOpencodeServer` - Monorepo issue with subdirectory access to parent directories - #3603: Display warning when agents.md is not accessible - Related to sandboxing when running from subdirectories Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4710