Repository navigation
feat(integration): add Claude Code plugin - #1237
Merged
Merged
Conversation
XnLemon
marked this pull request as ready for review
August 14, 2026 05:05
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 |
Contributor
Author
sure, i will fix them in midnight -w-)b |
Contributor
Author
|
Conflict files resolved, review fixed~ I will continue to follow up ( -w- ) b |
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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?
UserPromptSubmitHook that:/v1/context/prepareat most once;additionalContext;powercontext setup claude-codeandpowercontext doctor claude-code.The v1 integration does not install a
StopHook, read Claude Code transcripts, capture assistant responses, or mark ordinary prompts astask-outcome.Are there any user-facing changes?
Yes.
Users can install and diagnose the Claude Code integration with:
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-promptsorPOWERCONTEXT_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-integrationThen start the Server:
In another terminal, run:
In Claude Code, check
/hooksand/mcpto confirm that the PowerContext Hook and MCP Server are active.Automated validation:
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/powercontextAll commands passed.
Manual validation covered:
setupand bothdoctorcommands;/hooksand/mcp;A full
python -m pytest --doctest-modulesrun reported508 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 包含哪些修改?
UserPromptSubmitHook:/v1/context/prepare;additionalContext注入;powercontext setup claude-code和powercontext doctor claude-code。v1 不安装
StopHook,不读取 Claude Code transcript,不采集助手回复,也不把普通 prompt 标记为task-outcome。是否存在用户可见修改?
是。
用户可以通过以下命令安装和诊断 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然后启动并检查:
另一个终端:
在 Claude Code 中检查 /hooks 和 /mcp。
自动化验证:
结果:
109 passed。其他验证:
prek run -a ty check zensical build -s claude plugin validate --strict . claude plugin validate --strict integrations/claude-code/plugins/powercontext以上命令全部通过。
手动验证覆盖:
/hooks与/mcp中确认 PowerContext;完整执行
python -m pytest --doctest-modules时结果为508 passed, 7 skipped, 2 failed。一个失败来自未修改的 LoCoMo fixture 哈希不一致;另一个是 provider readiness timeout,单独重跑已通过。两者均不涉及本集成。AI 使用声明
使用了 OpenAI Codex 进行仓库分析、辅助实现、测试与文档编写以及验证。最终修改经过人工审阅,并由作者完成 CLI 集成的端到端手动验证。