RangeError: String.repeat with negative count in text padding (pNq)

Resolved 💬 2 comments Opened Feb 24, 2026 by deep-name Closed Mar 25, 2026

Bug Description

String.repeat() is called with a negative value (-5) in the CLI's text rendering/padding layer, causing a RangeError. This crashes the current operation.

Steps to Reproduce

  1. Run a skill/workflow that produces lengthy structured output (in my case, /simstim during an SDD generation phase)
  2. Terminal width is standard (not extremely narrow, but possibly in a split pane or slightly constrained)
  3. Error fires during text rendering — appears to be a padding/indentation calculation

This has happened twice in the same workflow phase (SDD generation), suggesting it's deterministic for certain content widths.

Error Output

ERROR Invalid count value: -5

  at String.repeat (<anonymous>)
  pNq (cli.js:12352:207)
  E3  (cli.js:288:20890)
  M_  (cli.js:288:39409)
  VC  (cli.js:288:50095)
  mF  (cli.js:288:86675)
  c16 (cli.js:288:85644)
  Vi  (cli.js:288:85466)
  w0  (cli.js:288:82234)
  W1  (cli.js:288:6445)

Root Cause Analysis

The pNq function computes a padding width as something like availableWidth - contentWidth. When content (a long line, URL, path, or code block) exceeds the available terminal column space, this goes negative. The negative value is passed directly to String.repeat() which throws a RangeError.

Suggested Fix

Clamp the repeat count to a non-negative value:

// Before
" ".repeat(paddingWidth)

// After
" ".repeat(Math.max(0, paddingWidth))

Environment

  • Claude Code version: Latest (installed via npm)
  • Node.js: v24.11.1
  • OS: Linux 6.16.12+deb13-amd64 (Debian)
  • Terminal: Standard terminal, possibly constrained width
  • CLI path: ~/.config/nvm/versions/node/v24.11.1/lib/node_modules/@anthropic-ai/claude-code/cli.js

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗