Skip to content

feat: add Cursor Agent support via --agent flag#595

Open
moisei wants to merge 1 commit intortk-ai:masterfrom
moisei:feat/cursor-agent-support
Open

feat: add Cursor Agent support via --agent flag#595
moisei wants to merge 1 commit intortk-ai:masterfrom
moisei:feat/cursor-agent-support

Conversation

@moisei
Copy link

@moisei moisei commented Mar 14, 2026

Summary

Adds Cursor Agent support to RTK via a new --agent <name> flag on rtk init.

  • rtk init -g --agent cursor installs a preToolUse hook in ~/.cursor/hooks.json that rewrites shell commands through rtk rewrite, using Cursor's JSON format ({permission, updated_input})
  • Works with both Cursor editor and cursor-cli — they share ~/.cursor/hooks.json, so a single installation covers both
  • rtk init --show now reports Cursor hook and hooks.json status alongside existing Claude Code / OpenCode status
  • rtk init -g --uninstall also removes Cursor artifacts (hook script + hooks.json entry)
  • rtk discover adds a note when Cursor hooks are detected, directing users to rtk gain for Cursor session analytics (Cursor transcripts use a text-only format without structured tool_use/tool_result blocks, so discover cannot extract commands from them)

Design decisions

  • --agent is an extensible enum (claude, cursor), not a boolean flag — ready for future agents (Windsurf, Zed, etc.)
  • Additive behavior: --agent cursor installs Cursor hooks ON TOP of the default Claude Code installation. Without --agent, behavior is 100% unchanged.
  • --opencode stays separate for backward compatibility
  • Cursor hook uses preToolUse with matcher: "Shell" and returns updated_input to rewrite commands — functionally identical to Claude Code's PreToolUse but with Cursor's JSON schema

cursor-cli note

The preToolUse hook mechanism is shared between Cursor's editor agent and its CLI agent (cursor-cli). Both read hooks from ~/.cursor/hooks.json, so rtk init -g --agent cursor covers both without any additional setup.

Files changed

File Change
hooks/cursor-rtk-rewrite.sh New: Cursor-format hook script (thin delegator to rtk rewrite)
src/main.rs Add --agent <name> flag with AgentTarget enum
src/init.rs Cursor install/uninstall/show functions, hooks.json patching, unit tests
src/discover/provider.rs Doc comment update noting Cursor limitation
src/discover/report.rs Cursor note in discover output when hook detected

Test plan

  • cargo build — 0 errors
  • cargo test — 899 passed, 0 failed
  • rtk init --help shows --agent with claude and cursor values
  • rtk init -g --agent cursor --auto-patch installs hook + patches hooks.json
  • rtk init --show reports Cursor hook status
  • rtk init -g --uninstall removes Cursor artifacts
  • Cursor agent session with hook active rewrites git statusrtk git status
  • rtk gain --history shows tracked commands from Cursor session

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
@moisei moisei force-pushed the feat/cursor-agent-support branch from bd25afd to a8a73d4 Compare March 15, 2026 00:01
@moisei moisei changed the title feat: add Cursor IDE support via --agent flag feat: add Cursor Agent support via --agent flag Mar 15, 2026
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.

1 participant