Repository navigation
feat(hooks): detect Cursor 3.x hook registration in ~/.cursor/hooks.json - #1806
Closed
cristianrojas07 wants to merge 1 commit into
Closed
cristianrojas07 wants to merge 1 commit into
cristianrojas07 wants to merge 1 commit into
Conversation
7 tasks done
…json Cursor 3.x ships its own hook config format at `~/.cursor/hooks.json` with `version: 1` and a `hooks` map keyed by event names (`preToolUse`, `beforeShellExecution`). Users who configure that file correctly with `rtk hook cursor` (or a wrapper invoking rtk) were still seeing the "No hook installed" warning because `hook_check::status()` only inspected `~/.claude/settings.json`. This adds `cursor_3x_hook_registered()`, called from `status()` before the existing Claude check. It returns `HookStatus::Ok` when the Cursor hooks file references the `rtk hook cursor` binary directly or via a thin shell wrapper (PowerShell/bash/batch). The wrapper case matters on Windows users running into the BOM/"ask" issue tracked in rtk-ai#1718, where a small shim returning `permission: "allow"` keeps rewrites working until that PR lands. Tests cover: - Native `rtk hook cursor` command in `preToolUse` - Wrapper script (PowerShell .ps1 invoking rtk) - `beforeShellExecution` hook key - Missing file - Unrelated command (no match) - Invalid JSON (graceful fail) - Empty hooks object
cristianrojas07
force-pushed
the
feat/cursor-3x-hook-detection
branch
from
May 8, 2026 22:59
68b7bbf to
8ddcbfc
Compare
Contributor
|
This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet. |
Contributor
|
Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds detection of Cursor 3.x hook registration so users who configure rtk via
~/.cursor/hooks.json(instead of~/.claude/settings.json) no longer see the[rtk] /!\ No hook installed — run rtk init -gwarning every time they runrtk git status,rtk gain, etc.Why
Cursor 3.x introduced its own hook config surface (separate from Claude Code's
settings.json):Cursor loads this file directly and pipes the hook payload to the configured
command. From the user's perspective the hook is "installed" — they ran the equivalent ofrtk init -g --agent cursor, the file exists, the hook gets invoked, and rewrites work end-to-end.But
hook_check::status()only inspects~/.claude/settings.jsonand the legacy~/.claude/hooks/rtk-rewrite.sh. So Cursor-only users (no.claude/directory at all, or.claude/exists but without rtk hook entries) get the warning on every command — even though their setup is correct.What this PR changes
cursor_3x_hook_registered(home: &Path) -> boolinsrc/hooks/hook_check.rs. It reads~/.cursor/hooks.json, parses the JSON, and returnstrueif any entry underhooks.preToolUseorhooks.beforeShellExecutionhas acommandthat:rtk hook cursor(the constantCURSOR_HOOK_COMMAND), ORrtk hook cursoras a substring (covers wrapper invocations likebash -c "rtk hook cursor"), ORrtk(covers thin wrapper scripts that invoke the rtk binary, e.g.powershell.exe -File ~/.cursor/hooks/rtk-cursor-allow.ps1on Windows).status()calls the new helper first, before the existing Claude path. If the Cursor 3.x hook is registered,HookStatus::Okis returned and the warning is suppressed regardless of whether~/.claude/exists.hooksobject → returnsfalse(falls through to the existing Claude detection).Why the wrapper substring match
Some Windows + Cursor users currently need a small PowerShell shim around
rtk hook cursorbecause Cursor 3.x silently ignorespermission: "ask"and Cursor on Windows ships hook stdin with leading UTF-8 BOMs. That issue is being addressed in #1718 — once it lands, the wrapper goes away and users go back to the nativertk hook cursorcommand directly. Until then, recognizing the wrapper as an rtk-aware hook avoids a confusing UX where the warning fires even though token savings are happening.Test plan
src/hooks/hook_check.rs::tests:test_cursor_3x_hook_registered_native_command—rtk hook cursordirectlytest_cursor_3x_hook_registered_wrapper_script— PowerShell wrapper invoking rtktest_cursor_3x_hook_registered_before_shell_execution— alternate hook keytest_cursor_3x_hook_not_registered_no_file— missinghooks.jsontest_cursor_3x_hook_not_registered_unrelated_command— non-rtk commandtest_cursor_3x_hook_not_registered_invalid_json— malformed JSONtest_cursor_3x_hook_not_registered_empty_hooks—hooks: {}empty~/.cursor/hooks.jsonregisteringrtk hook cursorand no~/.claude/directory →rtk gainruns without the "No hook installed" warning.~/.claude/present (no rtk entries) → still no warning (Cursor detection wins).~/.cursor/hooks.jsonmissing → falls through to existing behavior.Related issues
rtk init -g --agent cursorran) but the warning still fires. This PR addresses the post-installation visibility gap on the Cursor 3.x file format. Worth retesting on Linux with this branch.rtk hook cursormatch path is exercised. The two PRs are independent and can land in any order.Notes for reviewers
~/.cursor/hooks.json-only. Project-level<workspace>/.cursor/hooks.jsonis also a Cursor 3.x surface but I left it alone here — would prefer to do it as a follow-up if maintainers want, since it requires resolving the workspace cwd at the momentstatus()is called, which is non-trivial in the existing code.cmd.contains("rtk")branch is intentionally permissive to handle wrapper scripts whose path may not contain the literalrtk hook cursorsubstring (e.g.~/.cursor/hooks/my-rtk-shim.ps1). False positives here only suppress the warning — they don't change rewrite behavior. If maintainers prefer a stricter match (e.g. only the exactrtk hook cursorsubstring), happy to tighten it.~/.claude/settings.jsonregisteringrtk hook claudestill seeHookStatus::Okexactly as before.