Default behavior
By default, OpenCode uses the shell specified in yourSHELL environment variable. If SHELL is not set, it falls back to /bin/bash.
Configuration options
Setting the shell path
You can override the default shell in your OpenCode configuration:.opencode.json
Passing shell arguments
Shell arguments allow you to control how the shell is initialized:.opencode.json
The default argument is
["-l"], which starts the shell as a login shell, loading your profile files.Common configurations
Bash
- Login shell (default)
- Interactive shell
- Non-interactive
Loads
.bash_profile and .bashrc:.opencode.json
Zsh
- Login shell (recommended)
- Interactive shell
Loads
.zprofile and .zshrc:.opencode.json
Fish
.opencode.json
Custom shell
You can use any shell that supports the-c option for command execution:
.opencode.json
Shell argument reference
-l (login shell)
-l (login shell)
Starts the shell as a login shell, loading profile files.Bash: Loads
/etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profileZsh: Loads /etc/zprofile, ~/.zprofile, /etc/zshrc, and ~/.zshrcUse when: You need your full shell environment, including PATH modifications, aliases, and environment variables.-i (interactive shell)
-i (interactive shell)
Starts the shell in interactive mode.Bash: Loads
~/.bashrcZsh: Loads ~/.zshrcUse when: You want interactive features but don’t need full profile loading.No arguments
No arguments
Starts a non-interactive, non-login shell.Use when: You want minimal overhead and don’t need your custom environment.
-c <command>
-c <command>
Executes a specific command (automatically used by OpenCode).
Use cases
Loading custom environment variables
If your development environment requires specific environment variables, use a login shell:.opencode.json
~/.bash_profile or ~/.zprofile:
~/.bash_profile
Using version managers
If you use version managers likenvm, rbenv, or pyenv, you typically need a login shell:
.opencode.json
~/.zprofile
Minimal overhead
For faster command execution without environment customization:.opencode.json
CI/CD environments
In containerized or CI environments, you might want to ensure consistent behavior:.opencode.json
Troubleshooting
Commands not found
Commands not found
Symptoms: Tools like Verify your PATH is set correctly:
npm, python, or custom scripts are not foundSolution: Use a login shell to load your PATH:.opencode.json
~/.bash_profile
Aliases not working
Aliases not working
Symptoms: Shell aliases defined in your profile don’t workCause: Aliases are typically only available in interactive shellsSolution: Use functions instead of aliases, or use an interactive shell:Better approach - convert aliases to functions:
.opencode.json
~/.bashrc
Slow command execution
Slow command execution
Symptoms: Commands take a long time to startCause: Your shell profile may be loading slowly (plugins, external tools, etc.)Solution: Profile your shell startup:Optimize your profile files by:
- Lazy-loading plugins and tools
- Removing unnecessary initialization
- Using a faster shell configuration
Environment variables not set
Environment variables not set
Symptoms: Environment variables you set in your profile aren’t availableSolution: Ensure you’re using a login shell and the variables are exported:
~/.bash_profile
Permission denied errors
Permission denied errors
Symptoms: Shell can’t execute commands or scriptsSolution:
- Verify the shell path is correct and executable:
- Ensure scripts have execute permissions:
Advanced configuration
Per-project shell configuration
You can use a local.opencode.json in your project directory to override the global shell configuration:
./.opencode.json
Setting the SHELL environment variable
Alternatively, you can set theSHELL environment variable when launching OpenCode:
Testing your shell configuration
To test that your shell configuration works correctly:Best practices
Use login shells
Start with
-l to ensure your full environment is loaded.Keep profiles fast
Optimize shell startup time by lazy-loading tools and plugins.
Export variables
Always use
export for variables that need to be available to child processes.Test configurations
Test shell configurations before using them with OpenCode.