Skip to content

Add a Claude Code plugin: shared memory, compaction recall and operation skills - #615

Closed
erha-erha wants to merge 1 commit into
cortexkit:masterfrom
erha-erha:claude-code-plugin
Closed

erha-erha wants to merge 1 commit into
cortexkit:masterfrom
erha-erha:claude-code-plugin

Conversation

@erha-erha

@erha-erha erha-erha commented Oct 4, 2026 •

Copy link
Copy Markdown

Approved issue: none yet. Opened as a draft, as CONTRIBUTING.md asks, until a design proposal for a Claude Code host is approved.

Summary

Adds packages/claude-code-plugin, a Claude Code plugin installable from this repository's .claude-plugin/marketplace.json as magic-context@cortexkit. It shares context.db with OpenCode and Pi as the claude-code harness.

  • Memory across sessions and compaction. An MCP server provides ctx_memory, ctx_note, ctx_search and ctx_expand. A SessionStart hook injects project memory and session notes on startup, resume, /clear and after compaction. ctx_search and ctx_expand read Claude Code's own transcripts, so what Claude Code compacted away stays recoverable.
  • Operation skills (ctx_skill, /magic-context:capture-skill). These record a project's verified flows in the project's .claude/skills/, where Claude Code loads them as native skills. Each flow is button/event → action → APIs → data written → state updated → runnable steps → verification, plus a per-skill setup. Referenced files are hashed so changed code is flagged.
  • Prompt trigger. A UserPromptSubmit hook adds the verified operation to the model's context when a prompt names a recorded button or intent. It reads only the skill files and takes about 50 ms.
  • Capture on the session's own model. After verified work, a Stop hook asks the running model once to save it. No separate model is configured.
  • Not provided under Claude Code: ctx_reduce, historian, dreamer and compartments. Local embeddings are not bundled, so search is lexical unless an embedding endpoint is configured. Details are in packages/claude-code-plugin/README.md.

packages/claude-code-plugin/dist/ is committed, because Claude Code installs a plugin by copying it out of the marketplace repository with no build step (.gitignore exception, linguist-generated in .gitattributes).

Shared code (additive)

  • ctx_search and ctx_expand take an optional compaction cutoff (resolveMessageOrdinalCutoff, getLastCompactedOrdinal). When it is omitted they use the last compartment end, exactly as before.
  • HarnessId gains "claude-code". The stale-build notice and the prompt-surface config lookup handle it.
  • resolveWorkspaceRenderContext and sourceNamesForMemories are exported from inject-compartments.ts so the plugin renders memories the same way. This is an export only.
  • packages/plugin/src/shared/tool-schema.ts exposes the zod schema helper used by the MCP tools.

Harness coverage (required)

For each entry select: covered / not applicable — surface does not exist there / NOT covered.

  • OpenCode 1: covered. The shared ctx_search/ctx_expand/stale-build changes keep the existing default path, and packages/plugin tests pass. The new Claude Code surfaces (ctx_skill, prompt and Stop hooks) are not applicable: they do not exist there.
  • OpenCode 2: covered, same as OpenCode 1.
  • Pi: covered. The inject-compartments.ts change is export-only, and Pi uses its own resolveWorkspaceRenderContextPi, so the twin inject-compartments-pi.ts needs no change. packages/pi-plugin tests pass. The new Claude Code surfaces are not applicable.
  • OMP: covered, same as Pi.
  • Rust module: not applicable — surface does not exist there. No Rust code changes. mc-module already accepts the claude-code harness id, and the dashboard parses it as ClaudeCode.

Testing

  • bun run typecheck, bun run build, check:tui-compiled, the historian prompt golden check and bun run dists:load-probe pass.

  • Tests:

    • packages/plugin: 6661 pass, 1 fail. clean-dist-chunks.test.ts needs rsync, which the test machine lacked; it passes 8/8 with rsync available.
    • packages/pi-plugin: 1486 pass.
    • packages/claude-code-plugin: 93 pass.
    • packages/cli: 633 pass.
    • packages/retina-local-fs: 26 pass.
  • bun run lint passes for pi-plugin, claude-code-plugin, cli and retina-local-fs. packages/plugin reports 3 import-order errors in files this PR does not touch (config/schema/magic-context.ts, historian-expand-tools.test.ts, read-session-chunk.ts, from cad8ca016); the files this PR changes are clean.

  • packages/claude-code-plugin/scripts/smoke.ts covers:

    • the build;
    • plugin and marketplace validation;
    • the MCP server over stdio;
    • the hooks;
    • /clear session switching;
    • marketplace install into an isolated config;
    • with --live, real claude -p sessions.

    The live sessions cover memory save and recall, recall after /compact, capturing a demo frontend's buttons as operation skills, a fresh session performing a recorded operation without re-reading the source, and the Stop hook updating a skill after a verified change. The offline and live runs pass.

  • Release notes: a "Claude Code (new)" section in .cortexkit/alfonso/release-notes/v0.45.0.md; node scripts/check-release-notes.mjs passes.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Adds packages/claude-code-plugin, bringing Magic Context's memory layer to Claude Code with shared memory, compaction recall, and operation skills — backed by the same context.db as OpenCode and Pi.

What the plugin provides

  • MCP server exposes ctx_memory, ctx_note, ctx_search, ctx_expand, and ctx_skill.
  • SessionStart hook injects project memory and session notes on startup, resume, /clear, and after compaction.
  • ctx_search and ctx_expand read Claude Code's transcripts, so compacted messages stay recoverable.
  • Operation skills record verified flows (button → API → data → state → steps → verification) in .claude/skills/, loaded as native skills; referenced files are hashed to flag drift.
  • UserPromptSubmit injects a matching operation when a prompt names it; the Stop hook asks the session's own model once to record verified work — no separate model is configured.
  • Not provided: ctx_reduce, historian, dreamer, compartments; local embeddings aren't bundled, so search is lexical unless an OpenAI-compatible embedding endpoint is configured.
  • dist/ is committed because Claude Code installs a plugin by copying it out of the marketplace with no build step.

Shared code changes (additive)

  • HarnessId adds "claude-code"; stale-build guidance and the prompt-surface config lookup handle it.
  • ctx_search and ctx_expand take an optional compaction cutoff, defaulting to the last compartment end as before.
  • resolveWorkspaceRenderContext and sourceNamesForMemories are now exported (export-only); tool-schema.ts re-exports the zod helper the MCP adapter uses.
  • OpenCode 1/2 and Pi keep the default path and exist unchanged; the Rust module is untouched since the new surfaces don't exist there.

Written for commit 19a7c3f. Summary will update on new commits.

Review in cubic

…ion skills

packages/claude-code-plugin is a Claude Code plugin, installable from this
repository's .claude-plugin/marketplace.json as magic-context@cortexkit. It
shares context.db with the other hosts as the claude-code harness.

- MCP server with ctx_memory, ctx_note, ctx_search, ctx_expand and ctx_skill.
  ctx_search and ctx_expand read Claude Code's transcripts, so what Claude
  Code compacted away stays recoverable.
- SessionStart hook injects project memory, session notes and the project's
  operation skills on startup, resume, /clear and after compaction.
- Operation skills record a project's verified flows (trigger -> action ->
  APIs -> data written -> state updated -> runnable steps -> verification)
  in the project's .claude/skills/, where Claude Code loads them as native
  skills. Referenced files are hashed so changed code is flagged.
- UserPromptSubmit hook: a prompt that names a recorded button or intent gets
  the verified operation in context.
- Stop hook: after verified work the session's own model is asked once to
  record it; no separate model is configured.

Shared code changes are additive: ctx_search and ctx_expand take an optional
compaction cutoff, HarnessId gains "claude-code", and two memory rendering
helpers are exported. OpenCode and Pi keep their current behaviour.

The plugin's dist/ is committed because Claude Code installs a plugin by
copying it out of the marketplace repository with no build step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cortexkit-ci

cortexkit-ci Bot commented Oct 4, 2026

Copy link
Copy Markdown

Harness coverage advisory: these conventional twins were not touched:

  • packages/plugin/src/hooks/magic-context/inject-compartments.ts → packages/pi-plugin/src/inject-compartments-pi.ts

Cover every shipped harness or explain why the surface does not exist there. See CONTRIBUTING.md. This is advisory only; no draft state is changed.

@cortexkit-ci

cortexkit-ci Bot commented Oct 4, 2026

Copy link
Copy Markdown

This PR needs a linked issue with the design-approved label before it can be reviewed or merged. Link the approved issue with Approved issue: #<issue> (or Refs #<issue>) in the description. A maintainer will apply the design-approved label on the issue, or trivial on the pull request when there is genuinely no design to agree. The issue stays open until the change ships; maintainers take care of it then.

@magic-alfonso

magic-alfonso Bot commented Oct 4, 2026

Copy link
Copy Markdown

Thank you for the time and care you put into this. The live claude -p smoke runs in particular show real effort.

I'm closing it, and I'm sorry the reason is one our process is meant to prevent. Full Claude Code support for Magic Context is already built, and it covers context management (tags, ctx_reduce, the historian and history compaction) as well as memory, notes and search. It hasn't been released yet, so there was no way for you to see it. That's exactly why CONTRIBUTING.md asks for an issue with an agreed design before code: so nobody spends this much work on something that overlaps with what's already in progress. We'll take the blame for not having said publicly that Claude Code support was coming.

Operation skills (recording verified UI flows as Claude Code skills) are an interesting idea, but they're a separate product from context management, so we wouldn't take them into this repository. If you'd like to keep developing them, a standalone plugin that uses Magic Context's memory tools would be a good fit.

If you want to contribute again, please open an issue first. I'll make sure it gets a quick answer.

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