A comprehensive opencode plugin that enforces best practices by blocking potentially harmful or non-reproducible commands and file edits.
The plugin blocks various commands to promote better development practices:
node
- Blocked in favor ofbun
orbunx
npm
- Blocked in favor ofbun
orbunx
pip
- Blocked in favor ofuv
oruvx
python
,python2
,python3
- Blocked in favor ofuv
oruvx
- Exception: Virtual environment python commands are allowed:
- ✅
.venv/bin/python
,.venv/bin/python3
- ✅
venv/bin/python
,venv/bin/python3
- ✅
env/bin/python
,env/bin/python3
- ✅
- Exception: Virtual environment python commands are allowed:
- Write operations - Only read-only git commands are allowed:
- ✅
git status
- ✅
git diff
- ✅
git show
- ❌
git add
,git commit
,git push
,git checkout
, etc.
- ✅
- Local flake references - Must use proper prefixes:
- ✅
nix run path:./my-flake#output
- ✅
nix run github:user/repo#output
- ✅
nix run git+https://github.com/user/repo#output
- ❌
nix run ./my-flake#output
- ✅
Prevents editing of auto-generated lock files:
package-lock.json
- Usebun install
orbun update
insteadbun.lockb
- Usebun install
orbun update
insteadyarn.lock
- Useyarn install
oryarn upgrade
insteadpnpm-lock.yaml
- Usepnpm install
orpnpm update
insteadpoetry.lock
- Usepoetry install
orpoetry update
insteaduv.lock
- Useuv sync
oruv lock
insteadCargo.lock
- Usecargo update
insteadGemfile.lock
- Usebundle install
orbundle update
insteadflake.lock
- Usenix flake update
instead
# Add to your opencode plugins
The plugin works out of the box with sensible defaults. All blocking rules are hardcoded for consistency and reliability.
# JavaScript with Bun
bun install
bunx create-react-app my-app
# Python with uv
uv sync
uvx ruff check .
# Virtual environment python (allowed)
.venv/bin/python script.py
venv/bin/python3 -c "print('hello')"
# Git read operations
git status
git diff HEAD~1
git show HEAD
# Nix with proper prefixes
nix run path:./my-flake#hello
nix run github:nix-community/nixpkgs-fmt#nixpkgs-fmt
# These will be blocked with helpful error messages
node --version
npm install
pip install requests
python script.py # (but .venv/bin/python is allowed)
git add .
nix run ./my-flake#hello
The plugin detects and blocks various command injection techniques:
- Piping:
echo "node --version" | bash
- Command substitution:
echo $(node --version)
- Backticks:
echo \
node --version`` - Semicolons:
ls; node --version
- Logical operators:
ls && node --version
- Background execution:
node --version &
- Redirection:
node --version > output.txt
- Environment variables:
NODE_ENV=prod node app.js
- Eval/Exec:
eval "node --version"
- Quoted strings:
bash -c "node --version"
The plugin uses sophisticated regex patterns to detect blocked commands in:
- Complex command structures
- Multi-line commands
- Nested command substitutions
- Various quoting styles
Run the test suite:
npm test
# or
bun test
The plugin includes comprehensive tests covering:
- All blocked commands and allowed alternatives
- File edit restrictions
- Various escape methods and edge cases
- Integration scenarios
This plugin enforces several development best practices:
- Reproducibility: Blocks direct package manager usage in favor of modern alternatives
- Lock File Integrity: Prevents manual editing of auto-generated lock files
- Git Workflow: Encourages proper git workflows by limiting write operations
- Nix Best Practices: Ensures proper flake referencing for reproducibility
- Security: Blocks potentially harmful command injection techniques
When adding new blocking rules:
- Add the rule to the appropriate constant (e.g.,
BLOCKED_COMMAND_MESSAGES
) - Implement the validation logic in the corresponding function
- Add comprehensive tests covering various usage patterns
- Update this README with the new functionality
This plugin is part of the opencode ecosystem.