Skip to content

feat(install): confirm a killed Claude project change with repair or remove --yes - #974

Merged
777genius merged 5 commits into
mainfrom
feat/claude-project-attempt-recovery
Nov 17, 2026
Merged

777genius merged 5 commits into
mainfrom
feat/claude-project-attempt-recovery

Conversation

@777genius

Copy link
Copy Markdown
Owner

Follow-up to #968, found by running the installer against a real Claude Code on Linux.

#968 clears the attempt marker after Ctrl+C or SIGTERM, because by then the CLI is alive and knows that Claude's process tree is closed. If the CLI itself is killed (kill -9, out of memory, power loss) during one of Claude's native commands in project scope, nobody re-reads Claude's state: the state keeps a native_activation_attempt with no pending intent, and add, update, repair and remove all answered "native activation attempt ... is unresolved" with no way out except editing the state by hand.

repair --yes and remove --yes now confirm the interrupted change first and then do their usual work; doctor names both commands. The confirmation runs under the same mutation lock as any mutation and:

  1. refuses, naming the PID, while a claude ... plugin ... process or any Claude process with the same CLAUDE_CONFIG_DIR is still alive (read from the kernel on macOS and Linux; a Claude process whose arguments and environment cannot both be read counts as alive; the process list failing to read is a refusal, not a skip; on Windows the commands run in a job that dies with the CLI, so there are no orphans to find; other systems refuse);
  2. re-reads Claude's state once, read-only, with the same code as fix(install): resume Claude project native calls after an interrupt #968, and only an exact installation of the current package or a state where every recorded object is still exact lets it continue;
  3. clears only the marker, records the binding as failed and then runs the normal repair or removal.

--dry-run makes the same checks and writes nothing; without --yes the command asks for it; anything unrecognised keeps the block and the refusal says how to check Claude's state by hand. docs/NATIVE_SETUP_COMPLETION.md now states the two exceptions to "an uncertain effect is never reported as unchanged": the #968 re-read after a proven-closed process tree, and this explicit confirmation, which does not prove closure (the process check is a heuristic) and never records "unchanged" (committed effect, binding failed).

One existing #968 test changed: an unproven interrupt used to refuse remove --yes for good; now it is cleared when no Claude process is alive, so the test models a live child process and keeps asserting the refusal. Process reading is the largest part of the diff (about 250 lines, macOS and Linux, plus a Windows stub); a simpler signal could replace it later, for example recording the process group of each native command.

Checked with real Claude Code 2.1.325 (19 of 19): kill -9 of the CLI during plugin install and plugin uninstall; while the orphaned claude lives repair and remove (with --yes and with --dry-run) refuse and name its PID; after it exits --dry-run writes nothing, --yes completes, doctor shows no open operation and a following add and remove work. Go tests fail without the change (5 scenarios) and cover the four safety properties by mutation (process list error, no process listing, no lock, wrong binding state). Tests of the touched packages pass; lint is clean in all three modules.

Not covered here: the Linux process reading is checked only by compilation, tests and lint (no Linux run); the Linux supervisor edge, and a few DRY and comment follow-ups from the review.

When agentplugins itself is killed (SIGKILL, OOM, power loss) while a
Claude Code project command runs, nothing re-reads Claude's registry: the
binding keeps a native activation attempt without an intent, every add,
update, repair and remove refuses it, and doctor could only point to a
manual edit of state-v2.json.

`repair` and `remove` with --yes now confirm such an attempt first, under
the mutation lock:

- the process census refuses while a `claude plugin` command, or a Claude
  process bound to the same profile through CLAUDE_CONFIG_DIR, is still
  alive, because an orphaned command from the killed run can still change
  the registry (Windows jobs are kill-on-close, so none survives there);
- Claude's own state is then read once, the same read the interrupt
  settle uses: an exact install of the installed package records that
  cache ownership, a state in which every recorded object is still exact
  keeps the recorded ownership, anything else keeps the attempt;
- only the attempt and the confirmed ownership change, the binding is
  marked failed and the same command continues and finishes the job.

--dry-run performs the same checks, writes nothing and stops, since nothing
can be planned while the attempt is open. Without --yes the commands ask
for it. Doctor names both commands for this case.

The update, repair and remove commands share their option preamble, which
also brings update back under the cognitive complexity limit.
…rvives

The confirming removal now proves that no command of the interrupted run
is alive before it reads Claude's state. The unclosed-interrupt case models
that child as still running, so the removal keeps refusing the attempt.
…'s guards

A Claude Code process whose arguments and environment are both unreadable
can no longer be ruled out, so the confirmation of a killed attempt refuses
it, as the process census promises. An unrecognized client state now says
how to recover by hand instead of sending the user back to the same
command, and the listed command is shortened by runes.

Tests pin the remaining guards: a failed or missing process listing keeps
the attempt, a held mutation lock refuses with ErrActive and leaves it
untouched, and a confirmed binding is closed as failed, never active.

The native setup rule now names both exceptions to "no probe after an
uncertain effect": the read after a proven closed process tree, and the
explicit confirmation after a killed run, whose process census is a
heuristic on macOS and Linux and relies on kill-on-close jobs on Windows.
@777genius
777genius marked this pull request as ready for review November 17, 2026 07:47
@777genius
777genius merged commit 554768d into main Nov 17, 2026
52 of 58 checks passed
@strix-security

Copy link
Copy Markdown

Strix is installed on this repository, but we couldn't run this PR security review because this workspace's trial has ended. Add a card to resume code reviews here.

So far, Strix has reviewed 392 pull requests, surfaced 113 security issues (1 critical/high) and blocked 3 risky merges across this workspace.

@777genius
777genius deleted the feat/claude-project-attempt-recovery branch November 17, 2026 07:47
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant