beforeSubmitPrompt does not wait for the hook: a block returned after ~1 second is ignored and the prompt is sent

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Cursor sends the prompt to the model without waiting for the beforeSubmitPrompt hook to finish. A hook that answers {"continue": false} (or exits with code 2) blocks the prompt only if it answers almost instantly. If the hook takes even 1 second, the block is ignored, user_message is not shown, and the agent replies to the prompt.

This contradicts the hooks documentation (Hooks | Cursor Docs), which says beforeSubmitPrompt “can prevent submission” with continue: false, and which lets each hook set a timeout.

In practice, a hook that does any real work before deciding can no longer block a prompt. That includes scanning the prompt for secrets, or asking the user to confirm. This used to work.

Measured on Cursor 3.24.18, Windows 11, with the test hook below. Each row is a new chat. We logged the hook’s start time, its exact stdout and exit code, and when it answered, so the hook’s output is confirmed for every row:

Hook answer Answered after Result
{"continue": false, ...}, exit 0 0 s Blocked
{"continue": false, ...}, exit 2 0 s Blocked
{"continue": false, ...}, exit 0 1 s Not blocked (tried twice)
{"continue": false, ...}, exit 0 2 s Not blocked
{"continue": false, ...}, exit 2 5 s Not blocked
{"continue": false, ...}, exit 2 10 s Not blocked

The hook’s stderr is also not shown in the Hooks output channel.

Steps to Reproduce

  1. Save this as block_test.py:

    import json, sys, time
    
    event = json.loads(sys.stdin.buffer.read().decode("utf-8-sig"))
    words = event.get("prompt", "").split()
    block = {"continue": False, "user_message": "Blocked by the test hook"}
    
    if "block-now" in words:            # answer at once
        print(json.dumps(block)); sys.exit(0)
    if "block-after" in words:          # answer after N seconds, e.g. "block-after 2 hello"
        time.sleep(float(words[words.index("block-after") + 1]))
        print(json.dumps(block)); sys.exit(0)
    print(json.dumps({"continue": True}))
    
  2. Add it to ~/.cursor/hooks.json:

    {
      "version": 1,
      "hooks": {
        "beforeSubmitPrompt": [
          { "command": "python /absolute/path/to/block_test.py", "timeout": 60 }
        ]
      }
    }
    
  3. Reload the window. In a new chat for each, send:

    • block-now hello: blocked, as expected.
    • block-after 1 hello: expected blocked; actually the agent replies.
    • block-after 5 hello: expected blocked; actually the agent replies.

Expected Behavior

The prompt is not sent to the model until every beforeSubmitPrompt hook has returned, up to its configured timeout. A hook that returns {"continue": false} within its timeout blocks the prompt and shows user_message, however long it took.

Operating System

Windows 10/11

Version Information

Version: 3.24.18 (user setup)
VS Code Extension API: 1.128.0
Commit: be4c9e5350d77747b42cd467cbd3370a753d4640
Date: 2026-10-13T18:12:58.182Z
Layout: Agent Window
Build Type: Stable
Release Track: Default
Electron: 42.10.0
Chromium: 148.0.7778.280
Node.js: 24.18.1
V8: 14.8.178.38-electron.0
xterm.js: 6.1.0-beta.291
OS: Windows_NT x64 10.0.26200

Additional Information

Does this stop you from using Cursor

Sometimes - I can sometimes use Cursor

Hey, and thanks for the detailed report and the test script. That really helps.

We took a look at this. In 3.24.18, Cursor should wait for each beforeSubmitPrompt hook to finish, up to its timeout, before sending anything. Based on what we see, blocking after a few seconds of hook wait time on Windows in Agent Window works correctly. So this looks like something specific to your setup, and we’d like to locate it.

Could you run one failing case and send the output?

  1. Reload the window Ctrl+Shift+P > Developer: Reload Window
  2. Go to View > Output, then in the dropdown on the right select Hooks
  3. Right-click in the Output panel and choose Clear Output
  4. Start a new chat and send: block-after 2 hello
  5. Wait for the agent’s reply
  6. Copy everything from the Hooks output panel and paste it here
  7. In the same chat, open ... > Copy Request ID, and paste that here too

A couple more questions:

  • Does the same thing happen in the classic editor layout, or only in Agent Window?
  • What does Cursor Settings > Hooks show? A screenshot is fine. It should show all loaded hooks, including ones imported from Claude Code settings and plugins.
  • In the chats where the agent replied, did you click Try again or Continue, or send a second message before the reply appeared?

One more thing to keep in mind: when a hook really blocks, the blocked message currently stays in the chat. If you then send another message in that chat, or click Try again or Continue, the blocked text may still get sent to the model. We’re still looking into this. For now, starting a new chat after a block works around the issue.

Hey Dean, thanks for the quick reply.

I followed through the steps and my prompts did get blocked. SO I dug deeper into my earlier configuration and found out that this was on my side. My hook command used pythonw.exe (windowless Python on Windows). Run with python.exe, the same hook blocks correctly after 2 s and 10 s on Cursor 3.24.18. It looks like Cursor does not wait for a GUI-subsystem process, so only an answer that arrives almost instantly is used. That may be worth documenting, but the blocking itself works.

Thanks for digging into it and coming back with the result.

Most likely, this is about how Windows launches GUI-subsystem programs like pythonw.exe: the shell usually doesn’t wait for that kind of process to finish. Because of that, only the response that comes back almost right away gets counted. With python.exe, the hook runs as a console process, so any response that arrives before timeout is counted. I marked your post as the solution so other users with Python hooks on Windows can find it. I also passed along the suggestion to add this to the docs.

There’s already a separate thread about the BOM in stdin on Windows: On Windows, Cursor’s hook stdin JSON payload includes a UTF-8 BOM that breaks standard JSON.parse(), causing security guards to silently degrade to allowing commands across all agent channels, so utf-8-sig is still the right workaround for now.

And one question: with python.exe, is the hook’s stderr now visible in the Hooks channel? If not, let me know and we can look into that separately.