Skip to content

feat(integration): add Claude Code plugin - #1237

Merged
Teingi merged 4 commits into
oceanbase:masterfrom
XnLemon:feat/claude-code-integration
Aug 17, 2026
Merged

Teingi merged 4 commits into
oceanbase:masterfrom
XnLemon:feat/claude-code-integration

Conversation

@XnLemon

@XnLemon XnLemon commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Closes #1233.

Rationale for this change

PowerContext already provides automatic project-scoped recall for Codex, but Claude Code users cannot receive relevant context before each prompt through an official integration.

This change adds a native Claude Code plugin that reuses the existing HTTP and MCP interfaces. Runtime selection, ranking, citation, rendering, Memory, and Handoff logic remain owned by the PowerContext Server.

What changes are included in this PR?

  • Add a repository-level Claude Code Marketplace and a self-contained PowerContext plugin.
  • Add a native UserPromptSubmit Hook that:
    • derives the same project scope as the Codex plugin;
    • calls /v1/context/prepare at most once;
    • validates and injects Prepared Context through additionalContext;
    • captures the current prompt as ordinary Content Source evidence;
    • keeps recall and capture independent and fail-open.
  • Add Streamable HTTP MCP configuration for explicit Memory and Handoff workflows.
  • Add an environment-backed authorization header helper.
  • Add a bundled Skill describing explicit Memory maintenance and the inspected Handoff lifecycle.
  • Add powercontext setup claude-code and powercontext doctor claude-code.
  • Report configuration changes, storage, permissions, and rollback commands before setup mutates the Claude Code environment.
  • Roll back only Marketplace and plugin objects created by the failing setup invocation.
  • Add contract, Hook, CLI, cross-agent, authenticated transport, Memory, and Handoff tests.
  • Add English and Chinese setup, configuration reference, and troubleshooting documentation.

The v1 integration does not install a Stop Hook, read Claude Code transcripts, capture assistant responses, or mark ordinary prompts as task-outcome.

Are there any user-facing changes?

Yes.

Users can install and diagnose the Claude Code integration with:

powercontext setup claude-code
powercontext doctor claude-code

After setup, Claude Code automatically recalls project context and captures user prompts as ordinary Source evidence by default. Prompt capture can be disabled with --no-capture-prompts or POWERCONTEXT_CLAUDE_CAPTURE_PROMPTS=false.

Claude Code and Codex share Memory when they resolve the same Git project scope. Authentication is configured through POWERCONTEXT_CLAUDE_AUTHORIZATION.

There are no breaking HTTP API, MCP API, or persisted-format changes.

How was this change tested?

Evidence

Test the current branch:

uv tool install --force \
  "powercontext[cli,server] @ git+https://github.com/XnLemon/powercontext.git@feat/claude-code-integration"

powercontext setup claude-code \
  --source XnLemon/powercontext \
  --ref feat/claude-code-integration

Then start the Server:

powercontext server run

In another terminal, run:

powercontext doctor
powercontext doctor claude-code
claude

In Claude Code, check /hooks and /mcp to confirm that the PowerContext Hook and MCP Server are active.

8f593e4187ef4f72dfc688f6a57362ab_720 7e52683891538d5e635dfce774d16973_720 44c8bb21fcb23994a0fbc7911afd2bd9_720 d87118699909fc2994a157dcbf761c06_720 d88fad7eaf2bf76c3b7d5470f1d314f0

Automated validation:

python -m pytest \
  tests/claude_code_plugin \
  tests/codex_plugin \
  tests/test_system_cli.py \
  tests/e2e/test_claude_code_service_chain.py \
  tests/e2e/test_codex_service_chain.py \
  tests/e2e/test_mcp_transport.py

Result: 109 passed.

Additional validation:

prek run -a
ty check
zensical build -s
claude plugin validate --strict .
claude plugin validate --strict integrations/claude-code/plugins/powercontext

All commands passed.

Manual validation covered:

  • installing the CLI and plugin from the feature branch;
  • running setup and both doctor commands;
  • starting the PowerContext Server and Claude Code;
  • confirming the PowerContext entries in /hooks and /mcp;
  • explicitly saving project Memory in one Claude Code session;
  • automatically recalling that Memory in a new session.

A full python -m pytest --doctest-modules run reported 508 passed, 7 skipped, 2 failed. One failure is an unchanged LoCoMo fixture hash mismatch. The other was a provider-readiness timeout that passed when rerun independently. Neither failure touches this integration.

AI usage statement

OpenAI Codex 5.6 Sol xhigh was used for repository analysis, implementation support, test and documentation authoring, and validation. The resulting changes were reviewed, and the CLI integration was manually validated end to end by the author.

中文

该 PR 关闭哪个 Issue 或 RFC?

Closes #1233。

修改原因

PowerContext 已经为 Codex 提供项目级自动上下文召回,但 Claude Code 用户还无法通过官方集成,在处理每条 prompt 前获得相关上下文。

该修改增加原生 Claude Code 插件,并复用现有 HTTP 和 MCP 接口。选择、排序、引用、渲染、Memory 和 Handoff 逻辑仍由 PowerContext Server 负责。

该 PR 包含哪些修改?

  • 增加仓库级 Claude Code Marketplace 和自包含的 PowerContext 插件。
  • 增加原生 UserPromptSubmit Hook:
    • 使用与 Codex 插件相同的项目 scope;
    • 每条 prompt 最多调用一次 /v1/context/prepare;
    • 校验 Prepared Context,并通过 additionalContext 注入;
    • 将当前 prompt 采集为普通 Content Source 证据;
    • 让召回与采集独立执行并 fail open。
  • 增加 Streamable HTTP MCP 配置,用于显式 Memory 和 Handoff 工作流。
  • 增加从环境变量读取认证信息的 header helper。
  • 增加说明显式 Memory 维护和可检查 Handoff 生命周期的 Skill。
  • 增加 powercontext setup claude-code 和 powercontext doctor claude-code。
  • setup 修改 Claude Code 环境前,会报告配置变更、存储位置、所需权限和回滚命令。
  • setup 失败时,只回滚本次调用创建的 Marketplace 和插件对象。
  • 增加 contract、Hook、CLI、跨 Agent、认证传输、Memory 和 Handoff 测试。
  • 增加中英文安装、配置参考和故障排查文档。

v1 不安装 Stop Hook,不读取 Claude Code transcript,不采集助手回复,也不把普通 prompt 标记为 task-outcome。

是否存在用户可见修改?

是。

用户可以通过以下命令安装和诊断 Claude Code 集成:

powercontext setup claude-code
powercontext doctor claude-code

setup 完成后,Claude Code 默认自动召回项目上下文,并把用户 prompt 采集为普通 Source 证据。可以通过 --no-capture-prompts 或 POWERCONTEXT_CLAUDE_CAPTURE_PROMPTS=false 禁用采集。

Claude Code 和 Codex 解析到同一个 Git 项目 scope 时,会共享 Memory。认证通过 POWERCONTEXT_CLAUDE_AUTHORIZATION 配置。

该修改不包含破坏性的 HTTP API、MCP API 或持久化格式变更。

如何测试该修改?

证据

使用当前分支测试:

uv tool install --force \
  "powercontext[cli,server] @ git+https://github.com/XnLemon/powercontext.git@feat/claude-code-integration"

powercontext setup claude-code \
  --source XnLemon/powercontext \
  --ref feat/claude-code-integration

然后启动并检查:

powercontext server run

另一个终端:

powercontext doctor
powercontext doctor claude-code
claude

在 Claude Code 中检查 /hooks 和 /mcp。

8f593e4187ef4f72dfc688f6a57362ab_720 7e52683891538d5e635dfce774d16973_720 44c8bb21fcb23994a0fbc7911afd2bd9_720 d87118699909fc2994a157dcbf761c06_720 d88fad7eaf2bf76c3b7d5470f1d314f0

自动化验证:

python -m pytest \
  tests/claude_code_plugin \
  tests/codex_plugin \
  tests/test_system_cli.py \
  tests/e2e/test_claude_code_service_chain.py \
  tests/e2e/test_codex_service_chain.py \
  tests/e2e/test_mcp_transport.py

结果:109 passed。

其他验证:

prek run -a
ty check
zensical build -s
claude plugin validate --strict .
claude plugin validate --strict integrations/claude-code/plugins/powercontext

以上命令全部通过。

手动验证覆盖:

  • 从功能分支安装 CLI 和插件;
  • 执行 setup 和两个 doctor 命令;
  • 启动 PowerContext Server 和 Claude Code;
  • 在 /hooks 与 /mcp 中确认 PowerContext;
  • 在一个 Claude Code 会话中显式保存项目 Memory;
  • 在新会话中自动召回该 Memory。

完整执行 python -m pytest --doctest-modules 时结果为 508 passed, 7 skipped, 2 failed。一个失败来自未修改的 LoCoMo fixture 哈希不一致;另一个是 provider readiness timeout,单独重跑已通过。两者均不涉及本集成。

AI 使用声明

使用了 OpenAI Codex 进行仓库分析、辅助实现、测试与文档编写以及验证。最终修改经过人工审阅,并由作者完成 CLI 集成的端到端手动验证。

@CLAassistant

CLAassistant commented Aug 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@XnLemon
XnLemon marked this pull request as ready for review August 14, 2026 05:05
@XnLemon

XnLemon commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

cc @PsiACE, The content is essentially aligned with the Codex implementation, and evidence of the successful use of powercontext has been added. Pls review it when you have time. -w- )b

@XnLemon

XnLemon commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Please resolve the merge conflicts with the latest master branch. Thanks!

sure, i will fix them in midnight -w-)b

@XnLemon

XnLemon commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Conflict files resolved, review fixed~ I will continue to follow up ( -w- ) b

@XnLemon
XnLemon requested a review from Teingi August 14, 2026 22:10
@Teingi
Teingi merged commit 647ae02 into oceanbase:master Aug 17, 2026
9 checks passed
222twotwotwo pushed a commit to 222twotwotwo/powercontext that referenced this pull request Aug 23, 2026
* feat(integration): add Claude Code plugin

* style: apply pinned Ruff formatting

* fix(claude-code): harden plugin setup
AlexStocks pushed a commit that referenced this pull request Nov 20, 2026
Claude Code's hooks/user_prompt_submit.py and Codex's hooks/recall.py
carried the same prompt flow: resolve the Scope, take the session's
bootstrap receipt, recall prepared context, capture the prompt, and
flush, with the same HTTP helpers, failure classification, and
diagnostics. They differed in the integration name in source IDs and
metadata, the User-Agent, the diagnostic component, the metadata field
for the host's prompt identifier, the payload fields they read, and
their settings types.

The flow now lives once in src/powercontext_integration_lifecycle/, in
user_prompt_submit.py. run_user_prompt_submit() takes the HostProfile,
a UserPromptEvent that the hook translates from the host's payload, and
PromptSettings. PromptSettings carries the ScopeBindingSettings that
the Scope client uses, and the flow's own requests use the same Server,
credential, and request timeout. HostProfile gains prompt_id_field, the
metadata field in which a captured prompt keeps the host's identifier
for it: prompt_id for Claude Code and turn_id for Codex. Each plugin's
settings class converts itself with prompt_settings(). A Scope that
cannot be resolved becomes a scope_resolve diagnostic, as it did in the
hooks, and the result then has no scope_id. The flow scrubs the prompt
before it resolves the Scope, so the result always carries the scrubbed
prompt; scrubbing has no side effects.

Codex's POWERCONTEXT_CODEX_PROMPT_RECALL setting from #2453 moves
with the flow as PromptSettings.prompt_recall. With it off, the flow
sends no prepare request and injects nothing, and it still takes and
clears the session's bootstrap receipt, as the hook did. With recall
and capture both off, the flow returns before it looks at the event, so
the hook sends no request and writes nothing. Claude Code has no such
setting and passes prompt_recall=True.

The two hooks remain shells with the same paths. They read stdin, match
the event name, translate the payload, load settings, start the HTTP
budget where each did before, and write the host output. Codex still
writes its evaluation trace after the capture, now from the translated
event. Codex's token savings hook imports its HTTP helpers from the
package module instead of the recall hook. The comment in the WorkBuddy
hook, which adapts the same flow, points to the package module.

The capability manifest counted a registered prompt hook as complete
when its script named the prepare, capture, and flush endpoints. Those
requests are now in the package module, so the check also reads the
plugin module from which the hook script imports
run_user_prompt_submit(), resolved from the plugin root that the hooks
put on sys.path. It follows no other imports: Codex's token savings
hook imports HTTP helpers from the same module without running the
flow, and a test checks that registering it for UserPromptSubmit still
counts as incomplete. The test that rewrites a hook's registered
command copies whole plugins, without their .venv and __pycache__
directories, instead of their hooks directories, so that the other
hosts' hooks still find their modules.

One behavior changes, in Codex. When the recall raised an error that
the flow does not classify, the Codex hook ended before it captured the
prompt. The Claude Code hook has captured the prompt in that case
since #1237, and both hosts' docs say that recall and capture fail
independently. Codex lost the capture when #45 narrowed which recall
errors it reports, and no test covered it. Responses that break off or
cannot be decoded are classified now, so no known Server response
reaches this case. Both hosts now lose only the context. A Codex test
like the Claude Code one covers it and fails against the previous hook.

Requests and output are otherwise unchanged, and the Claude Code and
Codex characterization fixtures pass as recorded. The plugin tests patch
and call the flow in the package module. The Claude Code tests drop
that module between tests like the other package modules. A Codex test
checks that the include_code setting reaches the prepare request, which
now passes through the settings conversion; no Codex test covered it.
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.

feat(integration): add a PowerContext plugin for Claude Code

2 participants