Skip to content

fix(config): ask the harness whether the marketplace is gone - #4048

Merged
max-sixty merged 2 commits into
mainfrom
fix-plugin-removal-false-success
Sep 9, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix-plugin-removal-false-success

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

wt config plugins claude uninstall and codex uninstall could print Plugin & marketplace removed and exit 0 over a marketplace that was still configured.

plugin marketplace remove exits non-zero when the marketplace is not configured, which is the state uninstall is trying to reach, so a second run would otherwise fail with nothing left to do (#4033). To tell that from a removal that genuinely failed, run_plugin_removal asked the harness's own config file. That reader could not fail loudly: a record the harness renamed or moved is the same missing key or missing file as a record it never wrote, so a confident absence was also the answer for every genuine failure.

For Codex this isn't hypothetical. codex plugin marketplace remove deletes the whole marketplaces key along with the last entry under it, leaving an empty config.toml:

$ codex plugin marketplace add max-sixty/worktrunk
$ cat $CODEX_HOME/config.toml
[marketplaces.worktrunk]
source_type = "git"
source = "https://github.com/max-sixty/worktrunk.git"
$ codex plugin marketplace remove worktrunk
$ cat $CODEX_HOME/config.toml
$

So an absent marketplaces key had to read as "already removed" for a second uninstall to succeed, and that same reading swallowed every real failure. Making the reader distinguish "no key at all" from "key present, worktrunk absent" would just trade the false success back for the failure it was introduced to fix.

Both harnesses publish their marketplaces as structured output, so this asks them instead:

$ claude plugin marketplace list --json
[{"name":"worktrunk","source":"github","repo":"max-sixty/worktrunk"}]
$ codex plugin marketplace list --json
{"marketplaces":[{"name":"worktrunk","root":"…"}]}

An empty list is the harness saying it holds nothing, which is a different fact from a file that isn't where wt looked. A harness that won't answer — the subcommand gone, output that isn't JSON, or entries that aren't named marketplace objects — yields None, and the removal's error stands. The shape check now fails closed rather than open. The cost is that a repeat uninstall against a harness with no --json loses its clean exit and shows the harness's own "not configured" message instead.

Reading Codex's config also meant wt carried its own copy of the CODEX_HOME resolution rule. The child reads the variable itself, so codex_config_dir goes with the reader.

Verification and tests

Verified end-to-end against the real claude (2.1.265) and codex (0.153.4), with a shim that fails only plugin marketplace remove and forwards everything else. With the marketplace really configured both uninstalls surface the error and exit 1; with nothing configured both exit 0.

The mock-driven tests move from config-file fixtures to the mock's plugin marketplace list --json stdout, which is now the whole variable between the cases. Per harness: an empty list and a list naming only another marketplace both tolerate the failed removal; a list naming worktrunk surfaces it; and three unusable answers — the subcommand rejecting --json, stdout that isn't JSON, and a list reshaped so it parses and means something else — each leave the error standing. The three unusable cases assert the exit status and stderr directly rather than snapshotting, since they share one outcome that the single-case tests either side already pin.

Both guards were checked by mutation: making plugin_marketplace_list return an empty list on a non-zero exit fails case_1_unsupported, and dropping the entry-shape ? in marketplace_listed fails case_3_reshaped.

Local gate: cargo run -- hook pre-merge --yes — 4832 tests passed, cargo fmt, clippy, and pre-commit run --all-files clean.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

max-sixty and others added 2 commits September 8, 2026 17:00
`wt config plugins claude uninstall` and `codex uninstall` could print
`Plugin & marketplace removed` and exit 0 over a marketplace that was
still configured.

`plugin marketplace remove` exits non-zero when the marketplace is not
configured, which is the state uninstall is trying to reach, so a second
run would otherwise fail with nothing left to do. To tell that from a
removal that genuinely failed, `run_plugin_removal` asked the harness's
own config file. That reader could not fail loudly: a record the harness
renamed or moved is the same missing key or missing file as a record it
never wrote, so a confident absence was also the answer for every
genuine failure.

Measured against the real CLIs, this is not hypothetical for Codex.
`codex plugin marketplace remove` deletes the whole `marketplaces` key
along with the last entry under it, leaving an empty `config.toml`:

    $ codex plugin marketplace add max-sixty/worktrunk
    $ cat $CODEX_HOME/config.toml
    [marketplaces.worktrunk]
    source_type = "git"
    source = "https://github.com/max-sixty/worktrunk.git"
    $ codex plugin marketplace remove worktrunk
    $ cat $CODEX_HOME/config.toml
    $

So an absent `marketplaces` key had to read as "already removed" for a
second uninstall to succeed, and that same reading swallowed every real
failure. Making the reader distinguish "no key at all" from "key present,
worktrunk absent" would just trade the false success back for the failure
it was introduced to fix.

Both harnesses expose their marketplaces as structured output, so this
asks them instead:

    $ claude plugin marketplace list --json
    [{"name":"worktrunk","source":"github","repo":"max-sixty/worktrunk"}]
    $ codex plugin marketplace list --json
    {"marketplaces":[{"name":"worktrunk","root":"…"}]}

An empty list is the harness saying it holds nothing, which is a
different fact from a file that isn't where wt looked. A harness that
won't answer — the subcommand gone, output that isn't JSON, or entries
that aren't named marketplace objects — yields `None`, and the removal's
error stands, so the shape check fails closed rather than open. That
costs a repeat uninstall on a harness with no `--json` its clean exit;
it sees the harness's own "not configured" message instead.

Reading Codex's config also meant wt carried its own copy of the
`CODEX_HOME` resolution rule. The child reads the variable itself, so
`codex_config_dir` goes with the reader.

Verified end-to-end against the real CLIs, with a shim failing only
`plugin marketplace remove`: with the marketplace really present the
error surfaces for both harnesses, and with nothing configured both
uninstalls exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015DzKvVGJbopPJan9YYpz4T
@max-sixty
max-sixty merged commit f5cac67 into main Sep 9, 2026
40 checks passed
@max-sixty
max-sixty deleted the fix-plugin-removal-false-success branch September 9, 2026 00:18
max-sixty added a commit that referenced this pull request Sep 9, 2026
`wt config show` read Claude Code's `installed_plugins.json` and Gemini
CLI's `~/.gemini/extensions/` directory to report the plugin and
extension status. Both reads have the failure mode #4048 removed from
the marketplace reader sitting beside them: a store the tool relocated
is the same missing path as one it never wrote, so an installed plugin
reads as absent and the section prints `Plugin not installed` over a
plugin that is installed and enabled.

Both answers now come from the tool — `claude plugin list --json` and
`gemini extensions list -o json` — through one `harness_listing` helper
that the two marketplace readers share.

That leaves reading another tool's file with a single case, and a rule
rather than an exception behind it: wt reads `~/.claude/settings.json`
because wt writes it (`install-statusline` merges the `statusLine` key
in) and Claude Code has no command that reports the setting back.
OpenCode's and Pi's plugin files are wt's own writes too. Everything
else it asks.

## The uninstall simplification

`claude plugin uninstall` and `claude plugin marketplace remove` both
exit non-zero once their target is gone, so `wt config plugins claude
uninstall` now runs both through `run_plugin_removal`, each tolerating
only the absence Claude Code itself reports. That deletes the coupled
early return whose condition had to name both halves (`!plugin_installed
&& is_marketplace_configured() == Some(false)`), the conditional command
preview built to match it, and two tests that had become the same run.
The Claude Code and Codex uninstalls are now the same shape.

Behavior change: a repeat `claude uninstall` no longer prints `Plugin
not installed` and skips. It runs both removals and reports `Plugin &
marketplace removed`, which is what `codex uninstall` has always done.

## What was measured

Against `claude` 2.1.266 and `codex` 0.153.4, in throwaway
`CLAUDE_CONFIG_DIR` / `CODEX_HOME` directories:

| command | already in the target state |
|---|---|
| `claude plugin install` | exit 0, "is already installed" |
| `claude plugin marketplace add` | exit 0, "already on disk" |
| `claude plugin uninstall` | **exit 1**, "not found in installed
plugins" |
| `claude plugin marketplace remove` | **exit 1**, "Marketplace
'worktrunk' not found" |
| `codex plugin remove` | exit 0 |

So the install's short-circuit is a convenience over idempotent commands
— an answer wt cannot read costs a redundant run rather than a wrong one
— while the uninstall's tolerance is load-bearing. `codex plugin remove`
keeps `run_plugin_cli`, since it has nothing to tolerate.

End to end, with a shim forwarding to the real `claude` except forcing
the removals to exit 1: an uninstall over an installed plugin exits 1
carrying claude's own error, and a repeat uninstall over nothing exits
0. `wt config show` reports `Plugin installed` / `Plugin not installed`
correctly across an install and an uninstall of the real plugin.

## Cost

`wt config show` gains one spawn per section it renders: ~140 ms for
`claude`, ~630 ms for `gemini`, taking a run with both CLIs installed
from ~0.6 s to ~1.4 s. Neither query reaches the network. It is a
hand-run diagnostic rather than a hot path, so the two calls stay
sequential; running them concurrently would need the section renders
plumbed into threads.

## Tests

`is_plugin_installed` mutated to a confident `Some(false)` fails four
tests, including `test_plugins_claude_uninstall_command_fails`, which is
the one that would otherwise swallow a genuine failure.

The harness needed one change beyond the fixtures.
`configure_mock_commands` prepends mock-bin to the *caller's* `PATH`, so
a real `claude` or `gemini` on the developer's machine can answer in a
mock's place — which is why `setup_mock_claude_installed` and
`setup_mock_gemini_installed` now write a mock rather than only setting
the detection override.

## Review follow-up

`ConfigPluginsClaudeCommand::Uninstall`'s `after_long_help` still
described the early return this PR deletes ("skips gracefully only when
both are already gone"). It now names the current contract, and the
recovery note it carried is still true and stays:

> Requires `claude` CLI. Both removals run every time, tolerating only
the "already gone" error Claude Code itself reports. Running it again is
safe, and finishes an uninstall that removed the plugin and then failed
on the marketplace.

The Codex counterpart never described a skip, so it is unchanged.
`claude install`'s "Skips gracefully if already installed" still holds.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_015DzKvVGJbopPJan9YYpz4T

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.78.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **Hook scripts read renamed context keys**: the JSON piped to every hook drops `worktree`, `repo_root`, `main_worktree`, and `main_worktree_path` in favour of `worktree_path`, `repo_path`, `repo`, and `primary_worktree_path`. Config templates migrate on load, so hooks written with the old names keep working; scripts reading the JSON, `--execute` templates, and `--var` overrides need updating. (Breaking.) ([#4080](max-sixty/worktrunk#4080))

- **`wt config plugins pi` installs for Pi; oh-my-pi moves to `wt config plugins omp`**: `pi install` wrote an oh-my-pi hook, which Pi never loads; Pi users re-run it to get a Pi extension. Existing oh-my-pi hooks keep working, listed as outdated until `wt config plugins omp install`. (Breaking: scripts that run `wt config plugins pi` for oh-my-pi need `omp`.) [Docs](https://worktrunk.dev/claude-code/#oh-my-pi) ([#4135](max-sixty/worktrunk#4135), thanks @ashebanow)

- **Interactive prompts no longer open with a blank line**: `wt config shell install`, `wt config plugins claude install`, and the commit-message setup offer in `wt merge` began with one. ([#4059](max-sixty/worktrunk#4059))

- **`wt config show` gives a single `wt config shell install` hint**: an outdated wrapper, a fish wrapper at the deprecated `conf.d` path, and missing fish completions each printed their own hint. The zsh `compinit` snippet is now syntax-highlighted. ([#4059](max-sixty/worktrunk#4059))

- **`wt config update --output <path>` confirms the write**: it now prints `✓ Wrote user config migration @ ~/migrated.toml` where it printed nothing. `--output=-` stays silent. ([#4053](max-sixty/worktrunk#4053))

### Fixed

- **Removal no longer discards untracked files hidden by `status.showUntrackedFiles = no`**: under that setting, a worktree holding only untracked files looked clean, so `wt remove`, `wt merge`, and `wt step prune` removed it without `--force`. Safety checks now always count untracked files, and auto-staging warnings list every file they stage. ([#4111](max-sixty/worktrunk#4111), thanks @Duang777)

- **`wt remove` and `wt merge` check the right worktree under an inherited `GIT_DIR`**: run from a `!wt` git alias or a git hook, which pass `GIT_DIR` down, `wt remove` could delete a dirty worktree without `--force`, and `wt merge` could refuse a clean merge. Both now check the worktree they act on. ([#4082](max-sixty/worktrunk#4082), thanks @Duang777)

- **`wt merge` no longer deletes a worktree locked with `git worktree lock`**: the merge completes and prints `Worktree preserved (locked)`. Every Worktrunk removal refuses a locked worktree, even with `--force`; run `git worktree unlock <path>` first. ([#4073](max-sixty/worktrunk#4073), thanks @Duang777)

- **`wt config update` no longer overwrites a config edited while its prompt is open**: it wrote the pre-prompt snapshot over the newer file and reported success. It now fails with the path and leaves the newer file; re-running previews the current contents. ([#4127](max-sixty/worktrunk#4127), thanks @zach-hammad-vs for reporting)

- **`wt step prune` no longer deletes a branch created minutes ago from an older commit**: `--min-age` aged a branch without a worktree by its commit's date, so a new branch off a day-old commit was pruned on the next run. Age now comes from the branch's oldest reflog entry. ([#4077](max-sixty/worktrunk#4077))

- **A comment or blank line above an inline config section no longer breaks the config**: a save or migration that rewrote `commit = { … }` as `[commit]` put that line inside the brackets. `wt switch`, `wt merge`, `wt remove`, and several `wt step` commands then failed with `Failed to load config`; `wt list` warned and ran without the config. Saves also dropped unrecognized keys from inline sections. ([#4120](max-sixty/worktrunk#4120), thanks @zach-hammad-vs for reporting)

- **Config saves keep the trailing comment on a value they rewrite**: a save such as answering the commit-generation offer dropped the comment after each value it rewrote, including one after an inline section's closing brace. ([#4138](max-sixty/worktrunk#4138))

- **Ignored project-config keys warn from every worktree**: an unknown key in `.config/wt.toml`, or one that belongs in user config such as `[merge]`, warned only in the main worktree, so `wt merge` from a linked worktree ignored it silently. ([#4145](max-sixty/worktrunk#4145), thanks @ee-prog for reporting)

- **`wt merge` skips `post-commit` when it removes that hook's worktree**: before, the hook ran in the primary worktree when the removed one sat inside the repository, and otherwise didn't run. The merge now prints `▲ Skipped post-commit`; move work that must finish there to `pre-remove`. ([#4049](max-sixty/worktrunk#4049))

- **`wt switch` recovers from a removed worktree in a bare repository**: `wt switch` and the picker surfaced git's raw `fatal: Unable to read current working directory` instead, and the removed-directory message lacked `wt switch ^`. ([#4067](max-sixty/worktrunk#4067))

- **`wt config shell install fish` puts the wrapper where fish reads it under a custom `$XDG_CONFIG_HOME`**: the wrapper always went to `~/.config/fish/functions/`, so install reported success while `wt switch` changed no directory. On Windows, the fish completion moves from `%APPDATA%\fish\completions` to the wrapper's directory. ([#4107](max-sixty/worktrunk#4107))

- **`wt config shell install zsh` honours `$ZDOTDIR` only when it is absolute**: an empty or relative value resolved against the current directory, so install appended to a `.zshrc` under the current directory and reported success while the file zsh reads went untouched. A non-absolute value now falls back to `$HOME`. ([#4085](max-sixty/worktrunk#4085))

- **`wt config shell install` for Nushell no longer deletes a `wt.nu` under the current directory**: an empty or relative `$XDG_CONFIG_HOME` resolved against it, so install removed a `nushell/vendor/autoload/wt.nu` beneath it unread, as a stale wrapper. It now falls back to `~/.config`, which also fixes unread `tea` logins that let `wt switch pr:<n>` treat a Gitea host as GitHub. ([#4104](max-sixty/worktrunk#4104))

- **`wt switch --create` names the branch a failed worktree add leaves behind**: `git worktree add -b` writes the branch ref before populating the worktree, so a failure in between left the branch with no worktree, and the next attempt reported a name collision. The error now says how to delete or reuse it. ([#4109](max-sixty/worktrunk#4109), thanks @technicalpickles for reporting)

- **`wt config shell install` no longer tells an already-wrapped shell to restart**: reinstalling from a shell with the wrapper loaded, such as after a version bump, printed `↳ Restart shell to activate shell integration`. ([#4059](max-sixty/worktrunk#4059))

- **`wt config shell install` migrates a deprecated `conf.d` fish wrapper when `~/.config/fish/functions` is missing**: before, only `wt config shell install fish` migrated it. `wt config show` now reports that wrapper even when fish isn't on `PATH`. ([#4059](max-sixty/worktrunk#4059))

- **Plugin status and uninstall checks ask the agent CLIs**: `wt config show` could list an installed Claude Code plugin or Gemini CLI extension as not installed, and `wt config plugins claude|codex uninstall` could report success over a marketplace still configured. A repeat Claude uninstall now runs both removals instead of stopping at `Plugin not installed`. ([#4048](max-sixty/worktrunk#4048), [#4054](max-sixty/worktrunk#4054))

- **`wt config plugins opencode install` no longer writes the plugin into the current directory**: with `OPENCODE_CONFIG_DIR` set but empty, it wrote `plugins/worktrunk.ts` there, typically inside a repository, reporting success though OpenCode never saw it. An empty value now counts as unset. ([#4084](max-sixty/worktrunk#4084))

- **The OpenCode plugin clears its activity marker when OpenCode 1 disposes it**: only explicit session deletion cleared it, so a finished session kept its `💬` and `wt list` showed it as active until `wt config state marker clear` was run by hand. ([#4129](max-sixty/worktrunk#4129), thanks @drewdas for reporting)

- **`wt config update` migrates `[ci] platform` into a `[forge]` section that only sets `hostname`**: that config, common with GitHub Enterprise and self-hosted GitLab, kept the deprecated key with no deprecation warning. ([#4061](max-sixty/worktrunk#4061))

- **Deprecated keys in an inline `[projects]` entry now migrate**: `"example.com/org/repo" = { merge = { no-ff = true } }` skipped the migration the section form got, so the per-project setting was ignored. ([#4122](max-sixty/worktrunk#4122), thanks @zach-hammad-vs for reporting)

- **A deprecated config section the migration can't rewrite now warns**: `select = "not a table"`, or a `[select]` whose `[switch.picker]` destination is already set, was ignored without a message. It now reports `unknown field select (will be ignored)`. ([#4121](max-sixty/worktrunk#4121), thanks @zach-hammad-vs for reporting)

- **`wt config update` no longer changes what a template renders**: it could rename `{{ repo_root }}` inside a quoted s

See merge request: Harmonybrew/homebrew-core!20435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants