fix(cli): keep data and config on uninstall

This commit is contained in:
Dax Raad
2026-10-07 16:33:24 -04:00
Unverified
parent 8587f817cc
commit b8d3c92985
4 changed files with 7 additions and 32 deletions
+1 -11
View File
@@ -73,18 +73,8 @@ const Root = Spec.make(typeof OPENCODE_CLI_NAME === "string" ? OPENCODE_CLI_NAME
},
}),
Spec.make("uninstall", {
description: "Uninstall OpenCode and remove all related files",
description: "Uninstall OpenCode, keeping session data and configuration",
params: {
keepConfig: Flag.boolean("keep-config").pipe(
Flag.withAlias("c"),
Flag.withDescription("Keep configuration files"),
Flag.withDefault(false),
),
keepData: Flag.boolean("keep-data").pipe(
Flag.withAlias("d"),
Flag.withDescription("Keep session data and snapshots"),
Flag.withDefault(false),
),
dryRun: Flag.boolean("dry-run").pipe(
Flag.withDescription("Show what would be removed without removing"),
Flag.withDefault(false),
@@ -20,11 +20,10 @@ export default Runtime.handler(
const updater = yield* Updater.Service
const method = yield* updater.method()
const removal = method ? updater.removal(method) : undefined
// Data and config hold sessions, credentials, and user-authored settings; uninstall never removes them.
const directories = [
{ path: global.data, label: "Data", keep: input.keepData },
{ path: global.cache, label: "Cache", keep: false },
{ path: global.config, label: "Config", keep: input.keepConfig },
{ path: global.state, label: "State", keep: false },
{ path: global.cache, label: "Cache" },
{ path: global.state, label: "State" },
]
// All channels share these directories. Stop their owners before deleting state or data.
// Read registrations directly: ServiceConfig.options() can migrate files even during a dry run.
@@ -38,7 +37,7 @@ export default Runtime.handler(
yield* Effect.forEach(directories, (directory) =>
Effect.gen(function* () {
if (!(yield* fs.exists(directory.path))) return
log.info(` ${directory.label}: ${directory.path}${directory.keep ? " (keeping)" : ""}`)
log.info(` ${directory.label}: ${directory.path}`)
}),
)
services.forEach((name) =>
@@ -85,7 +84,6 @@ export default Runtime.handler(
const errors: string[] = []
yield* Effect.forEach(directories, (directory) =>
Effect.gen(function* () {
if (directory.keep) return
progress.start(`Removing ${directory.label}...`)
yield* fs.remove(directory.path, { recursive: true, force: true }).pipe(
// Windows reports a terminated service as gone before it releases its database
@@ -563,12 +563,6 @@ Preview what would be removed.
$ opencode uninstall --dry-run
```
Keep configuration and session data.
```bash
$ opencode uninstall --keep-config --keep-data
```
View all subcommands and flags.
```bash
+2 -9
View File
@@ -96,16 +96,9 @@ opencode uninstall --dry-run
```
Run `opencode uninstall` to confirm removal. OpenCode stops registered background services and persistent terminals before
removing global data, cache, configuration, and state. These directories are shared by OpenCode versions and channels.
removing the global cache and state directories. These directories are shared by OpenCode versions and channels. Session
data and configuration are never removed.
To retain configuration and session data:
```bash
opencode uninstall --keep-config --keep-data
```
- `--keep-config` (`-c`) retains configuration files.
- `--keep-data` (`-d`) retains session data and snapshots. Cache and state are still removed.
- `--force` (`-f`) skips confirmation; use it for noninteractive removal.
- Package-manager installations use the detected package manager. Curl installations print the final command to remove
the executable manually.