Skip to content

Harden the companion Claude Code plugin and how it is installed - #4289

Merged
backnotprop merged 10 commits into
mainfrom
fix/claude-code-run-plugin-hardening
Nov 30, 2026
Merged

backnotprop merged 10 commits into
mainfrom
fix/claude-code-run-plugin-hardening

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Hardening of the second Claude Code plugin (plannotator-run) and of the code that installs it. Nothing a person sees changes: no new words, steps or settings.

Changes:

  • The companion's tool.run hook (runs on every Bash call) can no longer throw into Claude Code: the whole body sits in one try. First it calls the main plugin's action with nothing to open. With no action there, that call throws before $.session.id() or anything else runs, and the call is passed on untouched. next is called once, outside the try. Why: $.session.id() used to run before the try. Claude Code refuses typeof $.plannotatorRun ("used as a value"), so a first call that does nothing is how the hook checks for the action.
  • The installers (sh, ps1, cmd) read the Claude Code version only from a first line of the form <x.y.z> (Claude Code), the same rule as the daily check. Why: before, they took any x.y.z, so a wrapper printing "Using node 22.14.0" first was read as Claude Code 22.
  • The installers read and write the daily check's record (companionSeen in claude-run-companion.json in the data dir). If the companion was installed before and is now gone, it is not installed again. A successful install, or a companion already there, is recorded. A record that cannot be read counts as "never installed". Why: someone who removed it got it back on the next update.
  • No companion is installed when the person has disabled the main plugin. The installers check enabledPlugins in Claude Code's user settings; the daily check checks enabled: false in plugin list --json. Why: the companion was added next to a disabled plugin.
  • Daily check: it runs the marketplace update and tries again for the installers' wider set of "unknown to the marketplace" messages. On failure it writes one cleaned-up line of the reason (at most 120 characters) to update.log. Why: the old pattern was too narrow, and the log gave no reason.
  • plannotator uninstall also clears the daily check's date (checkedAt), so a reinstall right after is picked up without waiting a day. The record is written to a temp file and renamed into place. On Windows, CLAUDECODE is removed from the environment whatever its letter case.
  • Windows installers: the silent companion step now runs before the "Claude Code plugin: …" result line, so a slow step does not look like a pause after it. What prints is unchanged.
  • A test in tests/claude-code-plugins.test.ts fails if the marketplace stops offering an id the daily check or the installers install (plannotator-run@plannotator). Why: a removed or renamed entry would leave installed users with "Plugin plannotator-run not found in marketplace plannotator" and a failing update. The guide now says the entry stays while installs exist, and that plannotator uninstall is how it is retired.
  • Guide (claude-code-mod.md): who gets the companion, who does not, and how a person opts out (remove or disable it, and it stays out).

Run locally against real Claude Code (sandboxed HOME, no login):

  • plugin validate on the companion: passes on 2.1.329 and 2.1.330.
  • The main plugin validates on 2.1.287 and 2.1.325.
  • plugin test (the main plugin's suite with the companion): 93 pass, 0 fail on 2.1.287, 2.1.325, 2.1.329 and 2.1.330.
  • After plugin disable plannotator@plannotator, plugin list --json shows "enabled": false on 2.1.287, 2.1.329 and 2.1.330.

Tests run locally:

  • early-run: 40 pass.
  • mod register: 10 pass.
  • claude-run-companion: 41 pass.
  • uninstall: 131 pass, 1 skip.
  • install.test.ts with the companion and Claude Code plugin filters: 54 pass, 137 skipped; the PowerShell cases run only in CI.
  • claude-code-plugins: 5 pass. Renaming the entry makes 2 of them fail; checked, then reverted.
  • agents-md-size: 3 pass.
  • tsc: server, mod and hook server are clean.

Not in this round: what happens after /reload-plugins if Claude Code does not re-run engine.create, and Windows .cmd shims.

Every step of the hook runs inside one try. It first asks the main plugin's
action with no call in it, which answers nothing; with no such action that
throws before $.session.id() or anything else runs, and the call is passed
on untouched. next is called once, outside the try.
…removed companion out, skip a disabled plugin

- claude --version counts only when its first line is "<x.y.z> (Claude Code)",
  as the daily check reads it; a wrapper's own line before it, or anything
  else, is an unknown version and the companion is left alone.
- The installers consult the daily check's record (claude-run-companion.json,
  companionSeen, in the data dir): absent and installed before means the
  person removed it, so it is not installed again. An install that succeeds,
  or a companion found there, is recorded. An unreadable record reads as
  never installed.
- No companion step when enabledPlugins in Claude Code's user settings turns
  plannotator@plannotator off.
- Windows: the silent companion step runs before the plugin's result line
  instead of after it; what prints is unchanged.
…ce retry, a reason in the log, small fixes

- readPluginList requires the main plugin enabled: a row with enabled false
  (what plugin list --json prints after plugin disable on 2.1.287 to
  2.1.330) is main-plugin-disabled, nothing is installed and companionSeen
  is kept.
- The marketplace update and retry run when the install's output says the
  plugin is not found, does not exist, no such or unknown in the
  marketplace, the pattern the installers use.
- A failure logs one sanitized line of why (the output's last non-empty
  line, control characters stripped, at most 120 characters) to the same
  update.log line.
- forgetRunCompanion (plannotator uninstall) also clears checkedAt, so an
  install right after is picked up without waiting a day.
- The marker is written to a temp file in the data dir and renamed.
- On Windows CLAUDECODE is cleared whatever its case.
A test fails when the marketplace no longer offers an id the daily check
or the installers install (plannotator-run@plannotator), and the guide
says the entry stays while installs exist; plannotator uninstall retires it.
The companion is installed once per Claude Code config folder, but the
"companion seen" flag was kept once per data dir, so a second profile
(another CLAUDE_CONFIG_DIR) or a restored data dir never got it. The marker
now keeps companionSeenIn: one entry per config folder (its real path, lower
case on Windows) with the main plugin's installedAt when the companion was
seen. Removed means: this folder's entry, the same installedAt now (Claude
Code keeps it through an update and sets it anew on a reinstall), and no
companion. Anything else, an older marker's single flag included, installs.

Also: the Claude Code version is the first line of `claude --version` that
reads "x.y.z (Claude Code)" (a wrapper may print its own line first), and the
update.log reason drops colour sequences, also the "[31m" left when the ESC
was already stripped.
…on line anywhere

The three installers apply the daily check's rule: a missing companion is
installed unless the shared marker has this config folder's entry with the
main plugin's installedAt now; they write this folder's entry and keep the
others. An older marker's single companionSeen flag reads as no entry.

- install.sh: the disabled main plugin is read only inside enabledPlugins (a
  false under another key no longer means disabled); a file whose
  enabledPlugins cannot be told apart reads as enabled. The checkedAt read
  cannot fail the function (|| true).
- All three: the first `claude --version` line that reads
  "x.y.z (Claude Code)" is the version, not only the first line.
- install.ps1 / install.cmd: a temp marker left by a failed move is removed;
  the companion step has its own try, so the result line always prints; the
  marker is written with ConvertTo-Json -InputObject (the attestation guard
  bans a piped ConvertTo-Json in these files, which failed CI's unit-3 lane).
  Under PowerShell 7 an installedAt read as a [datetime] is written back in
  Claude Code's form, so it compares equal.

install.cmd's PowerShell line is 8151 characters (cmd.exe's limit is 8191).
@backnotprop
backnotprop marked this pull request as ready for review November 30, 2026 19:19
@backnotprop backnotprop added the ci:e2e Run the full browser suite (Inbox window e2e) on this PR label Nov 30, 2026
@backnotprop
backnotprop merged commit ebf5a07 into main Nov 30, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:e2e Run the full browser suite (Inbox window e2e) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant