[BUG] Mods: on Team orgs cc-plugin-sec-default passes over user-tier classic.Stop/StopFailure/SessionStart, and the Stop skip is silent
What happens
On a Team org, cc-plugin-sec-default@builtin seats itself outermost and passes over the classic.* hooks of every user-tier mod (loaded with CLAUDE_CODE_PLUGIN_DIRS or --plugin-dir). For a mod that relies on classic.Stop, classic.StopFailure and classic.SessionStart, this means it never sees the end of a turn or the start of a session, in ordinary interactive and -p sessions (not only background ones, cf. #103962).
Only the classic.SessionStart skip shows a notice. The classic.Stop skip shows nothing in the session, so a mod that acts on Stop goes silent with no visible error: ours did for about 9 hours across 6 open sessions before we noticed.
Repro
- A user-tier mod whose hooks module registers
on("classic.Stop", …)andon("classic.SessionStart", …). claude -p --model haiku --debug "Reply only: ok"on an account of a Team org.- The debug log has:
[DEBUG] cc-plugin-sec-default@builtin seated outermost: the organization is team
[DEBUG] <mod>: classic.SessionStart bypassed by cc-plugin-sec-default (tier user); beneath runs
[DEBUG] <mod>: classic.Stop bypassed by cc-plugin-sec-default (tier user); beneath runs
Seen on 2.1.306 (debug log above) and still on 2.1.307 (the SessionStart notice appears at every session start). prependPlugins passed with --settings does not move the mod ahead of sec-default.
Workaround we use
turn.complete in place of classic.Stop/classic.StopFailure, and session.end with reason clear in place of classic.SessionStart after /clear: both reach the user tier.
Questions
- Is skipping
classic.Stop/classic.StopFailure/classic.SessionStartfor user-tier mods on Team orgs intended? - If it is, could the skip of
classic.Stopshow the same notice as SessionStart, or could registration tell the mod that the event will not reach its tier (as #104216 also asks)?
Related
#103962, #104216, #103626, #102653
The silent-skip half of this is fixable in the mod's source (mods/sec-default). This repository does not appear to take pull requests from outside the organization, so here is a ready branch on a fork: sec-default-classic-bypass-notice on potoior/claude-code — commit d285555872a630552a4f7de633c7c47273c0c1ca, diff against main.
What it does: after the classic.* hook's next.to(e, "append") settles, it reads next.trace and logs every user-tier link the continuation skipped (outcome: "skipped", reason: "bypassed by cc-plugin-sec-default") with $.ui.log, once a session for each plugin and event, in the same words the debug log keeps:
mine: classic.Stop bypassed by cc-plugin-sec-default (tier user); beneath runs
So the SessionStart notice stops being the only visible one, and a mod that acts on classic.Stop / classic.StopFailure names why it went quiet on its first bypassed event, once per session.
Scope notes:
- The skip itself is unchanged, and reads as intended per the mod's README (
classic.*row: continue past the user tier); only plugins that actually hooked the event are named, so a session with no classic-hook mods sees no line. - The registration-time warning ask (#104216) needs an engine API and stays open.
Verified the way .github/workflows/mod-tests.yml runs it: tsc -p mods/tsconfig.json clean, and claude plugin test under 2.1.308 across diff / telemetry / agents-md / sec-default — 420 pass / 0 fail, including two new tests for the notice and its per-plugin-per-event dedup (tests/register.test.ts, fixture tests/fixtures/hooking.ts).
Same on a Team org with Claude Code 2.1.309: cc-plugin-sec-default also passes over user-tier classic.SubagentStart, classic.SubagentStop and classic.PostCompact, and the native session.compact. Debug log:
<mod>: classic.SubagentStop bypassed by cc-plugin-sec-default (tier user); beneath runs
<mod>: classic.PostCompact bypassed by cc-plugin-sec-default (tier user); beneath runs
<mod>: session.compact bypassed by cc-plugin-sec-default (tier user); beneath runs
Workaround for subagents: agent.spawn (gives agentId, and teammateId for a teammate) plus the subagent's own turn.complete (e.agentId, fires for foreground and background subagents). Both reach the user tier. On accounts where the classic hooks do run, they run first, so deduping by agent id keeps it to one call. I found no stand-in for session.compact.
@eurrag The silent Stop-hook bypass is the scary part here.
If a verification gate relies on a lifecycle hook, merely having the hook installed doesn't prove that completion was actually checked.
I've been investigating completion verification from outside the agent's own claims, and this seems like an important failure boundary.
Is there any reliable runtime signal in your reproduction that an external supervisor could use to distinguish "the Stop hook ran and approved" from "the Stop hook never ran"?
On "I found no stand-in for session.compact": this is what we moved our mods to on a Team org (2.1.310). Each event below reaches the user tier there.
/compact:on('command.run', { command: 'compact' }, …). A probe mod saw it reach the user tier, andawait next(e)settles when the command is done. It does not see an auto-compaction, or a$.session.compact()call from another plugin.- A compaction between turns or while idle: the
SessionContextUsagedoc sayscontext.tokensis absent in "a fresh session, or one just compacted, until its next response". So atprompt.submit, if$.session.usage()has nocontext.tokensbut an earlier response gave a fill, the conversation was compacted. Forget the fill onsession.endwithreason: 'clear'so that/cleardoes not count. - An auto-compaction inside a turn:
session.measurereaches the user tier. We count a compaction whencontext.tokensfalls by at least 20k tokens and to 70% or less of the last fill. This is a heuristic: another sharp fall in context would count too, and we have not yet seen it catch a live auto-compaction.
let lastFill: number | undefined;
const isCompactedFill = (before: number | undefined, after: number) =>
before !== undefined && before - after >= 20_000 && after <= before * 0.7;
on('session.end', ($, e, next) => {
if (e.reason === 'clear') lastFill = undefined;
return next(e);
});
on('prompt.submit', async ($, e, next) => {
if (lastFill !== undefined) {
const { context } = await $.session.usage();
if (context.tokens === undefined) {
lastFill = undefined;
onCompacted($); // compacted since the last response
}
}
return next(e);
});
on('session.measure', ($, e, next) => {
const fill = e.context.tokens;
if (fill !== undefined) {
if (isCompactedFill(lastFill, fill)) onCompacted($); // inside a turn
lastFill = fill;
}
return next(e);
});
on('command.run', { command: 'compact' }, async ($, e, next) => {
const result = await next(e);
lastFill = undefined; // so the next prompt does not count it again
onCompacted($); // the person's /compact
return result;
});
What this cannot give is session.compact's own input: the transcript before the compaction, the trigger, and tokensBefore/tokensAfter.
SubagentStart is passed over too. On Claude Code 2.1.325 and 2.1.327 (macOS), a user-tier mod with a SubagentStart hook misses some subagent starts during normal work, with a "hook was skipped" notice naming cc-plugin-sec-default, as for classic.SessionStart.
A mod that tracks subagents from SubagentStart then misses the agent, so its row appears late or not at all, and nothing in the API lets it recover the event.