Set a mod's env flag in classic.SessionStart (or earlier), not session.start
PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
In a Claude Code plugin that holds both command hooks and a mod, setting an env var from the mod's session.start is too late: the SessionStart command hook has already run, so a switch-off flag is not yet set.
Cause#
The SessionStart command hook runs before the mod's session.start.
Fix#
Set it in classic.SessionStart before calling next (or in engine.create / plugin.register), and both the SessionStart and Stop command hooks then see it. A spike with a test plugin that logged the variable from its hook showed this.
Evidence#
rkb plugin: the switch-off flag for the command hooks.
Also found by searching
- setting an env var from the mod session.start is too late
- SessionStart command hook already ran when the mod sets the flag
- set the flag in classic.SessionStart before calling next
- engine.create / plugin.register as an earlier hook point