Skip to content

fix(install): list a trusted project's marketplace in Claude Code's user registry - #5230

Merged
Daniel Meppiel (danielmeppiel) merged 12 commits into
mainfrom
fix-5176-claude-trusted-marketplace
Nov 24, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 12 commits into
mainfrom
fix-5176-claude-trusted-marketplace

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

At project scope apm install declares a native plugin in .claude/settings.json under the relative marketplace path ./.agents/plugins. Claude Code has two problems with that:

Fix:

  • The committed relative .claude/settings.json declaration is unchanged.
  • After a project-scope install that declares Claude native plugins, the new owner native_plugins/claude_marketplaces.py lists the project marketplace in ${CLAUDE_CONFIG_DIR:-~/.claude}/plugins/known_marketplaces.json as {"<apm-p-name>": {"source": {"source": "directory", "path": "<abs checkout>/.agents/plugins"}, "installLocation": "<same>", "lastUpdated": "<ISO8601>Z"}}. It is called once from claude_plugins/registrar.py::reconcile_native_plugins, after the settings commit, and never fails the command: anything it cannot do safely is left unchanged and named in a warning.
  • Trust scope: APM registers the marketplace only for a folder Claude Code already trusts, that is when ${CLAUDE_CONFIG_DIR:-~}/.claude.json has projects["<abs checkout>"].hasTrustDialogAccepted set to true. The file is read only, never followed through a link, and matched only on the exact absolute path. A missing, unreadable, linked or unrecognised file counts as untrusted: APM writes nothing and prints "open the folder in Claude and accept the trust prompt, then re-run apm install". In CI or claude-code-action, an untrusted checkout does not auto-load project plugins. This is by design; use user scope or Claude's own trust setting.
  • Ownership: APM only adds an entry. An entry already under the name (this checkout's, another clone's or worktree's, or Claude's own) is kept byte for byte, with a warning when it names another root. Only apm-p-<8 hex> names are registered. APM records each entry it wrote in $APM_HOME/claude-known-marketplaces.json (before publishing it), and when a reconcile leaves no Claude native plugin in the project it removes only an entry its record owns for this root and registry.
  • Safety: a linked component on the registry path (as for MCP user configs), a registry that is not a JSON object (malformed, non-object, JSONC) or an unreadable record means no write and a warning. The file is re-read right before the atomic replace; a change is merged once on retry, otherwise left as it is. Values keep their characters; warnings print names and paths as printable ASCII. --dry-run writes nothing.
  • An install in a linked git worktree prints [!] This checkout is a git worktree: Claude Code may load the main checkout's copy of its native plugins (anthropics/claude-code#111812). See https://microsoft.github.io/apm/consumer/install-plugins/#known-gaps.
  • Docs (consumer/install-plugins.md): the registry entry, the trust scope and the keep-and-warn cases. The worktree known-gap row cites Project plugin marketplace with a relative directory path resolves against the main checkout in a git worktree anthropics/claude-code#111812, and the "newly declared plugin loads from the second session" row is removed for trusted folders.

Lifecycle I5 write sets: exactly two new home paths are admitted for a project command, with no wildcard: .claude/plugins/known_marketplaces.json (Claude's registry; the lifecycle world sets CLAUDE_CONFIG_DIR=$HOME/.claude) and .apm/claude-known-marketplaces.json (APM's record). They are added to each module's own allowed-home tuple (tests/lifecycle/rows.py, security/test_gate_removal.py, scenarios/_kit.py, journeys/test_journeys.py).

The real-harness lane flip (scripts/real_harness/expected.json) is not part of this PR; it follows #5201.

Issue and approved scope

Issue: Fixes #5176. Refs #5180 (outcome 1, a worktree-only install, is fixed; outcome 2, a worktree loading the main checkout's copy, stays open as a known gap, anthropics/claude-code#111812, with an install-time warning per the maintainer ruling).

Human scope-approval comment: #5176 is status/accepted with v0.39.0 scope from the maintainer lead; #5180 is assigned with #5176 as one design. Supersedes #5184.

Does this PR complete the issue, or what remains? It completes #5176 for folders Claude Code trusts. For #5180, outcome 2 remains a documented gap.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Lifecycle cells, real CLI with an isolated HOME (tests/integration/test_claude_known_marketplace_lifecycle.py):

  • fresh install lists the absolute entry (home and CLAUDE_CONFIG_DIR), and re-install changes no byte;
  • install and uninstall touch only APM's entry;
  • a worktree lists its own root and warns once, a main checkout does not;
  • dry-run writes nothing;
  • a same-name entry for another directory and a second clone are kept byte for byte with a warning;
  • a relative CLAUDE_CONFIG_DIR warns and the install succeeds;
  • a linked ~/.claude, plugins/ or registry is never written;
  • a malformed, non-object or JSONC registry is left unchanged;
  • uninstall removes only an entry the record owns for this root (other root, missing record);
  • an unreadable record is never overwritten;
  • a unicode and space root is recorded as is;
  • trust scope cells (in the fold push): an untrusted root writes nothing and prints the hint; a trusted root registers; a malformed, linked or unrecognised .claude.json is untrusted; CLAUDE_CONFIG_DIR is honored; a respelled root matches only the exact key.

Unit cells: tests/unit/test_claude_marketplaces_registry.py. Component cell: tests/unit/integration/test_claude_marketplace_registry_update.py (one-retry merge, else unchanged).

Validation evidence (commands and results) follows with the fold push.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

The committed project declaration (req-na-003, req-na-007) is unchanged; the user-registry entry is a per-machine harness side effect outside the committed manifest and lock.

apm-spec-waiver: per-machine harness registry side effect outside the committed manifest and lock; req-na-003 and req-na-007 declarations unchanged

Follow-up: #5257 (wider derived names with migration; APM_HOME created as 0700), #5258 (atomic registry publish; convergence after a failed uninstall cleanup), #5288 (regular-file check for the marketplace registry and receipt reads).

…n loading

#5176: a project install must list its marketplace in Claude Code's
known_marketplaces.json with the absolute path (HOME and CLAUDE_CONFIG_DIR),
idempotently, touching no other entry, and uninstall removes only APM's.
#5180: after installs in two checkouts of one repository, each checkout's
marketplace must map to its own absolute plugin root.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Claude Code fully loads a native plugin's skills and hooks in a first session
only from a marketplace its user-level plugins/known_marketplaces.json lists.
A project-scope install with the Claude target now upserts that entry with
the checkout's absolute plugin root (CLAUDE_CONFIG_DIR honoured), keeping the
committed relative declaration. The write is merge-only, atomic and
idempotent; an APM ledger under APM_HOME records the entry so uninstall
removes only APM's. An install in a git worktree warns that Claude Code may
load the main checkout's copy (anthropics/claude-code#111812). The lifecycle
write sets admit exactly the two new home paths.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…ckout

Review folds for the user-level registry write:
- add an entry only when none exists under the name; keep every existing
  entry (another clone or worktree, or Claude's own) byte for byte, warning
  when it names another root; accept only ^apm-p-[0-9a-f]{8}$ names;
- refuse a linked registry location with user_config_crosses_link, as the
  MCP user configs do;
- re-read before writing and redo the merge once if the file changed;
- treat an unreadable registry or receipt as a warning, never as empty;
- warn and continue on any registry error after the committed declaration,
  including a relative CLAUDE_CONFIG_DIR; keep non-ASCII values and print
  ASCII-safe warnings.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
… its registry

The receipt now records the root and the absolute registry path. It is written
before the registry entry and undone if publishing fails. Uninstall removes an
entry only from the registry the receipt names. Lifecycle cells no longer
inherit CLAUDE_CONFIG_DIR.

apm-spec-waiver: user-level Claude registry bookkeeping is not governed by an OpenAPM requirement

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…safety rules (#5176 review)

Real-CLI cells over the registry owner: a same-name entry for another
directory and a second clone are kept byte for byte with a warning; a
relative CLAUDE_CONFIG_DIR warns and the install succeeds; a linked ~/.claude,
plugins/ or registry is never written; a malformed, non-object or JSONC
registry is left unchanged; uninstall removes only an entry the receipt owns
for this root; an unreadable receipt is never overwritten; a unicode and
space root is recorded as is. A component cell covers the one-retry merge.
Docs name the keep-and-warn cases.

apm-spec-waiver: per-machine harness registry side effect outside the committed manifest and lock; req-na-003 and req-na-007 declarations unchanged

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical trust-validation and ownership-tracking defects allow home writes from untrusted checkouts, deletion of Claude-owned entries, and loss of cleanup records during concurrent or multi-profile installs.

5 open issues
What changed in this PR

This PR addresses Claude Code's first-session native-plugin loading gap (#5176) by registering project marketplaces in per-machine user state while preserving portable, relative project settings. It also targets worktree-only installs from #5180; loading the main checkout's copy remains a documented limitation.

Changes:

  • Adds marketplace registration and ownership-based cleanup after native-plugin reconciliation.
  • Adds a worktree warning and documents registry behavior and remaining limitations.
  • Adds lifecycle and component coverage, with two explicit home-path allowances.
File Description
tests/​unit/​test_claude_marketplaces_registry.py Tests registry safety, ownership, profiles and path handling.
tests/​unit/​integration/​test_claude_marketplace_registry_update.py Tests bounded retries when registry contents change.
tests/​lifecycle/​security/​test_gate_removal.py Allows the two new home-state paths.
tests/​lifecycle/​scenarios/​_kit.py Extends scenario home-write allowances.
tests/​lifecycle/​rows.py Extends lifecycle home-write allowances.
tests/​lifecycle/​journeys/​test_journeys.py Extends journey home-write allowances.
tests/​integration/​test_claude_known_marketplace_lifecycle.py Exercises real-CLI registration, cleanup and safety cases.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​5176.json Links the loading defect to regression tests.
src/​apm_cli/​native_plugins/​claude_marketplaces.py Implements registry updates, ownership receipts and warnings.
src/​apm_cli/​claude_plugins/​registrar.py Calls registry synchronization after settings commit.
docs/​src/​content/​docs/​consumer/​install-plugins.md Explains registration and updates known gaps.
changelog.d/​5184.fixed.md Announces first-session loading and worktree warnings.
.apm/​architecture/​owners/​marketplace-plugins.json Adds the registry module to the existing owner scope.

Review effort: Balanced

…Code trusts (#5176)

APM lists the project marketplace in Claude Code's user registry only when
Claude Code's user config ($CLAUDE_CONFIG_DIR/.claude.json, else
~/.claude.json) records hasTrustDialogAccepted true for the checkout's exact
absolute path. The file is read only, never through a link; a missing,
unreadable, linked or unrecognised file counts as untrusted, and APM then
writes nothing and prints the trust hint from the remediation catalog. So no
claude command (a session, or claude mcp list) runs a plugin's code in a
folder Claude Code does not trust. Uninstall's record logic is unchanged.

Docs and the apm-usage guide state the trust scope; journey J05 goldens show
the hint; the changelog fragment moves to #5230.

apm-spec-waiver: per-machine harness registry side effect outside the committed manifest and lock; req-na-003 and req-na-007 declarations unchanged

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved concurrency and ownership-tracking flaws can overwrite Claude updates, delete entries APM did not create, and leave APM-created entries behind when multiple profiles share receipts.

5 open issues
1 resolved since last review

Review effort: Balanced

…ude profile, record only published entries (#5176 review)

- _merge stages the candidate first, then compares the registry right before
  the atomic replace (a change during staging is retried, never overwritten)
  and reports whether APM published its change.
- The receipt keeps one record per (registry, marketplace) and is updated
  per entry, so installs under two Claude profiles each keep their record and
  a rollback drops only its own record.
- When Claude adds the same entry while APM merges, APM published nothing and
  keeps no record, so uninstall leaves Claude's entry.
- A skipped registry update asks the user to resolve the named issue and
  re-run, instead of promising a second-session load; docs match.

apm-spec-waiver: per-machine harness registry side effect outside the committed manifest and lock; req-na-003 and req-na-007 declarations unchanged

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical directory-swap race can redirect writes to an external registry, while cleanup failures can strand owned entries and merge-time root conflicts can go unreported.

1 open issue
3 previously missed issues

In code that hasn't changed since last review

High severity Symlink swap can redirect registry publication

src/​apm_cli/​native_plugins/​claude_marketplaces.py:146

The no-link check runs only in _registry(), before the receipt update and staging. If plugins/ becomes a symlink before the temporary file is created, an external registry with identical bytes passes the final comparison and receives APM's write. Pin reads, staging and publication to validated directory handles that do not follow links, and add a regression for a directory swap during staging.

Medium severity Failed cleanup strands receipt-owned registry entry

src/​apm_cli/​claude_plugins/​registrar.py:451

If registry cleanup fails while uninstalling the last native plugin, uninstall still drops the native lock state and leaves the ownership receipt behind. After the registry is repaired, a subsequent install returns at registrar.py:356-367 because no native records remain, so it never retries cleanup and the entry stays stranded. Reconcile receipt-owned entries for this root even without native lock records, and test failed cleanup followed by repair and reinstall.

Medium severity Merge-time root conflict skips the warning

src/​apm_cli/​native_plugins/​claude_marketplaces.py:269

If Claude adds this marketplace name for another root between the initial read and _merge() (or before a retry), this return keeps the entry but skips the conflict warning at lines 257-264. Install then succeeds silently even though Claude may load another checkout's plugins. Please apply the same root-conflict check to entries found during the merge as well as during the initial read.

5 resolved since last review

Review effort: Balanced

…name a conflict found mid-merge (#5176 review)

- _merge checks the registry (and receipt) path for linked components again
  after staging, right before the atomic replace, so a directory linked
  meanwhile is never published to; the staged file is removed.
- An entry another checkout's root that appears between APM's read and its
  merge is now named with the same warning as one found up front.

apm-spec-waiver: per-machine harness registry side effect outside the committed manifest and lock; req-na-003 and req-na-007 declarations unchanged

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The marketplace merge duplicates the canonical atomic writer’s staging, permissions, cleanup, and publication logic, creating implementations that can diverge instead of extending and reusing the registered owner.

1 open issue

Review effort: Balanced

…eckout (#5176 review)

- APM lists a project marketplace in Claude Code's registry only when its
  name is the one derived from this checkout's own project identity; a name
  a committed lock or catalog records for another identity writes no entry,
  and Claude Code's own first session lists it instead.
- Claude Code's trust record also matches the checkout's forward-slash
  spelling (Windows).
- APM's receipt is written with mode 0600.
- .claude.json is opened non-blocking without following links and judged on
  the opened file (fstat), so a FIFO or device is untrusted and never blocks.
- Docstrings say other entries keep their content (the file is
  re-serialized), not their bytes.

apm-spec-waiver: per-machine harness registry side effect outside the committed manifest and lock; req-na-003 and req-na-007 declarations unchanged

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because omitted findings include a critical install/uninstall hang, cleanup that cannot be retried on reinstall, and silent marketplace conflicts.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 3135d5c into main Nov 24, 2026
77 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the fix-5176-claude-trusted-marketplace branch November 24, 2026 05:47
Sami (Yshuro) pushed a commit to Yshuro/apm that referenced this pull request Nov 24, 2026
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Sami (Yshuro) pushed a commit to Yshuro/apm that referenced this pull request Nov 24, 2026
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.

[BUG] Project-scope native plugin: Claude Code's first session loads the plugin's MCP server but not its skills or hooks

2 participants