zsh-ask-opencode
January 31, 2026 ยท View on GitHub
A simple ZSH plugin that integrates OpenCode AI with your shell, allowing you to generate shell commands using natural language. Press Ctrl+O to transform any text in your command line into optimized shell commands.

Features
- ๐ค AI-powered command generation using OpenCode API
- โก Interactive selection with fzf for choosing between 3 ranked options
- ๐ฏ Ranked by best practices - speed, safety, and reliability
- ๐จ Smooth UX with animated spinner feedback
- ๐ง Easy configuration for model selection and debug output
- โจ๏ธ Single keybinding (Ctrl+O) for quick access
Outcomes
- Faster command composition - generate complex shell commands instantly
- Learn shell commands - see how experts would approach tasks
- Interactive choice - pick the best command from 3 ranked options
- No command execution - you control what gets run
Dependencies
This plugin requires:
- opencode - OpenCode CLI for generating commands
- fzf (optional) - For interactive command selection (defaults to first option if not installed)
Installing Dependencies
opencode
Visit OpenCode documentation for installation instructions specific to your system.
fzf
# macOS with Homebrew
brew install fzf
# Linux with apt
sudo apt-get install fzf
# Or via your package manager
# https://github.com/junegunn/fzf#installation
Installation
Oh My Zsh
git clone https://github.com/andreacasarin/zsh-ask-opencode.git $ZSH_CUSTOM/plugins/zsh-ask-opencode
Then add zsh-ask-opencode to the plugins array in your ~/.zshrc:
plugins=(... zsh-ask-opencode)
Reload your shell:
source ~/.zshrc
Antidote
Add to your ~/.zsh_plugins.txt:
andreacasarin/zsh-ask-opencode
Then run:
antidote bundle
Manual Installation
Clone the repository:
git clone https://github.com/andreacasarin/zsh-ask-opencode.git ~/zsh-ask-opencode
Source it in your ~/.zshrc:
source ~/zsh-ask-opencode/zsh-ask-opencode.plugin.zsh
Usage
Simply type what you want to do, then press Ctrl+O:
$ list all files modified in the last 24 hours
^O
The plugin will:
- Show a spinner while asking OpenCode
- Generate 3 ranked command options
- Display an fzf menu to select your preferred command
- Insert the selected command into your command line
- You can review and press Enter to execute, or edit further
Examples
$ compress all jpg files in this directory to 50% size
^O
# Generates: convert *.jpg -quality 50% compressed.jpg
$ find all python files with more than 100 lines
^O
# Generates: find . -name "*.py" -exec wc -l {} + | awk '\$1 > 100'
$ restart the docker container named web
^O
# Generates: docker restart web
Configuration
Model Selection
Change the AI model used for generation by setting ASK_OPENCODE_MODEL:
# In your ~/.zshrc (before sourcing the plugin)
export ASK_OPENCODE_MODEL="github-copilot/gpt-5-mini" # default
export ASK_OPENCODE_MODEL="github-copilot/gpt-5" # more powerful
Available models depend on your OpenCode configuration.
Debug Mode
Enable debug output to see raw API responses and parsed commands:
# In your ~/.zshrc
export ASK_OPENCODE_DEBUG=1
This will print:
- Raw output from OpenCode (NUL-separated format)
- Parsed command array after splitting
- Helpful for troubleshooting
Example debug output:
[ask_opencode] Raw output (NUL-separated):
1 command1
2 command2
3 command3
[ask_opencode] Parsed commands:
1 ls -lah
2 ls -la
3 ls -l
Keybinding
The default keybinding is Ctrl+O. To change it, add to your ~/.zshrc:
# Change keybinding to Ctrl+G instead
bindkey '^G' ask_opencode
Troubleshooting
"opencode: command not found"
Ensure OpenCode is installed and in your $PATH:
which opencode
# If not found, install it per OpenCode documentation
No commands generated
Check debug output:
ASK_OPENCODE_DEBUG=1 your_prompt_here
^O
Look for error messages from OpenCode in the terminal.
Commands not appearing in fzf
If fzf is not installed, the plugin uses the first generated command by default. Install fzf to enable selection:
brew install fzf # or your package manager
Plugin not loading
Verify the file is being sourced:
# For Oh My Zsh
ls -la $ZSH_CUSTOM/plugins/zsh-ask-opencode/
# For manual installation
grep "zsh-ask-opencode" ~/.zshrc
Then reload:
source ~/.zshrc
exec zsh
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE for details
Author
Created by Andrea Casarin