claude-code - 💡(How to fix) Fix [BUG] Bash output "+N lines" count is computed from total chars / terminal width, not actual newlines — undercounts hidden lines

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

In Claude Code's collapsed Bash-output preview, the +N lines (ctrl+r to expand) indicator does not reflect the actual number of hidden newline-separated lines. Instead, it is derived from a character-budget heuristic (Math.ceil(totalChars / terminalWidth) − 3), which systematically undercounts when the output has many short lines and overcounts when lines are very long.

Error Message

Error Messages/Logs

Root Cause

The indicator is the only signal a user has — before deciding to expand — about how much content was suppressed. A 56-line tool result that claims "32 lines" misleads the user into thinking the output is small. Worse: the value silently changes with terminal width, so the same command behaves differently across sessions.

Code Example

let M = f
  ? K.slice(z.length).split("\n").length
  : O;

---



---

timew export 2026-05-09 - 2026-05-15   # produced 53 entries / ~56 lines

---

var ZEH = 3, m19 = 10;          // ZEH = visible-lines const; m19 = width margin
let _ = Math.max($ - m19, 10);  // _ ≈ terminal width
let A = ZEH * _ * 4;            // budget = 12 × width chars
let f = K.length > A;
let M = f
  ? Math.max(O, Math.ceil(K.length / _) - ZEH)
  : O;
// → "+${M} lines"
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Summary

In Claude Code's collapsed Bash-output preview, the +N lines (ctrl+r to expand) indicator does not reflect the actual number of hidden newline-separated lines. Instead, it is derived from a character-budget heuristic (Math.ceil(totalChars / terminalWidth) − 3), which systematically undercounts when the output has many short lines and overcounts when lines are very long.

Why this matters

The indicator is the only signal a user has — before deciding to expand — about how much content was suppressed. A 56-line tool result that claims "32 lines" misleads the user into thinking the output is small. Worse: the value silently changes with terminal width, so the same command behaves differently across sessions.

What Should Happen?

Expected behavior

+N lines should reflect the actual number of newline-separated lines that are hidden, independent of terminal width or character density.

Suggested fix

Replace the character-budget heuristic with a direct newline count of the suppressed portion:

let M = f
  ? K.slice(z.length).split("\n").length
  : O;

(Plus minor adjustments for trailing newlines.)

Error Messages/Logs

Steps to Reproduce

Repro

  1. Run a command that produces ~50–60 short lines (e.g. JSON arrays, ls -1 of many short filenames):
    timew export 2026-05-09 - 2026-05-15   # produced 53 entries / ~56 lines
  2. Observe the collapsed view: 3 lines visible + "+29 lines" → total reported = 32.
  3. Expand with Ctrl+R. Real visible output = ~56 raw lines (~65 with wrapping).

The "+29" is wrong by ~24 lines. With a wider terminal the reported number drops further, with a narrower one it rises — even though the underlying byte content is unchanged.

Root cause (from claude-code 2.1.142 bundle)

EMK(H, $, q) in the rendering layer computes:

var ZEH = 3, m19 = 10;          // ZEH = visible-lines const; m19 = width margin
let _ = Math.max($ - m19, 10);  // _ ≈ terminal width
let A = ZEH * _ * 4;            // budget = 12 × width chars
let f = K.length > A;
let M = f
  ? Math.max(O, Math.ceil(K.length / _) - ZEH)
  : O;
// → "+${M} lines"

When the output exceeds the budget A, the displayed M is calculated from total character length divided by terminal width, minus the constant ZEH = 3. Real \n count is ignored. O (the true remaining-lines count from the visible chunk) is used only as a floor.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.142

Platform

Anthropic API

Operating System

Other Linux

Terminal/Shell

Other

Additional Information

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

+N lines should reflect the actual number of newline-separated lines that are hidden, independent of terminal width or character density.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING