[Bug]: openviking-memory Claude Code plugin: usage mod's classic.UserPromptSubmit and session.append hooks skipped in Team/Enterprise sessions (cc-plugin-sec-default)
Issue Origin
Observed or reproduced in a real environment
Bug Description
On Claude Code 2.1.304, every session start in a Team/Enterprise organization prints:
openviking-memory
its session.append hook was skipped. "cc-plugin-sec-default" runs first and sent the event on past it.
openviking-memory
its classic.UserPromptSubmit hook was skipped. "cc-plugin-sec-default" runs first and sent the event on past it.
Claude Code bundles a plugin, cc-plugin-sec-default@builtin. Its own description in the binary says it is "seated outermost on a machine with managed settings and for Team and Enterprise organizations" and "keeps the organization's classic hooks, prompt content, settings and tool policy out of reach of the plugins a person installs". It sends those events past the user tier with next.to(...), so two hooks in mods/usage/register.tsx (plugin 0.7.12) never run there:
on("classic.UserPromptSubmit", …)records each turn and the recall block it injected.on("session.append", …)attaches the card to the reply row.
The result is that the usage cards and /openviking-usage stay empty or incomplete for these users. The memory itself still works: the plain command hooks in hooks/hooks.json (session-start.mjs, auto-recall.mjs, auto-capture.mjs) still run.
Steps to Reproduce
- Use Claude Code 2.1.304 (desktop app or CLI) signed in to a Team or Enterprise organization.
- Install
openviking-memory@openviking0.7.12 from the marketplace. - Start a session and send a prompt.
Expected Behavior
The usage mod records turns and draws its cards. At minimum, it should not depend on events that installed plugins can't reach in these sessions.
Actual Behavior
Both hooks are skipped, and Claude Code prints the two lines above. The cards get no turns or replies.
Minimal Reproducible Example
// mods/usage/register.tsx (0.7.12)
on("classic.UserPromptSubmit", async ($, e, next) => { const res = await next(e); /* never runs */ })
on("session.append", async ($, e, next) => { const res = await next(e); /* never runs */ })
Error Logs
openviking-memory: classic.UserPromptSubmit bypassed by cc-plugin-sec-default (tier …); beneath runs
This is the form claude --debug logs it in, per the plugin-authoring reference. The transcript lines are quoted above.
OpenViking Version
openviking-memory Claude Code plugin 0.7.12
Python Version
3.14.7 (not involved; the issue is in the Claude Code plugin)
Operating System
Windows
Model Backend
N/A
Additional Context
These are only ideas, I haven't tested them:
- Have
auto-recall.mjskeep what it injected per prompt, for example in the plugin's data dir. The mod could then read it atturn.complete, which installed plugins still get. - Move the reply card off
session.append, which counts as prompt content here. - Or catch the bypass and draw a note in place of an empty card.
The same thing hit ponytail's band, which used classic.UserPromptSubmit for the transcript path. Fix: https://github.com/DietrichGebert/ponytail/pull/1209
Still reproduces on newer versions and another OS:
- openviking-memory 0.7.17, Claude Code 2.1.308 (desktop app), macOS
- Machine has managed settings (a corporate endpoint agent installs
/Library/Application Support/ClaudeCode/managed-settings.json) and the account is in a Team org, socc-plugin-sec-default@builtinis seated outermost.
Same two lines in every session, same effect: the memory hooks in hooks/hooks.json keep working (recall is injected on every prompt), only the usage cards are affected.
One more suggestion alongside the ones above: a userConfig option to turn the usage mod off. Right now the only way to silence the two notices is renaming mods/ in the plugin cache, which every plugin update undoes.
Confirming that this now also reproduces on personal Pro accounts (not only Team/Enterprise or MDM-managed machines):
- Environment: macOS (arm64), Claude Code
2.1.318/2.1.319(CLI) and2.1.321(Desktop app), Pro subscription, no managed settings on the machine (openviking-memory0.7.19/main). - Why personal Pro sessions hit this now: In recent Claude Code builds (
2.1.318+), when the hooks-module guard gate is active,cc-plugin-sec-default@builtinis seated outermost by default at session startup ("seated outermost by default: it is not known that neither policy nor plan would seat it") until both the OAuth profile plan check and the remote managed-settings check settle and matchCLAUDE_CODE_SUBSCRIPTION_TYPE. As a result, personal Pro users also get both skip notices (session.appendandclassic.UserPromptSubmit) injected as<task-notification>events, while usage cards remain empty (turns: [],replies: []).
Proposed Fix (Keep Usage Cards Working Without Skip Notices)
We saw #7180 adds a usageCards opt-out knob (defaulting to true). Alongside an opt-out toggle, it looks possible to make mods/usage/register.tsx work out-of-the-box with zero skip notices even when cc-plugin-sec-default@builtin is seated outermost:
-
Narrow
session.appendregistration with{ door: "response" }In Claude Code'scc-plugin-sec-default,session.appendonly bypassesuser-tier modules (next.to(e, "append")) fordoorvalues"attachment","hook-context", and"compaction"(plusSkill"tool-message"andprepend/append"note"). Assistant replies dispatch underdoor: "response", whichcc-plugin-sec-defaultdoes not intercept. Currentlymods/usage/register.tsxregisters an unfilteredon("session.append", ...)and checkse.door !== "response"inside the handler, which causeshook-context/attachmentappends to trigger the skip notice. Registeringon("session.append", { door: "response" }, ...)directly avoids matching intercepted doors while still receiving every assistant response row. -
Replace
classic.UserPromptSubmitwithturn.start+ existingscripts/lib/state.mjsrecall snapshotcc-plugin-sec-defaultbypasses allclassic.*events foruser-tier modules, soon("classic.UserPromptSubmit", ...)cannot run when the guard is seated. However,turn.start,tool.call,session.append({ door: "response" }),turn.complete, andui.renderare all unintercepted. Sincescripts/auto-recall.mjsalready runs as a plain command hook onUserPromptSubmit(unaffected bycc-plugin-sec-default) and already writes atomic runtime state viascripts/lib/state.mjs(~/.openviking/state/),auto-recall.mjscan include the sanitized recalled entries[{ uri, score }](no prompt text) in a per-session state file (e.g. keyed bycc_session_id).mods/usage/register.tsxcan then open each turn onon("turn.start", ...)and attach the recalled{ uri, score }[]snapshot when recording the reply inon("session.append", { door: "response" }, ...).
Would this approach make sense to the maintainers (complementary to #7180's opt-out setting, so cards also work by default in Pro and Team/Enterprise sessions without triggering skip notices)? Happy to put together a PR with tests if this direction looks good!
中文说明
补充确认:这个问题现在在个人 Pro 订阅账号下同样稳定复现(并非仅出现在 Team/Enterprise 组织或装有 MDM 托管配置的机器上):
- 复现环境:macOS (arm64),Claude Code
2.1.318/2.1.319(CLI)与2.1.321(桌面端),个人 Pro 订阅,本机无任何托管配置(openviking-memory0.7.19/main)。 - 个人 Pro 会话同样命中的原因:在近期 Claude Code 版本(
2.1.318+)中,当 hooks 模块守卫开关生效时,cc-plugin-sec-default@builtin会在会话启动阶段默认挂载在最外层("seated outermost by default: it is not known that neither policy nor plan would seat it"),直到 OAuth 订阅类型校验与远端托管策略请求双双返回并与CLAUDE_CODE_SUBSCRIPTION_TYPE匹配为止。因此个人 Pro 用户同样会在每轮被注入这两条跳过提示(session.append与classic.UserPromptSubmit的<task-notification>事件),同时来源统计卡片始终为空(turns: []、replies: [])。
修复方案建议(消除跳过提示并保持来源卡片正常可用)
看到 #7180 新增了 usageCards 手动关闭开关(默认 true)。在提供关闭开关的同时,其实可以让 mods/usage/register.tsx 即便在 cc-plugin-sec-default@builtin 挂载最外层时也开箱即用、零跳过告警且正常渲染卡片:
-
为
session.append增加{ door: "response" }精确过滤条件 在 Claude Code 的cc-plugin-sec-default中,session.append仅对"attachment"、"hook-context"、"compaction"(以及Skill的"tool-message"和prepend/append层的"note")执行跨过user层的next.to(e, "append")。助手回复走的是door: "response",cc-plugin-sec-default不会拦截该通道。 目前mods/usage/register.tsx注册的是无过滤条件的on("session.append", ...),再在回调内部判断e.door !== "response",导致宿主写入hook-context/attachment时命中拦截并打印跳过提示。直接改为注册on("session.append", { door: "response" }, ...)即可避开受限通道,同时完整接收每条助手回复记录。 -
用
turn.start+ 现有的scripts/lib/state.mjs召回快照替代classic.UserPromptSubmitcc-plugin-sec-default会对user层模块跨过全部classic.*事件,因此守卫挂载时on("classic.UserPromptSubmit", ...)无法执行,但turn.start、tool.call、session.append({ door: "response" })、turn.complete和ui.render均不受拦截。 由于scripts/auto-recall.mjs本就作为普通命令行 hook 运行在UserPromptSubmit阶段(不受cc-plugin-sec-default影响),且已经通过scripts/lib/state.mjs(~/.openviking/state/)原子写入运行时状态快照,可以让auto-recall.mjs将脱敏后的本轮召回列表[{ uri, score }](不含任何用户提示词原文)写入按会话隔离的状态文件(按cc_session_id区分)。随后mods/usage/register.tsx在on("turn.start", ...)开启新轮次,并在on("session.append", { door: "response" }, ...)记录回复时读取该召回快照即可。
想请教维护者这个修复方向是否合适(可与 #7180 的手动开关互补,让卡片在个人 Pro 及 Team/Enterprise 会话下默认也能正常工作且不再打印跳过提示)?如果方向认可,我们很乐意补齐单测并提交 PR!
hello 有人修复吗?