Repository navigation
Description
Summary
The Cursor integration (rtk init --global --agent cursor) does not rewrite shell commands. Both rtk hook cursor and hooks/cursor/rtk-rewrite.sh treat rtk rewrite exit code 3 as a failure and return {} (pass-through), so commands run unchanged and RTK filtering never applies.
This appears to be the same root cause as #2200 (OpenClaw plugin), but it also affects the official Cursor hook shipped with RTK.
Environment
- RTK: 0.42.3
- OS: macOS (darwin 25.4.0)
- Agent: Cursor IDE (Agent mode,
preToolUsehook) - Hook config:
~/.cursor/hooks.jsonwithmatcher: "Shell"andcommand: "rtk hook cursor"
Steps to reproduce
- Install RTK and run:
rtk init --global --agent cursor
- Restart Cursor.
- Ask the agent to run:
git status
- Observe raw
git statusoutput instead of RTK-compact output.
Expected behavior
git status should be transparently rewritten to rtk git status, and the agent should see compact output like:
* branch-name
clean — nothing to commit
Actual behavior
The command runs as plain git status. rtk gain --history does not record the command. Simulating the hook also returns {}:
printf '%s' '{"tool_input":{"command":"git status"}}' | rtk hook cursor
# → {}Root cause
rtk rewrite returns exit code 3 when it has a rewrite suggestion, but the hook treats any non-zero exit as failure:
# hooks/cursor/rtk-rewrite.sh (line 47)
REWRITTEN=$(rtk rewrite "$CMD" 2>/dev/null) || { echo '{}'; exit 0; }Even though stdout contains the correct rewrite (rtk git status), the || branch runs and discards it.
Verified manually:
$ rtk rewrite "git status"
rtk git status
$ echo $?
3The script comment says "rtk rewrite exits 1 when there's no rewrite", but successful rewrites also use a non-zero exit code (3), which breaks the hook logic.
Workaround (confirmed working)
Replace the hook command with a wrapper that captures stdout regardless of exit code:
REWRITTEN=$(rtk rewrite "$CMD" 2>/dev/null || true)
if [ -z "$REWRITTEN" ] || [ "$CMD" = "$REWRITTEN" ]; then
echo '{}'
exit 0
fi
jq -n --arg cmd "$REWRITTEN" '{
"permission": "allow",
"updated_input": { "command": $cmd }
}'After applying this workaround, git status is correctly rewritten and RTK-compact output is returned.
Suggested fix
- Fix
rtk rewriteto exit 0 on successful rewrite (breaking change for callers that rely on exit 3), or - Update all hook integrations (
hooks/cursor/rtk-rewrite.sh,rtk hook cursor, OpenClaw, etc.) to read stdout on exit code 3 instead of treating it as an error.
Activity
pszymkowiak commentedon Jun 11, 2026
🔍 Automated Triage
bughighSummary
Cursor hook discards all rewrites because
rtk rewriteexit code 3 is treated as failure; fix by capturing stdout regardless of exit code in rtk-rewrite.sh📁 Relevant files
hooks/cursor/rtk-rewrite.shTriaged automatically by wshm · This is an automated analysis, not a human review.
TuttiFruty commentedon Jun 24, 2026
I fixed this by adding a .cursor/cli-config.json with :
Root cause is that if you run Cursor in a Unsandboxed you will never have this config file that rtk check to know if it can wrap the command or not. Hence the issue.
Could be the same for your setup.
noamgal-c commentedon Jun 24, 2026
another possible workaround is to create the following script for example at ~/.cursor/hooks/rtk-cursor.sh:
and to change the cursor user hooks (
~/.curosr/hooks.json) to"command": "./hooks/rtk-cursor.sh",fix(hook): handle AskRewrite in Cursor hook when no rules configured
fix(hook): handle AskRewrite in Cursor hook when no rules configured
fix(hook): handle AskRewrite in Cursor hook when no rules configured
fix(hook): handle AskRewrite in Cursor hook when no rules configured
!15172 merge bump-rtk-0.44.0 into main