Skip to content

fix(init): detect and clean up orphaned .github/hooks/rtk-rewrite.json with broken hook command - #837

Closed
rolf-quadra wants to merge 1 commit into
rtk-ai:developfrom
rolf-quadra:fix/orphaned-copilot-hook-json
Closed

rolf-quadra wants to merge 1 commit into
rtk-ai:developfrom
rolf-quadra:fix/orphaned-copilot-hook-json

Conversation

@rolf-quadra

Copy link
Copy Markdown

Fixes #836

What

  • rtk init --show: warns when .github/hooks/rtk-rewrite.json exists with "command": "rtk hook" (missing subcommand), with actionable guidance pointing to rtk gain --failures and the fix
  • rtk init -g --uninstall: removes the broken file as part of standard cleanup (only when the command is the broken "rtk hook" — a correctly configured "rtk hook copilot" file is left untouched)

Why

Users who ran an earlier rtk init --copilot (introduced in #605) got .github/hooks/rtk-rewrite.json with "command": "rtk hook" (no subcommand). Since rtk hook requires gemini or copilot, it prints help and exits non-zero on every Bash tool call. RTK silently logs a parse_failure with raw_command = "hook" and fallback_succeeded = 0 in history.db, inflating rtk gain --failures stats with no visible error to the user.

The pending Copilot integration (#823) correctly generates "rtk hook copilot", but neither rtk init --show nor rtk init --uninstall check .github/hooks/ for these orphaned files.

Changes

src/init.rs only — 66 lines added, no deletions, no new dependencies.

Test

# Reproduce
echo '{"hooks":{"PreToolUse":[{"type":"command","command":"rtk hook","cwd":".","timeout":5}]}}' \
  > .github/hooks/rtk-rewrite.json

# Should warn
rtk init --show

# Should remove
rtk init -g --uninstall
ls .github/hooks/rtk-rewrite.json  # should be gone

@CLAassistant

CLAassistant commented Mar 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aeppling

Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

Users who ran an earlier rtk init --copilot (from commit rtk-ai#605) ended up
with .github/hooks/rtk-rewrite.json containing "command": "rtk hook"
(missing subcommand). This causes RTK to log a spurious parse_failure on
every Bash tool call, inflating rtk gain --failures stats silently.

- rtk init --show: warns when the broken file is detected, with actionable
  guidance pointing to rtk gain --failures and the fix
- rtk init -g --uninstall: removes the broken file as part of standard
  cleanup (only when command is the broken "rtk hook", leaves a correctly
  configured "rtk hook copilot" file untouched)

Fixes rtk-ai#836
@rolf-quadra
rolf-quadra force-pushed the fix/orphaned-copilot-hook-json branch from b712f13 to 3f9e822 Compare March 26, 2026 23:30
@rolf-quadra

Copy link
Copy Markdown
Author

Refactored to comply with the repository reorg.

@jeziellopes

Copy link
Copy Markdown
Contributor

Hi @rolf-quadra — just wanted to flag that PR #728 (feat(init): complete Copilot lifecycle) already covers the scenario you're fixing here:

  • --uninstall --agent copilot removes .github/hooks/rtk-rewrite.json cleanly
  • rtk init --show gains [ok]/[--] status for both Copilot files

If #728 gets merged first this PR may become redundant, but if yours lands first the orphaned-hook detection would be a nice complement. Either way, thanks for tackling #836 — it's the same root cause I ran into.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

@rtk-release-bot rtk-release-bot Bot closed this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] .github/hooks/rtk-rewrite.json with broken "rtk hook" command causes spurious parse_failure entries per session

5 participants