Skip to content

Inbox reminder reaches Team/Enterprise sessions and survives compaction (#2159) - #2167

Merged
backnotprop merged 4 commits into
mainfrom
fix/inbox-reminder-guarded-2159
Oct 25, 2026
Merged

backnotprop merged 4 commits into
mainfrom
fix/inbox-reminder-guarded-2159

Conversation

@backnotprop

@backnotprop backnotprop commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Part 1 of #2159 (part 2 shipped in #2160), built as the approved spec (inbox-reminder-guarded, options B + D′).

What changed

On Team/Enterprise accounts, Claude Code's built-in cc-plugin-sec-default sits in the prepend tier and sends prompt.context past every user-tier hook. The mod adds the Inbox reminder in that hook, so guarded sessions never got it.

  • Standard users: the prompt.context block is unchanged.
  • Learned fallback (register.ts, pure rules in inbox.ts): a $.store key, inboxReminderContextWorks, is read once per process. It becomes true the first time the mod's prompt.context hook runs. It becomes false when a conversation's first main-loop turn completes without that hook having run. While the key is not true, a conversation's first prompt (not isMeta, not a slash command) carries the same reminder text as prompt.submit context. The conversation counts as reached only once the prompt has entered. Two kinds of turn teach nothing: an aborted first turn, and a resumed session ($.session.usage().startedAt more than a minute before this process's first session.start).
  • After compaction, for everyone: at session start the mod sets PLANNOTATOR_INBOX_REMINDER to the reminder text, with the tool's full registered name. It unsets the variable when the reminder gate is off. hooks.json gains one SessionStart command hook, matcher compact, command echo "$PLANNOTATOR_INBOX_REMINDER", timeout 5 s. It never starts the plannotator binary. The engine trims hook stdout, so an unset variable adds nothing.
  • Docs: the inboxReminder entry, the mod's Inbox section, a new env-table row in CLAUDE.md/AGENTS.md, and the reminder section in reference/inbox.md.

Duplicates, as accepted: a standard user gets one duplicate, in the first conversation after the update. After that, one per compaction (the re-made block plus the hook's line). A resumed guarded conversation gets the copy again. The "prompt.context hook was skipped" transcript note stays for guarded users (spec finding 7).

Engine and platform checks

  • 2.1.287 (the mod's floor) supports prompt.submit context. Checked in the @anthropic-ai/[email protected] binary: the validator checks e.context, and the entered context becomes a hook_additional_context row (pen(it, "prompt.submit")). That build also trims a command hook's stdout before it becomes hook_success content. No gate was needed.
  • Windows: the mod is off there (no /bin/sh), so the variable is never set. Claude Code 2.1.310 runs a command hook in Git Bash, else in PowerShell (-NoProfile), never in cmd (e.shell ?? <bash|powershell>). The spec's [ -n … ] && printf … is a parse error in PowerShell. The hook therefore uses echo "$PLANNOTATOR_INBOX_REMINDER", which parses and exits 0 in sh, bash and PowerShell. In PowerShell the name is an empty PowerShell variable, so the hook prints only a newline, which the engine trims to nothing. inboxReminderEnvValue never publishes a value with a backslash or a leading -, so dash's echo prints the text unchanged. One side effect: without Git Bash, Claude Code shows its "a plugin hook ran in PowerShell" notice once, the first time any of the plugin's command hooks runs. The existing hooks already trigger that notice.

Tests

  • apps/hook/hooks/mod/inbox-reminder.test.ts: the decision table (every row), the first-turn lesson, resume detection, and the env value. It also runs the command from hooks.json for real under /bin/sh and /bin/bash, with the variable set and unset. It checks the compact matcher, and checks that register.ts spells the env name as the literal. A PowerShell case runs when pwsh is installed; it was skipped here.

  • The engine harness (apps/hook/tests/register.test.ts via scripts/test-claude-code-mod.sh, Claude Code 2.1.310, run with a temp CLAUDE_CONFIG_DIR) has 12 new cases. They use an inline prepend-tier stand-in for the guard that does next.to(e, 'append') on prompt.context and classic.*:

    • standard with the store true;
    • standard with nothing learned yet (one copy, then true, then nothing after /clear);
    • guarded (the exact text, false learned, a copy in the next conversation);
    • a machine that becomes guarded later;
    • an aborted first turn and a subagent turn;
    • a dropped prompt;
    • every gate off (inboxReminder: false, no inbox.json, tool refused, PLANNOTATOR_INBOX_TOOL=0): no copy, and the variable unset;
    • the mod off and -p: nothing set.

    All 50 harness tests pass. A mutation that disables the copy fails 4 of them.

  • bun test apps/hook/hooks/mod/ (218 pass before the new file), bun run typecheck, claude plugin validate apps/hook.

Not run: a live Team-account session and a live /compact (the manual checks in the spec).

Follow-up: prompt.context ran before session.start had decided

The #2167 review reproduced a bug live on Claude Code 2.1.310. The engine runs prompt.context before the mod's session.start has registered plannotator_inbox. As a result, every process's first conversation had no block; main has the same bug. The first turn then learned false on standard machines.

  • session.start now settles a promise with its decision as soon as the switch, inbox.json and the tool name are known. It also settles on the early returns (-p, mod off) and when it throws. prompt.context and the prompt.submit fallback wait on that promise for at most 2.5 s.
  • A prompt.context call that runs out of time adds no block, but it still records that it ran. That way the machine is never learned as guarded.
  • The CLI removes PLANNOTATOR_INBOX_REMINDER at startup (apps/hook/server/mod-session-env.ts), next to the other variables it takes from its host. Children of a server the mod launched, including Claude agent jobs, therefore never inherit it.
  • New engine-harness cases:
    • prompt.context fires while session.start waits on a slow Inbox /mcp. The block lands and the store learns true. This case fails without the fix.
    • A store wrongly set to false goes back to true.
    • The resume rule, with session.usage mocked: a session started an hour before this process teaches nothing, and one started 2 s before still teaches false.

Live check: an interactive Claude Code 2.1.310 session on a standard account, with --plugin-dir apps/hook, the installed plugin turned off, a scratch data dir and haiku.

  • First prompt of a new process: the plannotatorInbox block is there and the store learns true. prompt.context settled after 214 ms, before session.start (359 ms).
  • After /clear: the block again, with no copy.
  • After /compact: the block, plus SessionStart:compact hook success: Plannotator Inbox is on: … (the accepted duplicate). That hook finished with status 0 in 8 ms.
  • A second process: the block again, and the store stays true.

Closes #2159.

🤖 Generated with Claude Code

…on (#2159)

cc-plugin-sec-default sends prompt.context past the mod, so guarded
sessions never got the reminder. The mod now learns per machine whether
prompt.context runs ($.store inboxReminderContextWorks) and, while it has
no evidence that it does, adds the same line as the first prompt's
prompt.submit context. After every compaction a SessionStart 'compact'
command hook prints the reminder the mod publishes in
PLANNOTATOR_INBOX_REMINDER (echo, which parses in sh, bash and PowerShell).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
…CLI drops PLANNOTATOR_INBOX_REMINDER (#2159)

The engine runs prompt.context before the mod's session.start has
registered plannotator_inbox (live on 2.1.310), so the block was missing
from every process's first conversation and the first turn taught false
on standard machines. session.start now settles a promise with its
decision (also on -p, mod off, a throw); prompt.context and the
prompt.submit fallback wait on it, at most 2.5 s.

The CLI removes PLANNOTATOR_INBOX_REMINDER at startup, so agent jobs
and other children of a server the mod launched never inherit it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

Claude Code (Team/Enterprise): two transcript notices per session from hooks cc-plugin-sec-default skips

1 participant