OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: openviking-memory Claude Code plugin: usage mod's classic.UserPromptSubmit and session.append hooks skipped in Team/Enterprise sessions (cc-plugin-sec-default)

Open mohofo7 opened this issue 1 month ago • 3 comments

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

  1. Use Claude Code 2.1.304 (desktop app or CLI) signed in to a Team or Enterprise organization.
  2. Install openviking-memory@openviking 0.7.12 from the marketplace.
  3. 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.mjs keep what it injected per prompt, for example in the plugin's data dir. The mod could then read it at turn.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

mohofo7 avatar Oct 21 '26 13:10 mohofo7

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, so cc-plugin-sec-default@builtin is 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.

kyalpha313 avatar Oct 23 '26 16:10 kyalpha313

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) and 2.1.321 (Desktop app), Pro subscription, no managed settings on the machine (openviking-memory 0.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@builtin is 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 match CLAUDE_CODE_SUBSCRIPTION_TYPE. As a result, personal Pro users also get both skip notices (session.append and classic.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:

  1. Narrow session.append registration with { door: "response" } In Claude Code's cc-plugin-sec-default, session.append only bypasses user-tier modules (next.to(e, "append")) for door values "attachment", "hook-context", and "compaction" (plus Skill "tool-message" and prepend/append "note"). Assistant replies dispatch under door: "response", which cc-plugin-sec-default does not intercept. Currently mods/usage/register.tsx registers an unfiltered on("session.append", ...) and checks e.door !== "response" inside the handler, which causes hook-context / attachment appends to trigger the skip notice. Registering on("session.append", { door: "response" }, ...) directly avoids matching intercepted doors while still receiving every assistant response row.

  2. Replace classic.UserPromptSubmit with turn.start + existing scripts/lib/state.mjs recall snapshot cc-plugin-sec-default bypasses all classic.* events for user-tier modules, so on("classic.UserPromptSubmit", ...) cannot run when the guard is seated. However, turn.start, tool.call, session.append ({ door: "response" }), turn.complete, and ui.render are all unintercepted. Since scripts/auto-recall.mjs already runs as a plain command hook on UserPromptSubmit (unaffected by cc-plugin-sec-default) and already writes atomic runtime state via scripts/lib/state.mjs (~/.openviking/state/), auto-recall.mjs can include the sanitized recalled entries [{ uri, score }] (no prompt text) in a per-session state file (e.g. keyed by cc_session_id). mods/usage/register.tsx can then open each turn on on("turn.start", ...) and attach the recalled { uri, score }[] snapshot when recording the reply in on("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-memory 0.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 挂载最外层时也开箱即用、零跳过告警且正常渲染卡片:

  1. 为 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" }, ...) 即可避开受限通道,同时完整接收每条助手回复记录。

  2. 用 turn.start + 现有的 scripts/lib/state.mjs 召回快照替代 classic.UserPromptSubmit cc-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!

wycocoyu avatar Nov 11 '26 09:11 wycocoyu

hello 有人修复吗?

wycocoyu avatar Nov 13 '26 03:11 wycocoyu