Skip to content

feat: add forceMaxWidth config override#501

Merged
jarrodwatts merged 3 commits into
jarrodwatts:mainfrom
x1han:feat/force-max-width
May 6, 2026
Merged

feat: add forceMaxWidth config override#501
jarrodwatts merged 3 commits into
jarrodwatts:mainfrom
x1han:feat/force-max-width

Conversation

@x1han

@x1han x1han commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an explicit forceMaxWidth config option so users can tell claude-hud to use maxWidth even when a terminal width is detected.

This fixes a real issue I hit on Linux when running claude-hud inside the Claude Code statusline environment: the HUD process saw a much smaller width than the actual visible terminal width, so long lines were unnecessarily truncated with ....

With this change:

  • default behavior is unchanged
  • maxWidth still works as a fallback by default
  • users can opt in to forceMaxWidth: true when width detection is inaccurate

Problem

On my Linux setup, Claude Code itself was displayed in a wide terminal, but the claude-hud subprocess only detected a narrow width. As a result, fields like:

  • long branch names
  • session token lines

were truncated even though there was enough visible horizontal space.

This was a width detection mismatch between the HUD subprocess and the actual terminal UI.

Solution

Introduce:

{
  "maxWidth": 300,
  "forceMaxWidth": true
}

When forceMaxWidth is enabled, claude-hud uses the configured maxWidth instead of the detected terminal width.

Why this approach

  • no magic-number heuristic
  • no default behavior change
  • fully opt-in
  • easy to explain and document

Test plan

  • Verify default behavior is unchanged when forceMaxWidth is not set
  • Verify detected width is still used by default
  • Verify maxWidth overrides detected width when forceMaxWidth: true
  • Verify config parsing accepts forceMaxWidth: true
  • Verify invalid forceMaxWidth values fall back to false
  • npm test

Example

{
  "lineLayout": "expanded",
  "maxWidth": 300,
  "forceMaxWidth": true
}

This resolved the truncation issue for me on Linux in Claude Code's statusline environment.

🤖 Generated with Claude Code

@x1han x1han requested a review from jarrodwatts as a code owner April 27, 2026 12:28

@jarrodwatts jarrodwatts left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused report and implementation. I am holding this for changes before it can merge.

Required fixes:

  • Remove all committed dist/ artifacts. This repo keeps PR review on source/tests/docs; CI builds dist after merge.
  • Restore the existing showSessionName default coverage that was replaced in tests/config.test.js. Add forceMaxWidth tests as new coverage.
  • Restore or preserve stderr-width fallback coverage in tests/render-width.test.js.
  • Add coverage for forceMaxWidth with null/invalid maxWidth so the opt-in cannot accidentally erase detected width behavior.

This overlaps the active width-detection PRs (#510/#511), so keeping the diff source-only and narrowly tested matters here.

@x1han

x1han commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

Updated.

  • removed committed dist artifacts from the PR
  • restored the existing showSessionName default coverage
  • restored stderr-width fallback coverage
  • added forceMaxWidth coverage for null/invalid maxWidth

Full test suite passes.

x1han and others added 2 commits April 30, 2026 11:01
Allow users to explicitly apply maxWidth even when terminal width detection returns a smaller value, which helps in subprocess-driven statusline environments on Linux.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Restore the replaced config and width-fallback coverage, add guardrails for invalid forceMaxWidth inputs, and drop generated dist changes from the PR so review stays source-focused.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@x1han x1han force-pushed the feat/force-max-width branch from 5cb9788 to 721cfba Compare April 30, 2026 03:06

@jarrodwatts jarrodwatts left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security, regression, and maintainability review passed after dist artifacts were removed and width fallback coverage was restored. The new forceMaxWidth option is opt-in and keeps default width behavior unchanged. Local validation: npm test passed with 518 passing, 1 skipped.

@jarrodwatts jarrodwatts merged commit 32802c1 into jarrodwatts:main May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants