# zsh-opencode-ai 🤖 - AI-Powered Shell Command Generation
Convert natural language comments to shell commands with a single Tab press
Lightning-fast AI completion powered by OpenCode and GitHub Copilot
Quick Start • Features • Configuration • Usage • Development
Stop googling shell commands. Just describe what you want in plain English, press Tab, and get the exact command you need.
zsh-opencode-ai gives you:
- ⚡ Instant AI completion: Type
# list all files→ press Tab → getls -la - 🎯 Context-aware suggestions: Understands your intent and generates precise commands
- 🔄 Seamless integration: Works alongside existing completions (fzf-tab, zsh-autosuggestions)
- 🎨 Clean UX: Animated spinner feedback, no prompt clutter
- 🔧 Configurable: Switch AI models, adjust behavior via environment variables
- Installation
- Quick Start
- Features
- Configuration
- Usage
- Development
- Troubleshooting
- Contributing
- License
- Zsh (shell)
- OpenCode installed and configured (installation guide)
- Authenticated AI provider (GitHub Copilot recommended, OpenAI supported)
- Oh My Zsh (optional, recommended)
# Clone this repository to Oh My Zsh custom plugins directory
git clone https://github.com/USER/zsh-opencode-plugin ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-opencode-ai
# Add to plugins in ~/.zshrc
plugins=(... zsh-opencode-ai)
# Reload shell
source ~/.zshrc# Clone the repository
git clone https://github.com/USER/zsh-opencode-plugin ~/zsh-opencode-ai
# Add to ~/.zshrc
source ~/zsh-opencode-ai/zsh-opencode-ai.plugin.zsh
# Reload shell
source ~/.zshrc# Type a comment and press Tab
# remove all log files
<Tab>
# Should see spinner, then command appearsEnsure you have an AI provider authenticated:
# Check authentication status
opencode auth list
# If GitHub Copilot not authenticated
opencode config
# Select GitHub Copilot and follow prompts# Type a natural language comment (starts with #)
$ # list all files
# Press Tab key
⠋ AI generating command...
# Command appears clean
$ ls -la
# Press Enter to execute# Find files
# find all PDF files modified in last week
<Tab>
→ find . -type f -name "*.pdf" -mtime -7
# System operations
# show disk usage sorted by size
<Tab>
→ du -sh * | sort -h
# Git operations
# show git commits from last month
<Tab>
→ git log --since="1 month ago" --oneline
# Process management
# kill all node processes
<Tab>
→ pkill -f nodePress ? for examples, Ctrl+C to cancel generation.
- Natural language → command conversion: Describe intent, get executable command
- Tab key trigger: Seamless integration with existing Tab completion
- Animated spinner: Visual feedback during AI generation (~8s response time)
- Clean prompt handling: Original comment removed, only command visible
- Multiple AI models: GitHub Copilot, OpenAI GPT-4, Anthropic Claude supported
- fzf-tab compatibility: Falls back to standard completion for non-
#lines - Multi-format response parsing: Handles markdown blocks, inline code, raw text
- Prompt echo removal: Strips duplicated prompt from AI responses
- Configurable model selection: Switch models via environment variable
- Spinner customization: Adjust animation speed and style
- OpenCode integration: Uses local OpenCode server for AI access
- GitHub Copilot support: Authenticated provider, ~8s response time
- OpenAI support: Requires re-authentication, ~2-4s response time
- Anthropic support: Alternative AI provider option
Configuration is merged from multiple sources (in order of precedence):
- Defaults (hardcoded in plugin)
- Environment variables (highest priority)
# Set AI model (default: github-copilot/gpt-4o)
export OPENCODE_MODEL="github-copilot/gpt-4o"
# Alternative models (requires authentication)
export OPENCODE_MODEL="openai/gpt-4"
export OPENCODE_MODEL="anthropic/claude-3-5-sonnet-20241022"
# Adjust spinner animation speed (default: 0.1 seconds)
export OPENCODE_SPINNER_DELAY=0.1
# Set in ~/.zshrc for persistence
echo 'export OPENCODE_MODEL="github-copilot/gpt-4o"' >> ~/.zshrcNo config file needed. All settings via environment variables.
# File operations
# copy all images to backup folder
<Tab>
→ cp *.{jpg,png,gif} backup/
# compress all logs into archive
<Tab>
→ tar -czf logs.tar.gz *.log
# find files larger than 100MB
<Tab>
→ find . -type f -size +100M
# System monitoring
# show top 10 memory consuming processes
<Tab>
→ ps aux --sort=-%mem | head -11
# check listening ports
<Tab>
→ lsof -iTCP -sTCP:LISTEN -n -P
# Git workflows
# undo last commit but keep changes
<Tab>
→ git reset --soft HEAD~1
# show files changed in last commit
<Tab>
→ git diff --name-only HEAD~1
# Network operations
# download file from URL
<Tab>
→ curl -O <URL>
# test network connectivity to domain
<Tab>
→ ping -c 4 google.com- Type comment: Start line with
#followed by natural language - Press Tab: Triggers AI generation
- See spinner: Visual feedback during processing (~8s)
- Review command: AI-generated command appears in buffer
- Execute or edit: Press Enter to run, or edit before running
-
Be specific: More detail = better commands
- ❌
# list files - ✅
# list all files including hidden sorted by modification time
- ❌
-
Include context: Mention file types, paths, constraints
- ❌
# find files - ✅
# find all .log files in /var/log modified today
- ❌
-
Use natural language: Write like you're asking a human
- ✅
# show me the 10 largest files in current directory - ✅
# kill all processes using port 8080
- ✅
- Zsh 5.0+ (required for ZLE widgets)
- Python 3.x (for response parsing)
- OpenCode (installed and running)
zsh-opencode-plugin/
├── zsh-opencode-ai.plugin.zsh # Main plugin file (ZLE widget)
├── README.md # This file
├── AGENTS.md # AI agent development guidelines
├── LICENSE # MIT License
├── .gitignore # Git ignore rules
├── banner.svg # Project banner (generated)
├── banner.png # Project banner (generated)
└── docs/ # Local documentation (gitignored)
└── INSTALL.md # Detailed installation guide
- ZLE Widget Binding:
^I(Tab) bound to_opencode_ai_suggest_or_fzf - Trigger Detection: Checks if
BUFFERstarts with# - Prompt Extraction: Strips
#and whitespace from buffer - Line Clearing:
zle kill-whole-lineremoves original prompt - Spinner Start: Background process with Braille animation (
⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏) - OpenCode Call:
opencode run --model <MODEL> "<SYSTEM_PROMPT>" - Response Parsing: Python script handles markdown/inline/raw formats
- Spinner Kill: Clean shutdown of background process
- Command Insertion: Only generated command placed in
BUFFER - Fallback: Non-
#lines fall through to fzf-tab or default completion
- OpenCode: AI model orchestration
- GitHub Copilot: Default AI provider
- Python: Response parsing
- Zsh: Shell and ZLE framework
- Formatter:
shfmt -w zsh-opencode-ai.plugin.zshbefore commit - Linter:
shellcheck zsh-opencode-ai.plugin.zshmust pass - Keep Zsh widget logic minimal and readable
- Test with multiple AI models (GitHub Copilot, OpenAI, Anthropic)
- Ensure spinner cleanup on all exit paths
- Handle edge cases (empty prompts, network failures, timeout)
Cause: AI model not authenticated or unavailable
Fix:
# Check authentication
opencode auth list
# Re-authenticate if needed
opencode configCause: ZLE widget not properly bound or conflicting plugin
Fix:
# Check binding
bindkey | grep '\^I'
# Should show: "^I" _opencode_ai_suggest_or_fzf
# Disable conflicting plugins temporarily
# Edit ~/.zshrc, comment out other Tab completion pluginsCause: /dev/tty write issue or terminal doesn't support \r\033[K
Fix:
# Test terminal capabilities
printf "\r\033[K" > /dev/tty
# Try different terminal emulator (iTerm2, Kitty, Alacritty)Cause: Using OpenAI without authentication or network latency
Fix:
# Switch to GitHub Copilot (faster)
export OPENCODE_MODEL="github-copilot/gpt-4o"
# Or re-authenticate OpenAI for faster API access
opencode configCause: Ambiguous prompt or model misunderstanding
Fix:
- Be more specific in your natural language description
- Include file types, paths, constraints explicitly
- Test different phrasings
- Check if model supports your use case
Cause: OpenAI OAuth token expired
Fix:
# Re-authenticate
opencode config
# Select OpenAI provider
# Follow OAuth flow in browser
# Verify authentication
opencode auth listContributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feat/amazing-feature) - Make your changes
- Test thoroughly (multiple shells, AI models, edge cases)
- Lint code (
shellcheck zsh-opencode-ai.plugin.zsh) - Commit your changes (
git commit -m 'feat(completion): add amazing feature') - Push to the branch (
git push origin feat/amazing-feature) - Open a Pull Request
- All PRs require review before merging
- Code must pass
shellchecklinting - Must test with at least 2 AI models
- Update documentation as needed
- Follow conventional commit format
This project is licensed under the MIT License - see the LICENSE file for details.
Built using:
- OpenCode - AI model orchestration and session management
- GitHub Copilot - Default AI provider for command generation
- Zsh - Shell and ZLE (Zsh Line Editor) framework
Inspired by:
- zsh-autosuggestions - Fish-like autosuggestions
- fzf-tab - Fuzzy completion framework
Special thanks to early testers and contributors.
- Documentation: See docs/INSTALL.md for detailed installation
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- OpenCode: OpenCode Documentation
Stop googling. Start describing. 🤖