beforeSubmitPrompt hook lacks reliable current mode signal (Ask vs Agent), making mode-based command safety gates unreliable
Summary
I’m trying to enforce a simple safety policy via hooks:
/code-reviewmust run only in Ask mode- all other slash commands must run only in Agent mode
In practice, beforeSubmitPrompt does not expose a reliable current mode signal for this decision, so the hook cannot act as a dependable circuit breaker.
Expected behavior
A hook should be able to deterministically tell the current mode (Ask/Agent) for each submitted prompt, so it can allow/deny command execution safely.
Actual behavior
In beforeSubmitPrompt payloads, mode information is inconsistent/unreliable (sometimes misleading, sometimes missing), so mode-based enforcement becomes either:
- fail-open (unsafe), or
- fail-closed (blocks valid usage)
Minimal repro
- Create
.cursor/hooks.jsonwith abeforeSubmitPromptcommand hook andfailClosed: true. - Hook script reads stdin JSON and logs mode-like keys (
mode,session_mode,current_mode,interaction_mode,composer_mode) + prompt command. - Hook logic:
- deny
/code-reviewunless mode is Ask - deny other slash commands unless mode is Agent
- deny
- Start fresh session and run:
- Agent mode:
/code-review ...(should deny) - Ask mode:
/code-review ...(should allow)
- Agent mode:
Observed:
- mode keys are not consistently present/reliable per prompt
composer_modemay showagenteven when running from Ask UI context- mode can be missing entirely
Result: reliable policy cannot be implemented using hooks with confidence, and while it’s possible to work around using a 1 liner in the prompt, that’s only a suggestion and wastes context. I might be wrong, but I believe that this is a platform responsibility imo.
Why this matters
Hooks are the only practical place to build hard safety guardrails around command execution. Without reliable mode context in beforeSubmitPrompt, hooks can’t be trusted as a safety circuit breaker for mode-restricted commands.
Requested fix
Please expose a stable, documented, per-prompt field in beforeSubmitPrompt input, e.g.:
current_mode: "ask" | "agent" | "plan" | "debug"
(or equivalent, with clear semantics), guaranteed for every call.
Bonus: include command metadata (resolved slash command file/ID) so hooks can enforce command-specific policy without brittle prompt parsing.
Current workaround
I had to fall back to soft guardrails in command markdown (“if not Ask/Agent, stop”) instead of hard hook enforcement.
See also (similar, but not the same) : Add additional_context to beforeSubmitPrompt hook output