Skip to content

hooks.exclude_commands does not apply to head/tail rewrites #2363

Closed

Description

@liljamesjohn

Summary

Entries in [hooks] exclude_commands have no effect on the head -N file / tail -n N file rewrites. The same entries work for other commands.

Environment

rtk 0.42.3, macOS (Homebrew), Claude Code hook (rtk hook claude).

Reproduction

Config:

[hooks]
exclude_commands = ["head", "tail", "rg"]
$ rtk hook check "rg -n foo src"
No rewrite for: rg -n foo src          # exclusion works

$ rtk hook check "head -20 package.json"
rtk read package.json --max-lines 20   # exclusion ignored

Cause

In src/discover/registry.rs (develop), rewrite_segment_inner short-circuits head - / tail to rewrite_line_range() (around line 786) before the classify path reaches is_excluded() (around line 805). The short-circuit never consults the exclusion list.

Why it matters

rtk read --max-lines N returns a condensed view with elision markers rather than the verbatim first N lines:

$ head -3 package.json
{
}
[30 more lines]

That is the right trade for most output, but users who want verbatim head behavior reach for exclude_commands, the documented opt-out, and it silently does nothing for these commands.

Expected

exclude_commands applies to every rewrite path, including the head/tail short-circuit.

Activity

  1. added
    bug
    good first issue
    on Jun 10, 2026
  2. pszymkowiak commented on Jun 10, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 95%

    Summary

    exclude_commands config is silently ignored for head/tail rewrites due to early short-circuit before the exclusion check in rewrite_segment_inner; fix by moving the is_excluded() guard before the head/tail branch.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/discover/registry.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. hgunduzoglu commented on Jun 11, 2026

    @hgunduzoglu
    Contributor

    I'm taking this one — will follow up with a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:configbuggood first issuepriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions