Skip to content

The Claude Code MCP header helper takes its code scope from the session's project directory - #415

Merged
zlareb1 merged 2 commits into
mainfrom
fix/mcp-headers-session-scope
Nov 8, 2026
Merged

zlareb1 merged 2 commits into
mainfrom
fix/mcp-headers-session-scope

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #337

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The Claude Code plugin's X-Loom-Code-Scope header names the checkout the session works in. Before, it named no checkout for a plugin installed from a git marketplace, and the plugin's own checkout for one installed from a local clone.

Why

Claude Code starts a plugin's headersHelper in the plugin root, so checkoutScope(process.cwd()) resolved the plugin's directory, not the project's. The helper's environment carries no project directory. Claude Code does substitute ${CLAUDE_PROJECT_DIR} in a plugin entry's url, and it hands the helper that URL in CLAUDE_CODE_MCP_SERVER_URL. The entry's URL now ends in #${CLAUDE_PROJECT_DIR}, and the helper reads its project directory from the fragment. An HTTP client never sends a fragment, so the server sees /mcp?toolset=<toolset> as before.

The path is never in the headersHelper command. A command line carrying it would have the shell evaluate $(...) and backticks in a directory name, and Claude Code runs a plugin's helper before the folder is trusted.

A fragment that is not an absolute path names no checkout, so the plugin root is never used. That covers an empty one and a Claude Code that leaves ${CLAUDE_PROJECT_DIR} unsubstituted, which keeps an unknown ${VAR} as written and still connects. LOOM_CODE_REPO / code_repo still name a repository. A URL with no fragment (the Codex entry) keeps the directory the helper runs in.

Scope and risk

  • Touches the header helper, the Claude Code plugin's .mcp.json url, their tests and the Claude Code integration page. The bearer lookup and the headersHelper command are unchanged.
  • The URL Claude Code shows for the entry in /mcp now ends in the project directory.

Compatibility, rollout and rollback

  • Wire: none. The server receives the same request path and query.
  • Operator steps: none. Both plugin manifests move to 1.2.17.
  • Rollback: reverting restores the plugin-root scope. Nothing is stored.

Tests

  • node --test integrations/claude-code-plugin/tests/*.test.mjs: 606 pass. A new test gives the helper a project directory in the fragment while it runs in another checkout, and the header names the project's scope; this test fails on main. An empty or unsubstituted fragment gives no header, and no fragment keeps the working directory. projectDir returns a path holding #, %, $(id), backticks, quotes and an apostrophe as it is.
  • Claude Code 2.1.319, claude -p --plugin-dir with a probe plugin whose entry has this url and a local listener: the helper ran in the plugin root and read the project path from CLAUDE_CODE_MCP_SERVER_URL. The path held #50% $(id) `x` "q" it's and came through unchanged. Every request the listener logged was /mcp?toolset=coding, with no fragment and no path. ${CLAUDE_PROJECT_DIR:-} is not substituted (it reads as an environment variable), which is why the bare form is used. An undefined ${VAR} in the URL stays literal and the entry still connects.
  • claude plugin validate on the plugin and the marketplace; agent_plugin_sync; pytest on the codex-plugin, install, docs-link and public-copy tests: 249 pass.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. How Claude Code substitutes the variable and what reaches the server were checked against a real session, as above.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 2 commits November 8, 2026 09:35
…on's project directory

Claude Code starts a plugin's headersHelper in the plugin root, so the helper's
working directory named no checkout, or the wrong one when the plugin root sits
inside a checkout. The plugin's .mcp.json now passes ${CLAUDE_PROJECT_DIR}, which
Claude Code substitutes in headersHelper, and the helper resolves the scope from
that argument. An empty or unsubstituted argument names no checkout. The Codex
entry passes none and keeps the directory it runs in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…fragment, which no shell reads

Inside the headersHelper command the shell ran $(...) and backticks in a
substituted project path. The entry's url now ends in #${CLAUDE_PROJECT_DIR};
Claude Code hands the helper that URL in CLAUDE_CODE_MCP_SERVER_URL and sends no
fragment, and the headersHelper command is back to what it was.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 40b043b into main Nov 8, 2026
40 of 42 checks passed
@zlareb1
zlareb1 deleted the fix/mcp-headers-session-scope branch November 8, 2026 10:17
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
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.

The Claude Code MCP header helper takes its code scope from the plugin root, not the session's checkout

1 participant