Skip to content

fix(init): --agent cursor installs Cursor only and creates ~/.cursor#3000

Open
rNoz wants to merge 1 commit into
rtk-ai:developfrom
rNoz:fix/init-agent-cursor-directory
Open

fix(init): --agent cursor installs Cursor only and creates ~/.cursor#3000
rNoz wants to merge 1 commit into
rtk-ai:developfrom
rNoz:fix/init-agent-cursor-directory

Conversation

@rNoz

@rNoz rNoz commented Jul 14, 2026

Copy link
Copy Markdown

Summary

Two defects made rtk init -g --agent cursor fail / pollute the home dir:

  1. It fell through to the shared init path with install_claude derived only from !opencode, so it created RTK.md, CLAUDE.md, and patched settings.json under ~/.claude in addition to patching .cursor/hooks.json. On machines without ~/.claude it failed outright: Failed to create temp file in ~/.claude: No such file or directory.
  2. Even after removing the .claude writes, the Cursor path still failed on a fresh machine because install_cursor_hooks never created ~/.cursor before atomic_write placed its temp file there.

Fixes:

Root cause

  • src/main.rs, Commands::Init handler: install_claude = !opencode. Cursor is the only sibling agent that reaches the shared init path (Windsurf/Cline short-circuit earlier in hooks::init::run), so it incorrectly triggered the Claude install branch.
  • src/hooks/init.rs, install_cursor_hooks: wrote hooks.json via atomic_write without ensuring the parent directory exists.

Fix

// src/main.rs
let install_cursor = agent == Some(AgentTarget::Cursor);
let install_windsurf = agent == Some(AgentTarget::Windsurf);
let install_cline = agent == Some(AgentTarget::Cline);
let install_claude =
    !opencode && !install_cursor && !install_windsurf && !install_cline;

// src/hooks/init.rs (install_cursor_hooks)
if !dry_run {
    fs::create_dir_all(&cursor_dir)?;
}

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test --all: pass.
  • New tests/init_agent_cursor_test.rs:
    • agent_cursor_dry_run_never_touches_claude: asserts dry-run output contains no /.claude/ path and does patch /.cursor/.
    • agent_cursor_real_write_creates_no_claude_dir: non-dry-run install in a temp HOME: exits 0, never creates ~/.claude, and writes .cursor/hooks.json.
    • default_dry_run_still_installs_claude: regression: default init still installs Claude Code files.
  • cargo test --bin rtk hooks::init: 169 existing init tests pass (no regression).

E2E Validation

Tested locally and providing proofs (Screenshot). All working as expected:

image

rtk init -g --agent cursor fell through to the shared init path with
install_claude derived only from !opencode, so it created RTK.md,
CLAUDE.md, and patched settings.json under ~/.claude in addition to
patching .cursor/hooks.json. On machines without ~/.claude it failed
outright when creating the temp file.

Two fixes:
- Gate install_claude on the absence of a sibling agent target (Cursor,
  Windsurf, Cline) so only the default or explicit Claude target
  installs Claude Code files.
- Create ~/.cursor before patching hooks.json; atomic_write places its
  temp file in the target's parent, which failed on a fresh machine
  where the directory did not yet exist.

Closes rtk-ai#2097

@tapheret2 tapheret2 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.

Review: fix(init): --agent cursor installs Cursor only and creates ~/.cursor

Files: src/hooks/init.rs, src/main.rs, tests/init_agent_cursor_test.rs
Size: +93 / -1

Notes

  • Tests/fixtures present — good signal for correctness.

Thanks @rNoz — independent review on the patch.

@rNoz

rNoz commented Jul 15, 2026

Copy link
Copy Markdown
Author

Tested E2E locally with my local rnoz/integration branch. All working as expected. See the capture. Ready for review/merge.

@rNoz
rNoz marked this pull request as ready for review July 15, 2026 18:25
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.

rtk init -g --agent cursor fails bug: "rtk init -g --agent cursor" errors due to expecting $HOME/.claude

2 participants