Uninstall OpenCode: remove it, and its data, cleanly
opencode uninstall stops the service and removes the package but keeps sessions and keys. What each install route leaves, and how to delete the rest.
Run opencode uninstall. On OpenCode 2 it stops the background service, deletes the cache and, for an npm, pnpm, bun or yarn install, removes the package; it keeps your sessions, saved keys and configuration. After a curl install it prints an rm line for the binary, and the folder ~/.opencode and its PATH line in ~/.bashrc are yours to delete. A Homebrew install needs brew uninstall opencode-v2. For a clean slate, also delete ~/.config/opencode, ~/.local/share/opencode and ~/.local/state/opencode, which takes every session and stored credential with them. On OpenCode 1 the same command deletes everything, data included, unless you pass --keep-data and --keep-config.
Which version you have
opencode --version # 1.x.x is version 1; "opencode v2.x.x" is version 2
command -v opencode # where the binary is, which tells you how it was installedCopiedThe two versions remove themselves differently, so check before you start. A path under ~/.opencode/bin is the curl installer, a path under Homebrew’s Cellar is Homebrew, and a path under a Node prefix is npm, pnpm, bun or yarn. Both versions take --dry-run, which prints the plan and changes nothing; run it first.
OpenCode 2: what opencode uninstall does
opencode debug paths # note where your data is, before the binary goes
opencode uninstall --dry-run
opencode uninstall # asks to confirm; -f skips the questionCopiedThe command reference says it “stops background services, removes the global cache, and uninstalls OpenCode”, and that “session data, configuration, and state are not removed.” In the source at 2.3.2 the kept folders are named for what they hold: “sessions, credentials, settings, and prompt history”. It works out how OpenCode was installed from where the running binary sits, and that decides the rest:
| Installed with | What uninstall does about the program | What is left for you |
|---|---|---|
curl ( opencode.ai/v2/install) | Prints To finish removing the binary, run: and an rm line | The binary, ~/.opencode, the PATH line |
npm | Runs npm uninstall --global @opencode/cli | Nothing |
pnpm | Runs pnpm remove --global @opencode/cli | Nothing |
bun | Runs bun remove --global @opencode/cli | Nothing |
yarn | Runs yarn global remove @opencode/cli | Nothing |
Homebrew | Nothing | brew uninstall opencode-v2 |
mise, or not detected | Warns that it could not detect the installation method | The package, by its own manager |
If the package manager’s command fails, uninstall prints Run manually: with the command to run yourself. In every case the background service is stopped first and the cache, ~/.cache/opencode, is deleted. A mise install, from mise use -g opencode, comes off with mise unuse -g opencode, which removes the entry from mise’s global config and prunes the installed version. An AUR install (opencode-beta) comes off with pacman or your AUR helper.
Finishing a curl install by hand
The version 2 installer puts the binary in ~/.opencode/bin, writes a small opencode2 script beside it that runs the same binary, and adds two lines to the first shell file it finds (~/.bashrc for bash, ~/.zshrc for zsh, ~/.config/fish/config.fish for fish):
# opencode
export PATH=/home/you/.opencode/bin:$PATHCopiedUninstall removes that PATH line only when nothing else is in the binary’s folder, because, in the source’s words, “V1 and V2 curl installs share a PATH entry; retain it while another binary uses it.” The opencode2 script counts as something else, so on a normal version 2 install the line stays, and the folder is never deleted. After uninstall has run:
rm -rf ~/.opencodeCopiedThen open ~/.bashrc (or the file named above for your shell) and delete the # opencode line and the export PATH line under it. Open a new shell, or the old one keeps the folder in its PATH until it exits.
A clean slate: removing the data too
Keeping the data is the default so a reinstall picks up where you left off. To remove OpenCode completely, delete these after uninstall has stopped the service:
rm -rf ~/.config/opencode # opencode.json, cli.json, the service's settings and password
rm -rf ~/.local/share/opencode # opencode.db (sessions, saved keys), logs
rm -rf ~/.local/state/opencode # the running service's registrationCopiedWhat goes is not recoverable. The database is where, as the providers page puts it, “saved API keys and OAuth tokens live”, and it holds every session and its history. Deleting it removes your copy of the keys, not the keys: an API key you want dead is revoked in the provider’s own console. A variable you gave the service with opencode service set env is in ~/.config/opencode/service.json and goes with that folder. If you only want to sign out of one provider and keep the rest, opencode auth logout does that before you uninstall.
Those are the usual places. The database can sit elsewhere if OPENCODE_DB or an XDG_ variable is set, or on another release channel, which is why the first command above was opencode debug paths: what it printed is the list to trust. If you are deleting the data because opencode.db has grown to many gigabytes, the guide to the huge opencode.db covers shrinking it in place. An opencode.json or .opencode folder inside a project belongs to that project and is not touched by any of this; the config guide lists where OpenCode reads them.
OpenCode 1
Version 1’s uninstall is the opposite default: “Uninstall OpenCode and remove all related files.” It deletes the data, cache, config and state folders and, for a curl install, cleans the PATH line and prints the rm for the binary. Two flags spare parts of it:
opencode uninstall --dry-run
opencode uninstall --keep-data --keep-config # -d -c; keep sessions and settingsCopiedFor a package-manager install it runs the manager’s own command against the version 1 package, opencode-ai: npm uninstall -g opencode-ai, pnpm uninstall -g opencode-ai, bun remove -g opencode-ai, yarn global remove opencode-ai, or brew uninstall opencode.
If you are removing version 1 to install version 2, do not let it delete the data. Both versions use ~/.local/share/opencode and the same config folder, and version 2 imports version 1’s sessions and saved keys from there the first time it starts. Either uninstall with --keep-data --keep-config, or skip the uninstall: opencode upgrade --major swaps the binary or the package for version 2 in place. Moving from OpenCode 1 to 2 covers that, and the sessions that look missing afterwards.
Checking nothing is left
hash -r; command -v opencode # prints nothing once it is gone
pgrep -af opencode # no "opencode serve --service" still running
ls -d ~/.opencode ~/.config/opencode ~/.local/share/opencode ~/.local/state/opencodeCopiedIf command -v still finds one, a second install is on the machine, often a curl install and a package one side by side; remove it by its own route and check again. A service process still listed is one the uninstall did not stop, typically started by a different binary or under another account; stop it with that install’s opencode service stop before deleting it, or end the PID. A systemd unit or cron job you wrote for opencode serve or opencode run is your own and stays until you disable it. The guide to OpenCode’s background service covers how that process starts and where it registers. To install again afterwards, installing OpenCode on Linux has both install lines.