feat: add Cursor Agent support via --agent flag#595
Open
moisei wants to merge 1 commit intortk-ai:masterfrom
Open
feat: add Cursor Agent support via --agent flag#595moisei wants to merge 1 commit intortk-ai:masterfrom
moisei wants to merge 1 commit intortk-ai:masterfrom
Conversation
Add `rtk init -g --agent cursor` to install RTK hooks for Cursor Agent.
Cursor's preToolUse hook supports command rewriting via updated_input,
functionally identical to Claude Code's PreToolUse. Works with both the
Cursor editor and cursor-cli (they share ~/.cursor/hooks.json).
Changes:
- New `--agent <name>` flag (claude|cursor) on `rtk init`, extensible
for future agents. Default is claude (backward compatible).
- Cursor hook script (hooks/cursor-rtk-rewrite.sh) outputs Cursor's
JSON format: {permission, updated_input} vs Claude's hookSpecificOutput.
- `rtk init --show` reports Cursor hook and hooks.json status.
- `rtk init -g --uninstall` removes Cursor artifacts.
- `rtk discover` notes that Cursor sessions are tracked via `rtk gain`
(Cursor transcripts lack structured tool_use/tool_result blocks).
- Unit tests for Cursor hooks.json patching, detection, and removal.
Made-with: Cursor
bd25afd to
a8a73d4
Compare
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 Cursor Agent support to RTK via a new
--agent <name>flag onrtk init.rtk init -g --agent cursorinstalls apreToolUsehook in~/.cursor/hooks.jsonthat rewrites shell commands throughrtk rewrite, using Cursor's JSON format ({permission, updated_input})~/.cursor/hooks.json, so a single installation covers bothrtk init --shownow reports Cursor hook and hooks.json status alongside existing Claude Code / OpenCode statusrtk init -g --uninstallalso removes Cursor artifacts (hook script + hooks.json entry)rtk discoveradds a note when Cursor hooks are detected, directing users tortk gainfor Cursor session analytics (Cursor transcripts use a text-only format without structuredtool_use/tool_resultblocks, so discover cannot extract commands from them)Design decisions
--agentis an extensible enum (claude,cursor), not a boolean flag — ready for future agents (Windsurf, Zed, etc.)--agent cursorinstalls Cursor hooks ON TOP of the default Claude Code installation. Without--agent, behavior is 100% unchanged.--opencodestays separate for backward compatibilitypreToolUsewithmatcher: "Shell"and returnsupdated_inputto rewrite commands — functionally identical to Claude Code'sPreToolUsebut with Cursor's JSON schemacursor-cli note
The
preToolUsehook mechanism is shared between Cursor's editor agent and its CLI agent (cursor-cli). Both read hooks from~/.cursor/hooks.json, sortk init -g --agent cursorcovers both without any additional setup.Files changed
hooks/cursor-rtk-rewrite.shrtk rewrite)src/main.rs--agent <name>flag withAgentTargetenumsrc/init.rssrc/discover/provider.rssrc/discover/report.rsTest plan
cargo build— 0 errorscargo test— 899 passed, 0 failedrtk init --helpshows--agentwithclaudeandcursorvaluesrtk init -g --agent cursor --auto-patchinstalls hook + patches hooks.jsonrtk init --showreports Cursor hook statusrtk init -g --uninstallremoves Cursor artifactsgit status→rtk git statusrtk gain --historyshows tracked commands from Cursor session