Skip to content

Windows (Git Bash): the hook rewrites grep over a large glob into rtk.exe, which fails with "Argument list too long" and the command never runs #4210

Open

Description

@HetCreep

Thanks for rtk. We hit this on Windows and it seemed worth writing up because the agent's command does not run at all, which CONTRIBUTING's "Never Block" is meant to rule out.

Summary

Under Git Bash, the hook rewrites grep … <glob> into rtk grep … <glob>. The shell expands the glob into the argument list in both cases, but rtk.exe is a native Windows program, so the expanded command line has to fit Windows' 32,767-character limit. The MSYS grep it replaces has no such limit. A grep that works starts failing once the hook rewrites it:

/usr/bin/bash: line 1: /c/Users/<user>/.local/bin/rtk: Argument list too long

(exit code 126). Because the failure happens when bash execs rtk.exe, rtk never starts, so a fallback inside rtk cannot catch it; the decision has to be made at rewrite time.

Reproduction (rtk 0.49.0, Windows 11, Git Bash)

mkdir -p /tmp/rtk-e2big && cd /tmp/rtk-e2big
for i in $(seq -w 1 600); do echo "line $i" > "some-reasonably-long-file-name-for-the-glob-test-$i.txt"; done
echo /tmp/rtk-e2big/*.txt | wc -c                 # 43200 here

rtk rewrite 'grep -li zzz /tmp/rtk-e2big/*.txt'   # rtk grep -li zzz /tmp/rtk-e2big/*.txt   (exit 3)

/usr/bin/grep -li zzz /tmp/rtk-e2big/*.txt; echo "rc=$?"   # rc=1: no match, ran normally
rtk grep -li zzz /tmp/rtk-e2big/*.txt; echo "rc=$?"        # Argument list too long, rc=126

Typed as a plain grep -li zzz /tmp/rtk-e2big/*.txt in a Claude Code Bash call with rtk hook claude installed, the hook rewrites it and the call fails with the same error. With 60 files (about 10,900 characters) the rewritten command runs fine, so this only bites past the Windows limit.

Expected

The command runs, either rewritten or left as it was.

Suggested fix

The hook cannot know the expanded length, because the shell expands the glob after the rewrite. One option is to leave a segment un-rewritten on Windows when it contains an unquoted glob character (*, ?, [), perhaps only when the hook runs under an MSYS or Cygwin shell. The exclude_commands workaround works but costs the rewrite for every grep.

We only tested Git Bash; PowerShell and cmd may behave differently. Happy to test a fix on Windows.

Activity

  1. HetCreep commented on Oct 23, 2026

    @HetCreep
    Author

    I looked at a fix for this and stopped before writing code, because every option I can see changes how much the hook rewrites on Windows, which is your call. Notes at develop 32b2ec43:

    Options:

    1. Do not rewrite a command with an unquoted *, ? or [ on Windows (or only when MSYSTEM says Git Bash/MSYS). Fixes the reported case, but gives up the rewrite for most glob grep/ls/find there, where nearly all globs expand to a few hundred characters and work today.
    2. Skip the rewrite when the typed command is already near the cap (for example over 30,000 characters). Small and safe, but it does not cover this report, where the typed command is short and the expansion is what overflows.
    3. Keep the current behaviour and document exclude_commands = ["grep"] as the workaround.

    For weighing it: in my own history (about 7,000 hook-rewritten greps over two months on Windows) no glob came close to the cap, so this is rare, it fails loudly (rc 126 with a clear message) and loses no data. Against that, CONTRIBUTING.md:56 and docs/guide/getting-started/supported-agents.md:341 say hooks never stop a command from running. Happy to send a PR for whichever you prefer.

    Produced with AI assistance (Claude Code) operated by me (HetCreep); the code was read at 32b2ec43, nothing was rerun for this comment.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions