Hook beforeSubmitPrompt afterAgentResponse

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

When I use a hook to save chat records to a file, the file displays unreadable question marks, both in the request and response。

Steps to Reproduce

hook.json
{
“version”: 1,
“hooks”: {
“beforeSubmitPrompt”: [
{
“command”: “python .cursor/hooks/before_submit_prompt.py”
}
],
“afterAgentResponse”: [
{
“command”: “python .cursor/hooks/after_agent_response.py”
}
]
}
}

hook script
#!/usr/bin/env python
import sys
import json
import time
try:
# 读取输入
input_data = sys.stdin.read()
data = json.loads(input_data) if input_data else {}
current_date = time.strftime(‘%Y-%m-%d’, time.localtime(time.time()))
session_file_name = f’{current_date}_{data[“conversation_id”]}.txt’

with open("chat_history/raw_history/" + session_file_name, 'a+') as f:
    f.write(input_data)

response = {
    'continue': True
}
print(json.dumps(response))
sys.exit(0)

except Exception as e:
print(json.dumps({‘continue’: True}))
sys.exit(0)
{“conversation_id”:“a2980acf-562f-4027-9860-906ce452b419”,“generation_id”:“456d758e-7caa-4512-8f06-3dfed8eb88f0”,“model”:“default”,“prompt”:“hello “,“attachments”:[{“type”:“file”,“file_path”:“d:\code\code\securitycenter\.cursor\hooks\after_agent_response.py”},{“type”:“rule”,“file_path”:“command-prefix-required.mdc”},{“type”:“rule”,“file_path”:“topic-focus.mdc”}],“hook_event_name”:“beforeSubmitPrompt”,“cursor_version”:“2.3.34”,“workspace_roots”:[”/d:/code/code/”],“user_email":"[email protected]”}
{“conversation_id”:“a2980acf-562f-4027-9860-906ce452b419”,“generation_id”:“456d758e-7caa-4512-8f06-3dfed8eb88f0”,“model”:“default”,“text”:“\n???\n\n???\n- ???\n- ???\n- ???\n- ???\n- ???\n\n??? .cursor/hooks/after_agent_response.py???”,“hook_event_name”:“afterAgentResponse”,“cursor_version”:“2.3.34”,“workspace_roots”:[“/d:/code/code/”],“user_email”:“”}

“text”:“\n???\n\n???\n- ???\n- ???\n- ???\n- ???\n- ???\n\n???

Operating System

Windows 10/11

Current Cursor Version (Menu → About Cursor → Copy)

Version: 2.3.34 (system setup)
VSCode Version: 1.105.1
Commit: 643ba67cd252e2888e296dd0cf34a0c5d7625b90
Date: 2026-01-10T21:17:10.428Z
Electron: 37.7.0
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Windows_NT x64 10.0.26200

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey, thanks for the report. This is a known issue. On Windows, when passing data to hooks via stdin, Cursor doesn’t handle UTF-8 correctly, so non-ASCII characters get replaced with question marks.

A similar bug report is here: Windows: Cursor Hooks corrupt Chinese (UTF-8) characters in stdin - replaced with question marks

The team is already working on a fix. There’s a possible workaround. Enable “Beta: Use Unicode UTF-8 for worldwide language support” in Windows Regional Settings (Control Panel > Region > Administrative tab), then restart Cursor. Based on other reports, this may not fully fix the issue in every case.

Your detailed example with the JSON output is really helpful. I’ll link this thread to the existing ticket so the team has more examples.

Sorry, I didn’t find it. Could you please explain it in more detail? I’m already using the beta version
Version: 2.4.0-pre.23.patch.0 (system setup)
VSCode Version: 1.105.1
Commit: cab66266bb3203a8180b859fe1caccf9091f1f60
Date: 2026-01-13T00:21:31.647Z
Build Type: Stable
Release Track: Nightly
Electron: 37.7.0
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Windows_NT x64 10.0.26200

not found the region panel

Here’s how to find Regional Settings in Windows:

  1. Press Windows + R
  2. Type intl.cpl and press Enter
  3. Go to the Administrative tab
  4. Click Change system locale…
  5. Check Beta: Use Unicode UTF-8 for worldwide language support
  6. Restart your PC (you need a full reboot, not just restarting Cursor)

Important: like I said in post #4, this workaround might not fully fix the issue. Based on a report in this thread Windows: Cursor Hooks corrupt Chinese (UTF-8) characters in stdin - replaced with question marks, even after enabling the UTF-8 beta option, characters show correctly in the execution log, but files created by the hook script may still contain question marks.

The team is working on fixing this bug, but there’s no ETA yet.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.