Skip to content

fix(cli): preAction auto-sync fires on serve — the plugin's @latest MCP server silently rewrites .claude/hooks, skills, AGENTS.md in every project it starts in (#793 pin never ships via marketplace source "./") #988

Closed

Description

@admarble

Incident (2026-09-06)

A downstream project reported that a long-running npm exec sequant@latest serve process "silently re-synced the repo from 2.10.0 → 2.13.0 at 12:14, mid-test-run, and overwrote pre-tool.sh" — erasing a locally tested hook guard. Same-day inspection found the identical churn sitting uncommitted in two more local projects (pre-tool.sh +108/−17 and +228/−15, .sequant-version bumped, skills rewritten), each with a sequant@latest serve process whose cwd is that project.

Root cause — a four-link chain, every link verified in source or on disk

  1. The plugin ships sequant@latest, not the Reconsider sequant@latest pinning in generated MCP config (forces npx reinstall every release; surfaces as -32000) #793 pin. .claude-plugin/marketplace.json declares source: "./", so the plugin root is the repo root and the shipped MCP config is the repo-root .mcp.json — ["-y","sequant@latest","serve"]. scripts/prepare-marketplace.ts:153-170 stamps a pinned copy into dist/marketplace/external_plugins/sequant/.mcp.json, and its validator (:234-237) rejects @latest — but that dist copy is not what the GitHub marketplace installs. Proof: ~/.claude/plugins/cache/sequant/sequant/2.13.0/.mcp.json and 2.12.0/.mcp.json both carry sequant@latest. Reconsider sequant@latest pinning in generated MCP config (forces npx reinstall every release; surfaces as -32000) #793's fix is dead code on the primary distribution channel.
  2. Claude Code starts the plugin's MCP server with cwd = the open project, in every project. lsof -d cwd on the three running sequant@latest serve processes: three different project directories.
  3. The preAction hook fires on serve. bin/cli.ts:882-908 excludes only init/sync/update. When .claude/skills/.sequant-version < package version it calls syncCommand({ quiet: true }) → copyTemplates({ force: true, overwriteCustomizable: false }) (sync.ts:448-450) → rewrites .claude/skills/**, .claude/agents/**, .claude/hooks/**, AGENTS.md, scripts/dev/*.sh, .sequant-manifest.json, the .mcp.json pin (sync.ts:310), and the version marker — with zero output (quiet). An MCP server start, which every user reasonably assumes is side-effect-free, mutates tracked files in the working tree.
  4. The write path protects exactly one file. CUSTOMIZABLE_FILES = [".claude/memory/constitution.md"] (templates.ts:238). copyTemplates (templates.ts:618-628) checks only isCustomizableFile; the .claude/.local/ twin that the classifier treats as local-override (templates.ts:333-405) is not consulted on write, and sync.ts:374-375 explicitly overwrites non-customizable local-overrides even under a plain sync. A hook edited in place has no supported protection.

Repeat trigger: the condition is committed marker < package version. Until the marker bump is committed, every new Claude Code session in that project re-runs the silent sync. The downstream project's marker is still 2.10.0 at HEAD — the next session start will clobber the guard again.

Related history: docs/internal/plugin-updates.md:88-101 documents the auto-sync as intended behavior; #713 AC-3 decided content-only drift is warn-only because copying would clobber in-place customizations (#711) — the same reasoning applies with more force to a version bump arriving via a background server. #784 warned about stale plugin caches; this is the inverse failure — an eager plugin channel.

Design

D1 — auto-sync becomes warn-only; serve becomes side-effect-free.
The version-mismatch branch of the preAction hook stops calling syncCommand and instead surfaces the same warning path the content-drift branch already uses (checkAndWarnSkillsOutdated), naming the fix (sequant update). Mutation of the working tree happens only on explicit init / sync / update. serve additionally exposes the drift in the sequant://config resource and logs one stderr line at startup, so MCP users still learn about it. Rationale: #713 already established that the pre-flight must never clobber in-place customizations; a background process is the strongest case of that. The npm upgrade → skills auto-update convenience the hook was built for is preserved by the warning plus doctor.

D2 — fix the #793 regression at its actual source. Either (a) /release stamps the repo-root .mcp.json pin to the release version via the existing syncSequantMcpPin (the "tracks HEAD for contributors" comment is mistaken — @latest tracks npm, not HEAD, so contributors lose nothing), and prepare-marketplace's validator checks the root file; or (b) marketplace.json source points at the prepared dist directory. (a) is smaller and keeps source: "./".

D3 (decide, not prescribed) — align the write path with the classifier. copyTemplates skips any file with a .claude/.local/ twin unless --force, so the documented update-safe customization path (docs/guides/customization.md:165-210) is honored by the tree copy and not only by the preview. Independent of D1; D1 alone closes the incident.

Non-Goals

Acceptance Criteria

  • AC-1: bin/cli.ts preAction never calls syncCommand; on a version-marker mismatch it warns via the existing drift-warning helper and names sequant update; a unit test drives the hook with a stale marker and asserts no template write occurred — mutation-verified (restore the syncCommand call → exactly that test fails).
  • AC-2: sequant serve with a stale marker starts without modifying any file under .claude/, AGENTS.md, scripts/dev/, .sequant-manifest.json, or .mcp.json — integration test snapshots the tree before/after startup.
  • AC-3: serve surfaces the stale-install condition on one stderr line at startup and in a dedicated sequant://install resource that is always an object ({ installed: false } with no manifest) and carries filesModified: false; sequant://config stays the settings file verbatim (JSON or JSONC) with no server-computed fields; tests assert all three.
  • AC-4: the shipped plugin MCP config is pinned — the repo-root .mcp.json (or whichever file marketplace.json source resolves to) carries sequant@<package.json version> at release, and prepare-marketplace's validator checks that file; a test reads marketplace.json source, resolves .mcp.json from it, and asserts the pin — mutation-verified (set @latest → fails).
  • AC-5: docs/internal/plugin-updates.md and the preAction header comment describe the warn-only behavior; content-coverage gate scoped to that section.
  • AC-6: CHANGELOG entry states the behavior change plainly: "sequant no longer rewrites project files on startup; run sequant update to apply a new version."

Human decisions required

  • D2 (a) vs (b).
  • Whether to take D3 in this issue or file it separately.
  • Whether sequant run (also spawned by the MCP sequant_run tool, src/mcp/tools/run.ts) should keep any auto-behavior; recommendation: no — same rule, explicit commands only.

Context

#793 (pin decision — regressed via source: "./"), #713 / #711 / #708 (drift pre-flight and the in-place-customization rule), #784 (stale plugin cache — the mirror-image failure), #814 (constitution clobber — the overwriteCustomizable split), docs/guides/customization.md (the .claude/.local/hooks/ path the incident's guard should have used).

Activity

  1. added
    bug
    on Sep 6, 2026
  2. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    AC-3 reworded (2026-09-06, during PR #989): the original text asked for install status in sequant://config. Implementing it showed that's the wrong shape — the field only appeared when the settings file parsed as plain JSON, the file got re-serialized (formatting/key order), and a server-computed value shared a namespace with real settings. sequant://config stays the settings file verbatim; status lives in a dedicated sequant://install resource that is always an object with filesModified: false as the report-only contract. Tests cover the resource shape and config-verbatim for both JSON and JSONC.

  3. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Recurrence, post-merge / pre-release (2026-09-06 ~12:14 local): the plugin's npm exec sequant@latest serve (running since 11:11 in a downstream project) re-synced 2.10.0 → 2.13.0 mid-test-run and overwrote .claude/hooks/pre-tool.sh, erasing a guard the user had just written and tested there. npm latest is still 2.13.0, so every plugin session keeps the old preAction until 2.13.1 is published. This is the release-blocking reason to cut 2.13.1.

    Two file classes from the same sync that the fix here does not cover on an explicit sequant sync, filed separately: #990 (AGENTS.md regenerated unconditionally: 73-line pointer → 1,079-line CLAUDE.md copy) and #991 (scripts/dev/*.sh symlinks re-pointed into ~/.npm/_npx/<hash>/…, which gets evicted).

    Downstream note for the record: a customization placed in the managed pre-tool.sh will be clobbered again by the next sequant update even after 2.13.1; the update-safe home is .claude/.local/hooks/ registered via settings.local.json (docs/guides/customization.md).

  4. admarble commented on Sep 7, 2026

    @admarble
    ContributorAuthor

    Shipped: v2.13.1 (20e2a86), npm latest = 2.13.1, tag's root .mcp.json pinned to [email protected]. Downstream .mcp.json files that still say @latest now resolve to a build with the warn-only preAction, so the silent rewrite stops without any plugin-cache refresh. Remaining explicit-sync gaps tracked in #990 / #991.

  5. added a commit that references this issue on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions