The goal of this project is to provide a standalone, containerized version of the OpenCode CLI that feels transparent to the user. It allows you to run OpenCode without polluting your host system's global npm packages, while maintaining access to your projects and persistent data.
The solution uses a "transparent wrapper" strategy with focused isolation:
-
Containerized Environment: The tool runs inside a lightweight
node:20-slimcontainer. -
Granular Helper Script (
opencode):- Auto-Build: Automatically builds the container image (
opencode-cli) if it's missing. - Focused Mounting:
- Workdir: Mounts
$PWDto$PWDso you can run it anywhere. - Persistence: Maps Host XDG directories to specific container paths:
XDG_DATA_HOME/opencode->/dataXDG_CACHE_HOME/opencode->/cache
- Clean Home: Uses the container's native
/home/nodeasHOMEto avoid permission conflicts, ensuring a stable runtime environment.
- Workdir: Mounts
- User Mapping: Uses
--userns=keep-id(Podman) to ensure file ownership on the host remains correct (your user, not root).
- Auto-Build: Automatically builds the container image (
-
Lifecycle Management:
install.sh: Deploys the wrapper to~/.local/share/opencode-cli.uninstall.sh: Removes the installation and cleans up the Docker image.
To install the wrapper permanently:
- Run the install script:
./install.sh
- Ensure
~/.local/binis in yourPATH.
Run opencode as if it were a local binary:
# Initialize OpenCode
opencode /init
# Run the agent
opencodeTo remove the tool and the container image:
# Run the uninstall script from the source directory
./uninstall.sh
# OR from the install location (if installed)
~/.local/share/opencode-cli/uninstall.shWhen you run opencode:
- It checks for the
opencode-cliimage. - If missing, it triggers a
podman buildusing the embeddedContainerfile. - It runs the container with:
HOME=/home/node(Internal container home)XDG_DATA_HOME=/data(Mapped from host)XDG_CACHE_HOME=/cache(Mapped from host)PWDmapped nicely. This ensures user data persists across runs (server connections, history), but temporary config files generated during runtime do not clutter your host home directory.