Repository navigation
fix(effort): tolerate object schema from Claude Code 2.1.115+ - #491
Merged
jarrodwatts merged 2 commits intoApr 24, 2026
Merged
Conversation
Claude Code 2.1.115+ sends effort in stdin JSON as an object
({ "level": "max" }) rather than the bare string the original
design in PR jarrodwatts#471 was future-proofed for. That forward-guess
never materialised exactly as predicted, and the resulting type
mismatch crashes the statusline every tick:
[claude-hud] Error: level.toLowerCase is not a function
Captured payload from Claude Code 2.1.119 (macOS):
"effort": { "level": "max" },
"thinking": { "enabled": true },
"fast_mode": false,
...
Fix accepts both shapes via a small extractor, plus any
non-matching truthy type (numbers, booleans, arrays, empty
objects) falls through to the existing parent-process --effort
fallback rather than throwing.
Adds 10 tests covering:
- object with level field (the real 2.1.115+ shape)
- object with extra fields (forward-compat)
- object missing/nullable level (fall through)
- numeric / boolean / array inputs (no crash)
Baseline 486 pass -> 496 pass, 0 regressions.
The previous JSDoc listed "object first, string second" but `extractEffortString` checks `typeof value === 'string'` before the object branch. Because the two input shapes are mutually exclusive this does not cause a runtime bug, but a future reader parsing the numbered list would draw the wrong conclusion about dispatch order. Swap items 1 and 2 and rename "Priority:" to "Resolution order:" with an explicit cross-reference to the helper, so the comment describes what the code actually does.
jarrodwatts
approved these changes
Apr 24, 2026
jarrodwatts
left a comment
Owner
There was a problem hiding this comment.
Security, quality, and maintainability review cleared. Local full suite passed in an isolated worktree (496 pass, 1 skipped), and GitHub CI is green.
prezis
added a commit
to prezis/claude-hud
that referenced
this pull request
Apr 30, 2026
This fork adds a 4th resolution step to claude-hud's effort detection so the badge works for users on Claude Code < 2.1.115 (no stdin.effort) and for users who set effortLevel persistently in settings.json instead of via --effort CLI flag. Resolution priority (highest -> lowest): 1. stdin.effort string (PR jarrodwatts#471 path, upstream) 2. stdin.effort.level object (PR jarrodwatts#491, upstream, CC 2.1.115+) 3. --effort CLI flag from parent process (upstream) 4. settings.json effortLevel (NEW, this fork) -- reads from ${cwd}/.claude/settings.local.json, then settings.json, then ${CLAUDE_CONFIG_DIR:-~/.claude}/settings.json. Most-specific wins. Behavior change: display.showEffortLevel default flipped false -> true (this fork's whole purpose is to make effort visible by default). Source changes (already in eb58786 via auto-commit hook): src/effort.ts adds readSettingsEffort + cwd param; src/index.ts threads stdin.cwd; src/config.ts flips default; tests/effort.test.js +8 tests for the fallback (project-local > project > user precedence, malformed JSON, non-string values, stdin still wins). This commit: README banner explaining fork differences + CHANGELOG entry. Tests: 519/520 pass (1 pre-existing skip). Upstream-able: source changes are surgical and additive; PR candidate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since Claude Code 2.1.115+, the statusline crashes on every tick with:
when a user has
display.showEffortLevel: truein their config. The crashonly appears after upgrading Claude Code from 2.1.114 (or earlier) to
2.1.115+.
Root cause
The original effort support (#471) was future-proofed for the case where
Claude Code would eventually expose the effort level via stdin JSON — but
because no schema existed yet, the type was guessed as a bare string:
Claude Code 2.1.115+ actually added the field, but as an object:
resolveEffortLevelthen passes the whole object intoformatEffort, whichinvokes
level.toLowerCase()on what is actually a{ level: "max" }object — instant
TypeError.Evidence — live stdin dump from Claude Code 2.1.119 on macOS, Opus 4.7:
{ "session_id": "…", "version": "2.1.119", "model": { "id": "claude-opus-4-7", "display_name": "Opus 4.7" }, "effort": { "level": "max" }, "thinking": { "enabled": true }, "fast_mode": false, … }Fix
Accept both shapes (object with
levelstring, or bare string) through atiny
extractEffortStringhelper, and let any other truthy input fallthrough to the existing
--effortparent-process fallback rather thanthrowing.
The index signature keeps the type permissive — if Claude Code later adds
effort.budgetor similar, no more breaking changes here.Tests
Added 10 tests in
tests/effort.test.js:{ level: "max" }→ renders●levelResult:
End-to-end verified by feeding the captured stdin payload to a locally-built
dist/index.js:Exit code 0, effort bracket renders correctly.
Notes
src/only per CONTRIBUTING.md (CI rebuildsdist/on merge).in case any older Claude Code version still sends it or a user injects
effort via another path.
--effortparent-process fallback path is unchanged and still actsas a safety net when stdin gives us nothing usable.