You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hooks/cursor/README.md
+32-1Lines changed: 32 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,14 @@ This directory contains **optional** hook scripts and example `hooks.json` confi
4
4
5
5
Hooks are deterministic programs that run at defined points in the agent loop and can block, allow, or modify actions.
6
6
7
+
### Requirements
8
+
9
+
-[uv](https://docs.astral.sh/uv/) available on `PATH`
10
+
- Python 3.14 or newer, managed through `uv`
11
+
- Hook scripts copied with executable mode
12
+
13
+
The scripts use only the Python standard library at runtime. Repository development tools are declared in [`pyproject.toml`](../../pyproject.toml) and locked in [`uv.lock`](../../uv.lock).
14
+
7
15
### Files
8
16
9
17
-`guard_before_shell.py`: Intended for `beforeShellExecution`
@@ -12,7 +20,8 @@ Hooks are deterministic programs that run at defined points in the agent loop an
12
20
-`guard_before_read_file.py`: Intended for `beforeReadFile`
13
21
- Denies reading common secret files (for example `.env`, private keys)
14
22
-`audit_log.py`: Intended for `preToolUse` (or other events)
15
-
- Writes a redacted JSONL audit record to `.cursor/hooks/state/hook-audit.jsonl` (project) or `~/.cursor/hooks/state/hook-audit.jsonl` (user)
23
+
- Writes a bounded, redacted JSONL audit record to `.cursor/hooks/state/hook-audit.jsonl` (project) or `~/.cursor/hooks/state/hook-audit.jsonl` (user)
24
+
-`hook_io.py`: Shared fail-safe JSON input/output helpers used by both guard scripts
16
25
-`hooks.project.example.json`: Example project config (paths like `.cursor/hooks/...`)
17
26
-`hooks.user.example.json`: Example user config (paths like `./hooks/...`)
The example configuration executes each script directly. Its `uv run` shebang selects the declared Python runtime without requiring a project-specific virtual environment.
40
+
41
+
### Security model
42
+
43
+
These hooks are defense-in-depth controls, not a sandbox:
44
+
45
+
- Guard scripts reject malformed input instead of silently allowing it.
46
+
- Audit records redact common secret keys and values, bound untrusted data, and use `0700` directory and `0600` file permissions.
47
+
- Example configurations retain `"failClosed": false` so a missing runtime or broken optional hook does not disable Cursor. Organizations that treat hooks as mandatory policy enforcement should test the scripts in their environment and deliberately change this setting.
48
+
- Shell parsing is conservative but cannot prove arbitrary shell code safe. Remote-write authorization and normal code review remain required.
49
+
50
+
### Development
51
+
52
+
```bash
53
+
uv sync --dev
54
+
uv run ruff check hooks/cursor
55
+
uv run ruff check hooks/cursor/*.py --select D --config "lint.pydocstyle.convention='google'"
56
+
uv run ruff format --check hooks/cursor
57
+
uv run pylint hooks/cursor/*.py
58
+
uv run python -m unittest discover -s hooks/cursor/tests -v
0 commit comments