Add external directories to your OpenCode session context with automatic permission approval.
- Install the plugin:
cd ~/.config/opencode
npm install opencode-add-dir- Add
"opencode-add-dir"to your~/.config/opencode/opencode.jsoncplugins array:
-
Restart OpenCode
-
Use the command:
/add-dir /path/to/your/project- Zero Configuration: Works immediately after installation
- Auto Permission: No permission prompts for directories you add
- Smart Filtering: Automatically skips node_modules, .git, binary files, etc.
- Recursive Scanning: Reads entire directory structures
- File Limits: 100KB per file, 500 files max (to prevent overwhelm)
- Full Access: Read and write to added directories
/add-dir <path>scans the directory and adds all files to context- Directory path is automatically registered for future access
- Any operations on that directory skip permission prompts
- Works recursively - all subdirectories are auto-approved
# Add a project directory
/add-dir ~/projects/my-app
# Add any external directory
/add-dir /path/to/external/code
# Now you can read/write without permission prompts
read ~/projects/my-app/src/index.js
edit ~/projects/my-app/package.jsonnode_modules.gitdist,build.next__pycache__- Virtual environments (
.venv,venv,env) .env,.env.*coverage.nuxt,.outputtmp,temp,.turbo
Images, PDFs, Office docs, archives, media files, executables, compiled files, etc.
The plugin's postinstall script automatically:
- Finds your OpenCode config directory (
~/.config/opencode/) - Creates the
/add-dircommand file - Installs it to
~/.config/opencode/command/add-dir.md
If the /add-dir command doesn't work after installation:
- Verify the command file exists:
ls -la ~/.config/opencode/command/add-dir.md- If missing, create it manually:
mkdir -p ~/.config/opencode/command
cat > ~/.config/opencode/command/add-dir.md << 'EOF'
---
description: Add an external directory to the session context
---
Add the directory at path $ARGUMENTS to this session's context.
Use the add_dir tool to read all files from the specified directory.
EOFFor contributors and maintainers:
# Clone the repository
git clone https://github.com/kuzeofficial/add-dir-opencode.git
cd opencode-add-dir
# Install dependencies
bun install
# Build the TypeScript source
bun run build
# Test locally
npm link
cd ~/.config/opencode
npm link opencode-add-dir
# Publish new version
npm version patch # or minor/major
npm publishsrc/index.ts- Main plugin with permission auto-approvalcommand/add-dir.md- Command definition (auto-installed)scripts/install.js- Post-install script (auto-runs)package.json- NPM package configuration
MIT
{ "plugin": [ "your-other-plugins", "opencode-add-dir" ] }