Skip to content

Add Cursor hooks examples - #40

Merged
ericzakariasson merged 3 commits into
cursor:mainfrom
shivamjindal:shivam/add-hooks-examples
Jun 10, 2026
Merged

Add Cursor hooks examples#40
ericzakariasson merged 3 commits into
cursor:mainfrom
shivamjindal:shivam/add-hooks-examples

Conversation

@shivamjindal

@shivamjindal shivamjindal commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

💻 Change Type

  • docs
  • chore

🔀 Description of Change

Add a guided Cursor Hooks examples folder with sample project hook configuration and scripts for audit logging, sensitive prompt guarding, model/repo prompt blocking, and skill update follow-ups. The top-level README now links to the hooks examples so they are discoverable from the cookbook index.

📝 Additional Information

Validation run:

  • jq empty hooks/.cursor/hooks.json
  • bash -n hooks/.cursor/hooks/audit-log.sh hooks/.cursor/hooks/block-models-by-repo-origin.sh hooks/.cursor/hooks/sensitive-prompt-guard.sh
  • node --check hooks/.cursor/hooks/update-skills-on-stop.mjs
  • sample sensitive-prompt-guard.sh allow/block payload checks

No root build or unit test suite was present for these documentation/example changes.


Note

Low Risk
Documentation and sample hook scripts only; no application or production runtime changes.

Overview
Adds a Cursor Hooks cookbook section and a new hooks/ example you can copy into projects: sample .cursor/hooks.json plus scripts for audit logging, blocking sensitive prompts, optional model/repo prompt blocking, and a stop hook that nudges skill doc updates when mapped paths change.

The root README now links to hooks/ so the examples sit alongside Cloud Agents and SDK entries. hooks/README.md documents layout, how to merge config, and customization (blocklists, patterns, SKILL_MAPPINGS, log env vars).

Reviewed by Cursor Bugbot for commit 36fde23. Bugbot is set up for automated code reviews on this repo. Configure here.

- Add sample hook configuration for prompt, shell, file edit, and stop events
- Include audit logging, model/repo blocking, sensitive prompt guard, and skill follow-up hooks
- Document setup, customization, dependencies, and security-tool extension points
- Link the new hooks examples from the top-level README
- Summarize the audit, sensitive prompt guard, and skill follow-up examples
- Preserve existing SDK documentation links

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 4 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit d667fb3. Configure here.

Comment thread hooks/.cursor/hooks.json
local model="$1"
local repo="$2"

printf '{"continue":false,"user_message":"%s model is not allowed to be used on %s"}\n' "$model" "$repo"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deny response breaks JSON escaping

Medium Severity · Logic Bug

The deny function uses printf with unescaped %s placeholders to construct the user_message in its JSON output. If blocked model or repo names contain characters like " or %, or newlines, the resulting JSON will be invalid, breaking the expected response contract.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d667fb3. Configure here.

function changedFiles() {
const tracked = gitLines(["diff", "--name-only", "HEAD"]);
const untracked = gitLines(["ls-files", "--others", "--exclude-standard"]);
return [...new Set([...tracked, ...untracked])].sort();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop hook uses unrelated git diff

Medium Severity · Logic Bug

changedFiles uses git diff --name-only HEAD plus all untracked files, so skill follow-ups can fire for pre-existing local edits the agent never touched, not just files changed during the run.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d667fb3. Configure here.

printf '%s' "$payload" \
| tr '\n' ' ' \
| sed -nE 's/.*"model"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/p'
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex model parse is spoofable

Medium Severity · Logic Bug

model_from_payload pulls model with sed over the entire stdin blob instead of parsing JSON, so a model substring inside prompt (or other fields) can be mistaken for the real selection and drive allow/deny incorrectly.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d667fb3. Configure here.

- Run blocking prompt guards before audit logging
- Keep sensitive prompt previews out of logs when prompts are blocked
- Preserve existing hook matchers, timeouts, and fail-closed settings
@ericzakariasson
ericzakariasson merged commit fd24f2f into cursor:main Jun 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants