fix(hook): cursor hook fails to rewrite commands due to incorrect exit code handling#1075
Open
sebastiancichos wants to merge 1 commit intortk-ai:developfrom
Open
fix(hook): cursor hook fails to rewrite commands due to incorrect exit code handling#1075sebastiancichos wants to merge 1 commit intortk-ai:developfrom
sebastiancichos wants to merge 1 commit intortk-ai:developfrom
Conversation
The Cursor agent hook failed to rewrite shell commands because it treated exit code 3 from `rtk rewrite` as a failure condition. Exit code 3 actually indicates a successful rewrite, but the `||` operator treated ANY non-zero exit as failure, causing the hook to always exit early with an empty JSON response. Changes: - Capture exit code explicitly instead of using `||` - Accept both exit 0 (no rewrite) and exit 3 (rewritten) as success - Only treat other exit codes as actual errors Before: Commands were never rewritten, 0% token savings After: Transparent command rewriting works as designed, 60-90% savings
a4fea51 to
3aa08b2
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
The Cursor agent hook (
~/.cursor/hooks/rtk-rewrite.sh) fails to rewrite shell commands because it incorrectly handles the exit code fromrtk rewrite. The hook treats exit code 3 (which indicates a successful rewrite) as a failure condition.Bug Description
Current Behavior (Broken)
All shell commands pass through unchanged - RTK never rewrites them.
Expected Behavior
Shell commands like
git status,ls,cat, etc. should be automatically rewritten to their RTK equivalents.Root Cause
In
hooks/cursor/rtk-rewrite.sh(line 43):The problem: The comment says "exits 1 when there's no rewrite", but
rtk rewriteactually returns exit code 3 when it successfully rewrites a command.The
||operator treats ANY non-zero exit code as failure, so:{}{}Result: Commands are never rewritten because the hook always exits early.
Evidence
Test showing
rtk rewriteexit codes:Hook behavior with current code:
Fix
Replace the incorrect exit code handling:
Before:
After:
Testing
After applying the fix:
Hook now correctly rewrites commands and RTK tracking works:
Impact
Without this fix:
rtkWith this fix:
Checklist
hooks/cursor/rtk-rewrite.shrtk rewritecommands