Shell Rc
Make the opencode agent shell load your zsh aliases and functions (via a fast ZDOTDIR shim), without paying for oh-my-zsh/compinit on every command.
0
0
20.0
Multi-signal model
23 hours ago
2026-10-04
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@jeffreyjyz/opencode-shell-rc@0.1.0"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@jeffreyjyz/opencode-shell-rc@0.1.0"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D @jeffreyjyz/opencode-shell-rcOpenCode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
Make the opencode agent shell load your zsh aliases and functions. The shell
tool runs /bin/zsh -c … in a non-interactive shell, which never reads
~/.zshrc, so an alias like gp='git push' fails in agent shells. This plugin
points every zsh the agent spawns at a .zshenv shim that sources the aliases and
functions your interactive shell defines — without paying for oh-my-zsh,
compinit, autosuggestions or syntax-highlighting on every command.
Install
Add it to the plugins array in ~/.config/opencode/opencode.json and restart
(or /reload) opencode:
{
"plugins": ["@jeffreyjyz/opencode-shell-rc"]
}
For local development point at the checkout instead (an absolute path is treated as a local plugin):
{
"plugins": ["/Users/you/dev/cmdcode-tools/opencode-shell-rc"]
}
After bun run build the root index.js shim loads dist/.
How it works
The plugin registers a shell.create.before hook. When the shell about to run is
zsh it:
- lays down
$XDG_STATE_HOME/opencode/shell-rc/(default~/.local/state/opencode/shell-rc/) containing:.zshenv— the tiny shim zsh reads first;state.zsh— the generated aliases and functions;.zshrc/.zprofile/.zlogin— symlinks to your real files so nested interactive/login shells still find them;
- regenerates
state.zshonly when the rc changed (~/.zshrc,~/.zshenvor oh-my-zsh), by runningzsh -ic 'alias -L; typeset -f'once — zsh's own serializer, so every alias and function is captured exactly — thenzcompiles it so sourcing costs ~0.5ms instead of ~10ms; - sets
ZDOTDIRfor that command.
Per-command cost is ~0ms: the generated state is sourced from .zshenv, and the
rc is re-read only on a change.
What you get and what you don't
| kept | skipped |
|---|---|
| every alias (incl. oh-my-zsh's) | oh-my-zsh startup / theme |
| every shell function | compinit, completions |
an optional ~/.config/opencode/shell.zsh |
autosuggestions, syntax-highlighting |
PATH and environment variables are not snapshot — the agent shell inherits
the environment opencode was started with. If you add a PATH entry to .zshrc,
restart opencode for the agent to see it; alias and function edits are picked up
on the next command with no restart.
Non-zsh shells are left completely untouched. If zsh is missing or generation
fails, ZDOTDIR is not set and the agent shell behaves exactly as before.
Development
bun install
bun test
bun run typecheck
bun run build
Similar plugins
Goal
@prevalentware/opencode-goal-plugin
OpenCode goal plugin that adds Codex-style long-running goal mode, /goal commands, persistence, and TUI status for AI coding agents.
Pty
opencode-pty
OpenCode plugin for interactive PTY management - run background processes, send input, read output with regex filtering
Skills Tui
opencode-skills-tui
OpenCode TUI plugin that shows skills and loaded state in the sidebar