Ray's Knowledge Base
Unlock

Defer a mod's prompt submit with $.clock.after, never setTimeout

PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A Claude Code mod cannot call $.prompt.submit from inside a command hook, because the engine refuses a submit made there. A subagent wrote setTimeout, which may not exist in the mod sandbox, and tests failed even though the code was right because the mock clock was never advanced.

Cause#

The engine refuses a submit made inside a command hook, and the sandbox may lack setTimeout.

Fix#

Defer the submit with the mod's clock, $.clock.after (the mod's own later() helper), not setTimeout. Mod tests that cover the deferred prompt must then advance the mock clock (see the claude-code/testing clock types) before they assert that the prompt was queued.

Evidence#

rvow mod; the clock-based defer and clock-advancing tests worked.

Also found by searching

  • a mod cannot call $.prompt.submit from inside a command hook
  • defer the submit with $.clock.after not setTimeout
  • setTimeout may not exist in the mod sandbox
  • mod tests must advance the mock clock before asserting the prompt was queued