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
