Skip to content

head -N rewritten to whole-file compressed view folds structure without inline markers — false-positive "orphaned }" nearly triggered a wrong edit #3046

Closed as duplicate

Description

@cyh7789

Summary

head -30 <file> executed through the rtk rewrite hook (Claude Code PreToolUse) returned what appears to be a whole-file compressed view instead of the first 30 lines: the output ended with [124 more lines] for a 154-line file, and content from beyond line 30 was folded into the visible portion. Function bodies were elided without any inline marker at the fold point, which caused a dangerous false positive.

What happened

File: a 154-line ~/.zshrc containing (structure sanitized):

L10-L32   various export PATH=... lines
L61       git_branch() {
L62         git branch 2>/dev/null | ...
L63       }
L67       PROMPT='...'
...
L154      EOF

Command issued by the agent: head -30 ~/.zshrc

Output received (abridged): a mixed view where the closing brace from line 63 appeared directly between two export PATH lines, with the function header git_branch() { (line 61) folded away:

export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"
}
export PATH="..."
...
[124 more lines]

Consequence

The LLM agent reading this output concluded the file contained an orphaned } (syntax error) and proposed editing the user's shell config to remove it. The file was in fact perfectly valid (zsh -n clean); the brace was a normal function closer whose opening line had been silently folded. The edit was only avoided because a later Read/grep -n of the raw file contradicted the compressed view.

Why this matters

Related open issues (#2204 silent truncation without marker, #2806 rg false negatives, #1296/#2665 git log silent truncation) all describe omission — the LLM misses data. This case is the more dangerous direction: the rewritten view fabricated an apparent defect that triggered a concrete (wrong) modification action on a user's config file. Silent truncation misleads scope; silent folding misleads content.

Suggestions

  1. Preserve head -N semantics — return only the first N lines; a bounded read is already token-cheap and should not be replaced by a whole-file summary.
  2. Wherever compression folds lines, emit an inline elision marker at the fold point (e.g. [... 2 lines folded]), not just a trailing total count. A trailing [124 more lines] does not tell the reader that interior lines are missing.

rtk 0.43.0 (homebrew), macOS, invoked via Claude Code PreToolUse hook rewrite.

Activity

  1. pszymkowiak commented on Jul 18, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 88%

    Summary

    rtk's hook rewrite of head -N returns a whole-file compressed/folded view without inline elision markers, causing the LLM to misread folded content as a syntax defect and nearly make an incorrect edit — fix by preserving head -N bounded semantics and adding inline fold markers.


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

  2. albatrossflyon-coder commented on Jul 19, 2026

    @albatrossflyon-coder
    Contributor

    I'd like to work on this one. Planning to reproduce with a concrete large-file head -N case first, then trace how the rewrite folds into the compressed view and look at adding inline elision markers so bounded output doesn't read as the whole file.

  3. Yohjisakamoto commented on Jul 22, 2026

    @Yohjisakamoto

    Your near-miss where RTK folding almost triggered a wrong edit shows why token savings must be evaluated against task correctness. Tura’s DeepSWE benchmark measures completed tasks and verifier outcomes, finding fewer agent rounds cut about 80% of overhead. Would you evaluate it? https://turaai.net/docs#benchmark-current-test-set-record

  4. KuSh commented on Sep 13, 2026

    @KuSh
    Collaborator

    Closing as a duplicate of #3421, which tracks the same problem with the more complete discussion. Please follow up there; if your case differs in a way that issue does not cover, comment here and it can be reopened.

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:clibugpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions