Skip to content

[BUG] head -N with multiple files rewrites to invalid rtk read file1 file2 ... --max-lines N #1362

@pjcau

Description

@pjcau

Summary

rtk rewrite turns head -N file1 file2 ... into rtk read file1 file2 ... --max-lines N, but rtk read only accepts a single <FILE> argument. When invoked with multiple files, rtk read falls through to the system read command (/usr/bin/read on macOS, which is a POSIX wrapper around the shell builtin), which interprets the first filename as a variable name and fails with "not a valid identifier".

Same class of bug as #989 (cat multi-file, fixed) and #1108 (tail -N).

Repro

$ rtk --version
rtk 0.37.0   # also confirmed on 0.31.0

$ rtk rewrite "head -3 /tmp/a /tmp/b /tmp/c"
rtk read /tmp/a /tmp/b /tmp/c --max-lines 3

$ rtk read /tmp/a /tmp/b /tmp/c --max-lines 3
/usr/bin/read: line 4: read: `/tmp/a': not a valid identifier
$ echo $?
0   # silent failure — exit 0 despite error

Real-world Claude Code failure:

$ head -5 .claude/skills/generate/SKILL.md .claude/skills/enclosure-design/SKILL.md
Exit code 1
/usr/bin/read: line 4: read: `.claude/skills/generate/SKILL.md': not a valid identifier

Environment

  • OS: macOS (Darwin 25.2.0)
  • rtk: 0.37.0 (also 0.31.0)
  • Claude Code hook v2 (auto-patched via rtk init -g --auto-patch)

Expected

Either:

  1. rtk rewrite returns exit 1 (no rewrite) when head -N has >1 file argument, so the shell runs native head — consistent with the cat fix in Cat multiple files result in an error #989.
  2. rtk read natively supports multiple files.

Workaround

Use rtk proxy head -N file1 file2 ... to bypass the rewrite, or use editor/IDE file-read tools that don't go through Bash.

Related

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingeffort-smallQuelques heures, 1 fichierfilter-qualityFilter produces incorrect/truncated signalgood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions