Cursor Hooks 说明
结构
hooks/
├── run-hook.ps1 # Windows dispatcher(读取 local-env.json 后分发)
├── session-init.ps1 # sessionStart hook(PowerShell 版)
├── session-init.sh # sessionStart hook(bash 版)
├── check-changelog.ps1 # stop hook(PowerShell 版)
├── check-changelog.sh # stop hook(bash 版)
└── README.md # 本文件
跨平台适配
hooks.json 中的 command 字段是平台绑定的——Windows 用 powershell,macOS/Linux 用 bash。
Windows(当前)
hooks.json 使用 powershell ... run-hook.ps1 作为入口,dispatcher 根据
.cursor/local-env.json 的 shell 字段决定执行 .ps1 还是 .sh 脚本。
迁移到 macOS / Linux
将 hooks.json 的 command 改为直接调用 .sh 脚本:
{
"version": 1,
"hooks": {
"sessionStart": [{ "command": "bash .cursor/hooks/session-init.sh", "timeout": 5 }],
"stop": [{ "command": "bash .cursor/hooks/check-changelog.sh", "timeout": 10, "loop_limit": 1 }]
}
}
同时更新 .cursor/local-env.json 的 shell 字段为 bash 或 zsh。