Skip to content

Comments

feat(init): add Cursor support (rtk init --cursor)#254

Open
sahilmgandhi wants to merge 1 commit intortk-ai:masterfrom
sahilmgandhi:feat/cursor-init
Open

feat(init): add Cursor support (rtk init --cursor)#254
sahilmgandhi wants to merge 1 commit intortk-ai:masterfrom
sahilmgandhi:feat/cursor-init

Conversation

@sahilmgandhi
Copy link

@sahilmgandhi sahilmgandhi commented Feb 23, 2026

Summary

I find myself switching between Cursor (via the agent cli) and Claude code. So making this PR to add cursor support and make it generic enough to add codex, or any other support in the future.

  • rtk init --cursor installs RTK for Cursor Agent: hook script (preToolUse for Shell), rules file (rtk.mdc), and hooks.json registration
  • Refactored init system with InitTarget enum and shared helpers (patch_json_registry, ensure_agent_hook_installed) so adding future agents (Codex, OpenCode) requires only a new enum variant + one run_<agent>_mode function
  • Hook script auto-detects Cursor vs Claude Code from payload shape, with RTK_HOOK_MODE=cursor|claude env var override for edge cases
  • Clap conflicts_with_all prevents invalid flag combos (--cursor --claude-md, --cursor --hook-only)
  • Safe JSON handling: no panics on malformed hooks.json (array, null, wrong types)
  • Windows #[cfg(not(unix))] guard with clear error since hook is bash-only

Changes

File Change
src/init.rs InitTarget enum, run_cursor_mode(), patch_json_registry() (generic JSON patcher shared by Claude + Cursor), ensure_agent_hook_installed() (replaces old Claude-specific duplicate), uninstall_cursor(), show_cursor_config(), prepare_cursor_paths(), insert_cursor_hook_entry() with safe type checks. Windows guard. 6 new tests for Cursor hook detection/removal.
src/main.rs --cursor flag with conflicts_with_all, routes to InitTarget
hooks/rtk-rewrite.sh Cursor detection from payload (hook_event_name / cursor_version), RTK_HOOK_MODE env override, dual JSON output format (Claude hookSpecificOutput.updatedInput vs Cursor decision + updated_input)
hooks/rtk-cursor-rules.mdc Cursor rules file with RTK command mappings (native rewrites + rtk err custom rules + exceptions)
CHANGELOG.md Unreleased section for Cursor support
CLAUDE.md Updated architecture docs: init system, adding new agents
README.md Cursor init usage examples in init matrix table

Test plan

  • cargo fmt --all passes
  • cargo clippy --all-targets — no new warnings
  • cargo test init:: — 30/30 tests pass (6 new for Cursor)
  • cargo test --all — 418/418 tests pass
  • Manual test: rtk init --cursor in a project directory
  • Manual test: rtk init --cursor -g for global install
  • Manual test: rtk init --cursor --show shows status
  • Manual test: rtk init --cursor -g --uninstall removes artifacts
  • Manual test: verify Cursor rewrites git statusrtk git status
Manual Test Results

  ┌──────────────────────────────────┬────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  │               Test               │ Result │                                                                            Notes                                                                            │
  ├──────────────────────────────────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ rtk init --cursor (local)        │ PASS   │ Creates .cursor/hooks/rtk-rewrite.sh (executable), .cursor/rules/rtk.mdc, and hooks.json (with --auto-patch)                                                │
  ├──────────────────────────────────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ rtk init --cursor -g (global)    │ PASS   │ Creates ~/.cursor/hooks/rtk-rewrite.sh, ~/.cursor/rules/rtk.mdc, and ~/.cursor/hooks.json. Idempotent on re-run                                             │
  ├──────────────────────────────────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ rtk init --cursor --show         │ PASS   │ Shows status for both global and project scopes with correct icons                                                                                          │
  ├──────────────────────────────────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ rtk init --cursor -g --uninstall │ PASS   │ Removes hook, rules, and RTK entry from hooks.json. Show confirms removal                                                                                   │
  ├──────────────────────────────────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ Cursor rewrite hook              │ PASS   │ git status → rtk git status, cargo test → rtk cargo test. Correct Cursor JSON format. RTK_HOOK_MODE override works both ways. Claude Code format unaffected │
  └──────────────────────────────────┴────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Closes #213

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.

feat: add support for cursor

1 participant