You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(native): let Claude Code load project plugins in a first session and in worktree-only installs (#5176) - #5184
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:
The committed relative .claude/settings.json declaration is unchanged.
After a project-scope install that declares Claude native plugins, new owner native_plugins/claude_marketplaces.py upserts ${CLAUDE_CONFIG_DIR:-~/.claude}/plugins/known_marketplaces.json with {"<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.
The write is merge-only and atomic: one entry changes, and no other entry is touched. It is idempotent: an entry already naming this root, APM's or Claude's own, is left byte for byte. An unreadable registry is left alone, with a warning.
APM records each entry it wrote in $APM_HOME/claude-known-marketplaces.json. When a reconcile leaves no Claude native plugin in the project (apm uninstall, or the last plugin removed), APM removes only the entry it recorded, and only while that entry still names the same root.
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.
Lifecycle I5 write sets (W3d): exactly two new home paths are admitted for a project command, with no wildcard. Each module's own allowed-home tuple gets them: tests/lifecycle/rows.py_PROJECT_HOME_ALLOWED, tests/lifecycle/security/test_gate_removal.py_PROJECT_HOME_ALLOWED, tests/lifecycle/scenarios/_kit.pyPROJECT_HOME_ALLOWED and tests/lifecycle/journeys/test_journeys.py_HOME_ALLOWED. tests/lifecycle/security/test_integrity.py reuses the rows.py tuple.
.claude/plugins/known_marketplaces.json: Claude's registry. The lifecycle world sets CLAUDE_CONFIG_DIR=$HOME/.claude.
.apm/claude-known-marketplaces.json: APM's ledger of the entry it wrote.
Lane: once #5201 lands, scripts/real_harness/expected.json flips claude-normal-project, claude-worktree-project, claude-headless-project and claude-headless-wt-branch-project to LOADS. claude-headless-wt-after-main-project stays PARTIAL (the known gap). That file is not on main yet, so the flip follows in this PR after #5201 merges.
Trust scope: APM registers the project marketplace only for a folder Claude already trusts. 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.
Issue and approved scope
Issue: Fixes#5176 for folders Claude already trusts. 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 ruling PD-47).
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; the fix shape follows the real-harness runs (shape A).
Does this PR complete the issue, or what remains? It completes #5176. For #5180, outcome 2 remains a documented gap; the lane flip follows #5201.
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally
All existing tests pass (targeted; CI runs the full suite)
Added tests for new functionality (if applicable)
Lifecycle cells in tests/integration/test_claude_known_marketplace_lifecycle.py (real CLI, isolated HOME). They were red on main and are green now:
test_project_install_lists_the_marketplace_for_claude_with_its_absolute_path[home|CLAUDE_CONFIG_DIR]: a fresh install writes the absolute entry under ~/.claude or CLAUDE_CONFIG_DIR (and only there); a re-install changes no byte.
test_install_and_uninstall_touch_only_apms_entry: another marketplace entry survives install and uninstall unchanged; uninstall removes APM's entry and the plugin root.
test_a_checkout_install_lists_its_own_plugin_root[main|worktree]: an install in a worktree alone lists that worktree's own absolute root and prints the worktree warning once; a main-checkout install prints none.
Validation (one targeted run at a time):
APM_BINARY_PATH=$(uv run which apm) uv run --extra dev pytest tests/integration/test_claude_known_marketplace_lifecycle.py tests/lifecycle/scenarios/test_ownership_siblings.py -n 0: 100 passed after merging main.
Neighbours (every module using reconcile_native_plugins, extraKnownMarketplaces or a lifecycle allowed-home set): 994 passed. The 12 tests/lifecycle/security/test_integrity.py failures fail the same way on this branch's base with every change stashed (a marketplace source_digest golden), so they are not from this change.
Lint mirror, all clean: uvx [email protected] check and format --check; scripts/lint_architecture_boundaries.py --root .; scripts/check_complexity_ratchet.py --base-ref origin/main; python -m tests.quality.taxonomy --changed; scripts/check_test_assertions.py; scripts/check_exact_test_duplicates.py; pylint R0801; scripts/lint-auth-signals.sh; python -m tests.lifecycle.generator --check; tests/quality/test_lifecycle_bug_ledger.py (new row bugs/5176.json).
Owner map: native_plugins/claude_marketplaces.py is added to the claude-native-plugin-registration selectors.
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 -- 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; if the Spec Mode B gate asks, a waiver line will name that.
…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]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Inherited CLAUDE_CONFIG_DIR can make tests inspect the wrong registry and risk modifying a real profile, while inherited worktree bindings and preservation of pre-existing marketplace entries without APM ownership receipts remain untested.
This PR adds regression tests for Claude Code’s first-session and worktree plugin-loading issues (#5176 and #5180). The current diff establishes expected registry behavior; the production fix remains pending.
Changes:
Adds five lifecycle cases covering absolute marketplace paths, CLAUDE_CONFIG_DIR, reinstall idempotence, uninstall isolation, and checkout-specific mappings.
Adds a changelog fragment describing the intended loading fix.
Daniel Meppiel (danielmeppiel)
changed the title
fix(native): let Claude Code load project plugins in a first session and in worktrees (#5176, #5180)
fix(native): let Claude Code load project plugins in a first session and in worktree-only installs (#5176)
Nov 23, 2026
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]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved registry collisions and ownership-tracking flaws can overwrite or delete entries APM does not own, while improperly isolated integration tests can modify a developer’s real Claude configuration.
…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]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Unresolved ownership-scoping and concurrency flaws can delete unowned Claude registry entries or lose marketplace registrations and the receipts needed for cleanup.
Concurrent installs sharing HOME can both pass this check, then replace the registry with stale snapshots and lose another project's marketplace. The shared receipt has the same problem in _record() (lines 143–146): publishing an earlier ownership snapshot can erase another install's receipt, preventing later cleanup. Serialize registration and removal across APM processes from the ownership read through registry and receipt publication; an APM-only lock still cannot protect against Claude Code's independent writes.
Ownership is checked only by marketplace name and checkout root, but the receipt does not identify the registry APM wrote. Install with CLAUDE_CONFIG_DIR=A, then uninstall with CLAUDE_CONFIG_DIR=B where Claude already has its own entry for the same checkout: this deletes B's unowned entry and discards A's receipt, leaving A's entry behind. Record the registry path alongside each owned entry and only remove entries from the registry covered by that receipt; preserve independent receipts when switching profiles.
Distinguish null registry values from missing keys
An existing JSON null value is treated as an absent entry because dict.get() returns None in both cases. For a registry containing this marketplace name with a null value, install overwrites the existing value and claims ownership instead of preserving it and warning, contrary to the add-only behavior. Check whether the key exists, independently of its value.
Recover when ownership recording fails after registration
If _record() fails after the registry entry is published, for example because APM_HOME is unwritable, the entry remains without ownership evidence. Reinstalling after fixing permissions preserves the existing entry without recording it, so uninstall cannot remove it. Make both writes recoverable through ownership journaling or safe rollback of the newly inserted entry, without claiming pre-existing Claude entries.
… 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]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Ownership receipts can lose track of entries across configuration directories or incorrectly claim concurrently created Claude entries, causing uninstall to leave APM entries behind or delete entries APM never created.
…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]>
Superseded by a new pull request from branch fix-5176-claude-trusted-marketplace (same scope, plus registering only for folders Claude already trusts). Review continues there.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Unresolved ownership-tracking issues can cause uninstall to delete Claude-created entries after a no-op merge or leave APM-created entries behind when installations across profiles overwrite receipts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
At project scope
apm installdeclares a native plugin in.claude/settings.jsonunder the relative marketplace path./.agents/plugins. Claude Code has two problems with that:claude -p, claude-code-action, a fresh clone) it loads the plugin's MCP server but not its skills or hooks. It fully loads only marketplaces listed in its user-levelplugins/known_marketplaces.json, which it fills in itself only after a session.Fix (real-harness shape A):
.claude/settings.jsondeclaration is unchanged.native_plugins/claude_marketplaces.pyupserts${CLAUDE_CONFIG_DIR:-~/.claude}/plugins/known_marketplaces.jsonwith{"<apm-p-name>": {"source": {"source": "directory", "path": "<abs checkout>/.agents/plugins"}, "installLocation": "<same>", "lastUpdated": "<ISO8601>Z"}}. It is called once fromclaude_plugins/registrar.py::reconcile_native_plugins, after the settings commit.$APM_HOME/claude-known-marketplaces.json. When a reconcile leaves no Claude native plugin in the project (apm uninstall, or the last plugin removed), APM removes only the entry it recorded, and only while that entry still names the same root.[!] 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.consumer/install-plugins.md): a paragraph on the registry entry and Claude Code's folder-trust gate. The worktree known-gap row now 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" gap row is removed because this fixes it.Lifecycle I5 write sets (W3d): exactly two new home paths are admitted for a project command, with no wildcard. Each module's own allowed-home tuple gets them:
tests/lifecycle/rows.py_PROJECT_HOME_ALLOWED,tests/lifecycle/security/test_gate_removal.py_PROJECT_HOME_ALLOWED,tests/lifecycle/scenarios/_kit.pyPROJECT_HOME_ALLOWEDandtests/lifecycle/journeys/test_journeys.py_HOME_ALLOWED.tests/lifecycle/security/test_integrity.pyreuses the rows.py tuple..claude/plugins/known_marketplaces.json: Claude's registry. The lifecycle world setsCLAUDE_CONFIG_DIR=$HOME/.claude..apm/claude-known-marketplaces.json: APM's ledger of the entry it wrote.Lane: once #5201 lands,
scripts/real_harness/expected.jsonflips claude-normal-project, claude-worktree-project, claude-headless-project and claude-headless-wt-branch-project to LOADS. claude-headless-wt-after-main-project stays PARTIAL (the known gap). That file is not on main yet, so the flip follows in this PR after #5201 merges.Trust scope: APM registers the project marketplace only for a folder Claude already trusts. 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.
Issue and approved scope
Issue: Fixes #5176 for folders Claude already trusts. 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 ruling PD-47).
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; the fix shape follows the real-harness runs (shape A).
Does this PR complete the issue, or what remains? It completes #5176. For #5180, outcome 2 remains a documented gap; the lane flip follows #5201.
Type of change
Testing
Lifecycle cells in
tests/integration/test_claude_known_marketplace_lifecycle.py(real CLI, isolated HOME). They were red on main and are green now:test_project_install_lists_the_marketplace_for_claude_with_its_absolute_path[home|CLAUDE_CONFIG_DIR]: a fresh install writes the absolute entry under~/.claudeorCLAUDE_CONFIG_DIR(and only there); a re-install changes no byte.test_install_and_uninstall_touch_only_apms_entry: another marketplace entry survives install and uninstall unchanged; uninstall removes APM's entry and the plugin root.test_a_checkout_install_lists_its_own_plugin_root[main|worktree]: an install in a worktree alone lists that worktree's own absolute root and prints the worktree warning once; a main-checkout install prints none.Validation (one targeted run at a time):
APM_BINARY_PATH=$(uv run which apm) uv run --extra dev pytest tests/integration/test_claude_known_marketplace_lifecycle.py tests/lifecycle/scenarios/test_ownership_siblings.py -n 0: 100 passed after merging main.tests/lifecycle/security/test_integrity.pyfailures fail the same way on this branch's base with every change stashed (a marketplacesource_digestgolden), so they are not from this change.uvx [email protected] checkandformat --check;scripts/lint_architecture_boundaries.py --root .;scripts/check_complexity_ratchet.py --base-ref origin/main;python -m tests.quality.taxonomy --changed;scripts/check_test_assertions.py;scripts/check_exact_test_duplicates.py; pylint R0801;scripts/lint-auth-signals.sh;python -m tests.lifecycle.generator --check;tests/quality/test_lifecycle_bug_ledger.py(new rowbugs/5176.json).native_plugins/claude_marketplaces.pyis added to the claude-native-plugin-registration selectors.Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedThe 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; if the Spec Mode B gate asks, a waiver line will name that.