Skip to content

permissions: managed macOS temp directory prompts for /var path alias #52272

Closed

Description

@Rikonorus

Summary

On macOS, OpenCode v2.0.19 requests external_directory permission for a literal /var/folders/<id>/<id>/T/opencode/... path, even though this is the /var alias of OpenCode's managed temporary directory.

The effective permission rules include a built-in allow rule for the realpath spelling /private/var/folders/<id>/<id>/T/opencode/*. The shell permission parser passes the literal /var/... directory from cd to authorization, and the boundary check compares it lexically without resolving it to its realpath. Therefore, the built-in allow rule does not match.

Environment

  • opencode version: 2.0.19
  • OS: macOS (Darwin, arm64)
  • Terminal: iTerm.app (TERM=xterm-256color, COLORTERM=truecolor)
  • Shell: /bin/zsh
  • Install/channel: installed release 2.0.19; npm latest is 2.0.20
  • Active plugins: A configured plugin is present but does not handle permission evaluation.

Reproduction

  1. On macOS, start OpenCode v2.0.19 in a clean project with no saved permission approvals.
  2. Use a literal path under the macOS temporary-directory alias:
    /var/folders/<id>/<id>/T/opencode/probe
    
  3. Have the agent invoke the shell tool with:
    mkdir -p /var/folders/<id>/<id>/T/opencode/probe && cd /var/folders/<id>/<id>/T/opencode/probe && pwd
  4. Observe the permission request.

Expected Behavior

No external_directory confirmation should be requested.

The permissions documentation states: "OpenCode also allows external-directory access to its managed tool-output, shell-output, temporary, and global configuration directories." The literal /var/folders/<id>/<id>/T/opencode/... path refers to the same macOS location as the built-in allowed realpath:

/private/var/folders/<id>/<id>/T/opencode/*

Actual Behavior

OpenCode requests external_directory permission for:

/var/folders/<id>/<id>/T/opencode/probe/*

This was also observed with a user-rejected request for:

cd /var/folders/<id>/<id>/T/opencode/<dir> && git status --short

In v2.0.19, the shell parser extracts literal directories from directory-changing commands such as cd. It does not resolve $TMPDIR during permission analysis: commands containing that shell expression are not a valid reproduction of this issue.

Additional Context

The built-in allow rule uses the realpath spelling:

/private/var/folders/<id>/<id>/T/opencode/*

Inspection of v2.0.19 indicates that FileAccess.resolve / authorizeExternal performs the relevant boundary comparison lexically, without canonicalizing the supplied /var/... path first. As a result, the equivalent macOS aliases do not match.

A workaround is to add an explicit allow rule for the /var spelling:

{
  "action": "external_directory",
  "resource": "/var/folders/*/*/T/opencode/*",
  "effect": "allow"
}

With that rule, the reproduction command no longer requests permission.

The relevant agent.ts, file-access.ts, shell/parse.ts, and global.ts files did not change between v2.0.19 and v2.0.20, so this behavior is likely still present in v2.0.20.

Related

Activity

  1. github-actions commented on Sep 30, 2026

    @github-actions
    Contributor

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

    • #16660: Reports unnecessary external_directory prompts when canonical project paths and symlink-spelled tool paths do not match.
  2. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced this on 2.0.19. On Linux I pointed TMPDIR at a symlink to fake macOS's /var → /private/var alias. A shell cd into the realpath spelling of OpenCode's managed temp directory ran without a prompt. The same cd through the symlinked spelling asked for external_directory permission (pattern …/opencode/probe-alias/*), just as you describe.

    On the latest dev (f0160a1) this no longer happens. #53585 ("stop asking for external directory access by default") removed the default external_directory: ask rule, so with default permissions the /var/folders/... alias is allowed and there's no prompt. I checked this by evaluating the default agent's permission rules on dev, not by re-running the TUI script. The latest release, 2.2.0, also no longer has the ask default, so upgrading should get rid of the prompt.

    One caveat: the external-directory check still compares paths as plain text, without resolving symlinks. If you set external_directory to ask yourself, alias spellings can still behave differently. Related:

    The bot will close this issue in 1 day unless you reply that it still happens, e.g. on 2.2.0 or newer.

  3. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Closing this as completed, since there's been no reply in the day since my last comment. I reproduced the prompt for the /var/... alias of the managed temp directory on 2.0.19. On the latest dev it no longer happens: #53585 stopped asking for external_directory access by default. 2.2.0 doesn't have the ask default either, so upgrading should get rid of the prompt.

    If it still happens on 2.2.0 or newer, please comment here or open a new issue with your version and permission config. Separately, the plain-text path comparison when external_directory is set to ask is tracked in #52224 and #58638. Thanks again for the thorough report!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions