Automatically allows OpenCode agents to access files in configured directories without permission prompts.
Problem
By default, OpenCode restricts file access to the directory where it's launched. When agents try to access files outside this directory, they trigger permission prompts. This can be tedious in multi-project workspaces.
Solution
This plugin reads allowed directories from .opencode/opencode-allowlist.json config files and automatically approves file access requests to those locations.
Installation
From npm (Recommended)
# Add to your opencode.json { "plugin": [ "opencode-allowlist@latest" ] }
Then create .opencode/opencode-allowlist.json:
{
"allowedDirectories": [
"/Users/username/workspace/projects"
]
}From Source
- Clone and install dependencies:
git clone https://github.com/crayment/opencode-allowlist.git
cd opencode-allowlist
npm install- Add the plugin to your
opencode.json:
{
"plugin": [
"file://{env:HOME}/path/to/opencode-allowlist/src/index.ts"
]
}- Create
.opencode/opencode-allowlist.jsonto configure allowed directories:
{
"allowedDirectories": [
"/Users/username/workspace/projects"
]
}Configuration
Create a .opencode/opencode-allowlist.json file. The plugin searches from your current directory up to the git worktree root (matching OpenCode's pattern):
{
"allowedDirectories": [
"/Users/username/workspace/projects",
"/Users/username/other-workspace",
"/path/to/shared/libraries"
]
}Multiple configs: You can have configs at different levels (e.g., workspace root and project level). All found configs are merged together.
Why a separate file? OpenCode's opencode.json has strict schema validation and won't accept custom fields. This separate config file gives us flexibility without breaking OpenCode's validation.
Config Search Pattern
The plugin follows OpenCode's config search pattern:
- Global config: Checks
~/.config/opencode/opencode-allowlist.jsonand~/.local/share/opencode/config/opencode-allowlist.json - Workspace configs: Searches from current directory up to git worktree root
- Merges all found configs: All allowedDirectories from all levels are combined
Example:
~/.config/opencode/opencode-allowlist.json ← Global (all projects)
/Users/username/workspace/.opencode/opencode-allowlist.json ← Workspace level
/Users/username/workspace/projects/my-project/.opencode/opencode-allowlist.json ← Project level
All three configs are loaded and merged! This matches how OpenCode loads plugins and configs.
Path Matching
- Paths are matched using
startsWithafter normalization - All subdirectories of an allowed directory are automatically included
- Supports absolute paths only (for security and clarity)
Examples
If you configure (in .opencode/opencode-allowlist.json):
{
"allowedDirectories": ["/Users/username/workspace/projects"]
}Then these paths are auto-allowed:
- ✅
/Users/username/workspace/projects/project-a/file.ts - ✅
/Users/username/workspace/projects/project-b/src/main.ts - ✅
/Users/username/workspace/projects/nested/deep/file.md
But these are NOT:
- ❌
/Users/username/workspace/other-folder/file.ts - ❌
/Users/username/other-repo/file.ts
Usage
Once configured, the plugin works automatically. No manual intervention needed.
Checking Configuration
The plugin provides a tool that agents can use:
This will show the currently configured allowed directories.
Security
Why No Add/Remove Tools?
This plugin intentionally does NOT provide tools for the agent to add or remove directories. This is a security feature:
- Without tools: Only you (the human) can modify allowed directories via config
- With tools: An agent could grant itself access to any directory on your system
Manual Configuration Only
To change allowed directories:
- Edit
.opencode/opencode-allowlist.jsonmanually - Add or remove paths from the
allowedDirectoriesarray - Restart your OpenCode session (config is cached)
How It Works
- Plugin loads on OpenCode startup
- Searches for
.opencode/opencode-allowlist.jsonfiles from current directory up to worktree root - Merges all found configs and caches in memory
- Hooks into
permission.askevents - When agent requests external directory access:
- Checks if path matches any allowed directory
- Auto-approves if match found
- Otherwise, normal permission prompt appears
Development
# Install dependencies bun install # Run in development mode bun run dev # Build for production bun run build # Run tests bun test
Troubleshooting
Plugin not loading
Check console output for [Allowlist] messages:
[Allowlist] Loaded 1 allowed directories from /path/to/.opencode/opencode-allowlist.json
[Allowlist] Total 1 unique allowed directories configured
Directories not being allowed
- Check paths are absolute (not relative)
- Verify
.opencode/opencode-allowlist.jsonsyntax is valid JSON - Ensure
.opencode/opencode-allowlist.jsonexists somewhere between your current directory and worktree root - Check console for
[Allowlist] ✗ Not in allowed list: /path
Config changes not taking effect
The config is cached in memory. Restart your OpenCode session after changing .opencode/opencode-allowlist.json.
License
MIT