Execute bash commands directly in OpenCode without LLM processing
An OpenCode plugin that allows you to run bash commands instantly using the ! prefix, bypassing the AI agent for immediate command execution.
- Instant Execution: Run bash commands immediately with
!prefix - No LLM Overhead: Commands execute directly without AI processing
- Real-time Feedback: See command output and errors instantly
- Execution Logging: All commands are logged for audit trails
- Error Handling: Clear error messages when commands fail
Add the plugin to your OpenCode configuration:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-direct-bash"]
}OpenCode will automatically install the plugin on startup.
Install manually in your global config:
# Create plugin directory if it doesn't exist
mkdir -p ~/.config/opencode/plugin
# Copy the plugin file
cp src/index.ts ~/.config/opencode/plugin/direct-bash.tsInstall for a specific project:
# In your project root
mkdir -p .opencode/plugin
cp src/index.ts .opencode/plugin/direct-bash.tsIn the OpenCode TUI, simply prefix any bash command with !:
!ls -la
Lists all files in the current directory.
!git status
Shows the current git repository status.
!npm install
Installs project dependencies.
!pwd # Print working directory
!echo "Hello, World!" # Echo text
!node --version # Check Node version
!python3 --version # Check Python version
!docker ps # List running containers
!kubectl get pods # List Kubernetes pods
!cat package.json # Display file contents
!grep "TODO" src/**/*.ts # Search for TODOs
- Plugin intercepts user input via
tui.prompt.appendhook - Detects if input starts with
! - Extracts and executes the command using Bun shell API
- Shows execution result or error message
- Prevents original input from being sent to the LLM
No configuration required! The plugin works out of the box.
- Commands execute in the current working directory
- Make sure commands are safe - they execute directly without validation
- Long-running commands may block the UI
- Command execution is logged in OpenCode's logging system
- Standard output and errors are captured and displayed
- Written in TypeScript with full type support
- Uses Bun's shell API (
$) for command execution - Leverages OpenCode SDK for logging and toast notifications
- Uses
output.prevent = trueto block input from reaching the LLM
- OpenCode v1.0 or later
- No additional dependencies required
-
Verify the file is in the correct directory:
- Global:
~/.config/opencode/plugin/direct-bash.ts - Project:
.opencode/plugin/direct-bash.ts - Or added to
opencode.jsonconfig
- Global:
-
Restart OpenCode
- Verify the command syntax is correct
- Check if you have necessary permissions
- Review OpenCode logs for detailed error messages
- Ensure the command is available in your PATH
- Check OpenCode logs using the logging interface
- Some commands may not produce output (e.g.,
cd) - Try commands with explicit output (e.g.,
!echo test)
Check system information:
!uname -a
!which node
!df -h
Git operations:
!git log --oneline -5
!git branch
!git diff HEAD
Package management:
!npm list --depth=0
!yarn why package-name
!bun outdated
Docker operations:
!docker images
!docker-compose ps
!docker logs container-name
Contributions are welcome! Please feel free to submit issues or pull requests.
MIT License - see LICENSE file for details
Created for the OpenCode community
- Initial release
- Basic command execution with
!prefix - Error handling and logging
- Toast notifications for feedback