Skip to content

fix(init): skip redundant hook warning during rtk init - #1013

Closed
andeart wants to merge 3 commits into
rtk-ai:developfrom
andeart:fix/redundant-init-warning
Closed

andeart wants to merge 3 commits into
rtk-ai:developfrom
andeart:fix/redundant-init-warning

Conversation

@andeart

@andeart andeart commented Apr 4, 2026 •

Copy link
Copy Markdown

Summary

This fixes #1011.

  • Skip maybe_warn() hook check when the command is Init, since it's about to install/update hooks itself
  • Suppresses the misleading "No hook installed" warning that printed during rtk init (no replacement message, init already announces its own actions)
  • Matches existing pattern where Gain already skips the check

Test plan

  • Pre-test: clean up any previous markers first, with rtk init -g --uninstall and rm ~/Library/Application\ Support/rtk/.hook_warn_last, then rebuild the binary.
  • cargo fmt --all && cargo clippy --all-targets && cargo test. All pass.
  • Manual testing: rtk init -g no longer prints the misleading "No hook installed" warning. rtk init --uninstall and --show stay clean too.

Important: All PRs must target the develop branch (not master).
See CONTRIBUTING.md for details.

When running `rtk init -g`, the hook check would fire before init
had a chance to install the hook, printing a confusing "No hook
installed - run rtk init -g" message. Replace that with an
"Installing RTK hook" message for Init, matching how Gain already
skips the check.
@andeart
andeart marked this pull request as ready for review April 4, 2026 05:50
@andeart andeart changed the title Skip redundant hook warning during rtk init fix(init): skip redundant hook warning during rtk init Apr 4, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks @andeart — #1011 is a real bug (verified, still present on develop), and skipping the hook-check for init is the right call.

I built and tested the branch. The fix works: rtk init -g no longer prints the misleading "No hook installed" warning. Two things on the implementation though:

  1. eprintln!("[rtk] Installing RTK hook") also fires for rtk init --uninstall. --uninstall is a flag on the Init command, so matches!(.., Commands::Init { .. }) matches it too. Tested — rtk init -g --uninstall prints:

    [rtk] Installing RTK hook
    RTK uninstalled:
      - Hook: ... removed
    

    "Installing" during an uninstall.

  2. The message sits in the generic hook-check block of run_cli. An "Installing…" notice belongs in init's own code (which already prints its output), not in this block.

The minimal fix is just to extend the skip condition, no extra message:

if !matches!(cli.command, Commands::Gain { .. } | Commands::Init { .. }) {
    hooks::hook_check::maybe_warn();
}

init already announces what it does. Could you simplify it that way? The diagnosis is spot-on — it's just the fix that's a bit over-built.

@andeart
andeart marked this pull request as draft May 17, 2026 20:57
@andeart
andeart marked this pull request as ready for review May 17, 2026 21:51
@andeart

andeart commented May 17, 2026

Copy link
Copy Markdown
Author

Thanks for the suggestion, @pszymkowiak . This is cleaner and more direct. I just updated the code if you could take another look when you have a moment please.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Tested against a compiled build of the current head (052c283). Small PR, one real gap.

The exemption at src/main.rs:1399 is a blanket match on the whole Init command:

// Warn if installed hook is outdated/missing (1/day, non-blocking).
// Skip for Gain (own inline hook warning) and Init (about to install/update hooks itself).
if !matches!(cli.command, Commands::Gain { .. } | Commands::Init { .. }) {
    hooks::hook_check::maybe_warn();
}

But Init covers every --agent target (cursor, windsurf, cline, kilocode, antigravity, hermes, ...), and only the Claude Code path actually touches the hook this warning is about. The other agent-init subflows (run_hermes_mode, run_kilocode_mode, etc. in src/hooks/init.rs) never write .claude/settings.json's PreToolUse entry or the legacy hook script — so the comment's rationale ("about to install/update hooks itself") doesn't hold for them.

Repro with a compiled build (~/.claude exists but has no hook registered, so status() returns Missing):

# baseline — warns correctly
rtk git status
# [rtk] /!\ No hook installed — run `rtk init -g` for automatic token savings

# init for an unrelated agent — no warning, even though it never touches the Claude hook
rtk init --agent hermes
# (no warning printed)

# confirms the Claude hook is still missing right after
rtk git log
# [rtk] /!\ No hook installed — run `rtk init -g` for automatic token savings

Low severity — it's a single missed notification per day (the rate-limit marker is only written when the warning actually fires, so the next non-Init command still warns normally), not a correctness/security issue. But it doesn't match the stated rationale for non-Claude agent targets. Might be worth narrowing the skip to Commands::Init { agent: None, .. } / the Claude-specific branch, or checking agent inside the condition, rather than exempting the whole command.

@andeart andeart closed this Sep 4, 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.

rtk init -g shows redundant "run rtk init -g" warning

2 participants