worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Claude Code statusline JSON: new fields worth surfacing in wt list statusline

Open worktrunk-bot opened this issue 6 months ago • 3 comments

What changed upstream

Claude Code's statusline JSON schema now exposes several fields that src/commands/statusline.rs doesn't read yet:

New field Description Potential use in wt list statusline
workspace.git_worktree Git worktree name when the current directory is inside a linked worktree. Absent in the main working tree. Populated for any git worktree, unlike worktree.* which applies only to --worktree sessions Claude Code is doing the worktree detection for us. Could simplify the cwd→worktree lookup currently done in wt list statusline --claude-code
pr.number, pr.url Open PR for the current branch. Absent until a PR is found, once merged, or outside a git repo A small PR badge inline with the worktree name
pr.review_state approved / pending / changes_requested / draft. May be independently absent Color/symbol on the PR badge — same intent as the running-tend skill's example list
effort.level Current reasoning effort (low / medium / high / xhigh / max) Inline alongside the model name
agent.name Agent name when running under --agent or with agent settings Useful when subagents make worktree state confusing

Surface that's not new but worth a second look

  • workspace.repo.{host,owner,name} is already in the schema; worktrunk uses none of it. With pr.number, we'd have enough to link the PR badge directly to its URL without re-parsing the remote.

What worktrunk already consumes

src/commands/statusline.rs reads workspace.current_dir, model.display_name, context_window.used_percentage, and rate_limits.{five_hour,seven_day}.*. The fields above are additive — no breaking change to flag.

What's not changing

Hook events (WorktreeCreate, WorktreeRemove) are unchanged in the recent Claude Code changelogs (2.1.154 → 2.1.158). The 2.1.157 entry "Plugins in .claude/skills directories are now automatically loaded" loosens — doesn't break — the existing wt config plugins claude install flow.

Codex (rust-v0.134 / 0.135), Gemini CLI (v0.44.1), and OpenCode (v1.15.13) had no integration-surface changes that affect worktrunk's plugins or commit.generation.

Disposition

Filing per running-tend → "Weekly Maintenance: Agent App Integration Surfaces" → "File one issue per relevant change, linking the upstream entry and noting what Worktrunk would need to do." Adding any of these is optional and a judgment call about statusline density. Closing as not-planned is a fine outcome.

worktrunk-bot avatar May 31 '26 10:05 worktrunk-bot

A later weekly scan (#3285) re-flagged workspace.git_worktree, which this issue already covers, plus one item not tracked here. Folding it in and closing #3285 as a duplicate so this stays the single tracking issue.

New: statusline commands now receive COLUMNS / LINES env vars

Per the statusline docs (§ Sizing output to the terminal): as of Claude Code v2.1.153, "Claude Code sets these to the current terminal dimensions before running your script." This is an env-var contract, not a JSON field, which is why it wasn't in the table above.

This one is more than cosmetic for worktrunk. The reason wt list statusline does an expensive parent-process-tree walk (ps up to 10×, then stty) is that Claude Code historically piped stdin/stdout/stderr and inherited no TTY, so width detection returned nothing — see detect_parent_tty_width and the terminal_width_for_statusline doc comment. The new env var closes exactly that gap.

Worth noting two things before anyone writes code:

  • It's already partly wired. terminal_dimensions already falls back to reading COLUMNS (line 99) when direct detection fails, and terminal_width_for_statusline only runs the ps/stty walk when terminal_width() is None. So on v2.1.153+ the COLUMNS path should already fire first and short-circuit the walk — no change needed just to consume it. The open question is whether to verify that empirically and then drop the parent-TTY walk for newer Claude Code versions.
  • One behavioral seam. The stty path reserves 5 columns for Claude Code's own UI messages (saturating_sub(5)); the COLUMNS fallback returns the raw count with no such reservation. If we lean on COLUMNS for sizing, that 5-column margin disappears and the line can render flush to the edge. LINES is currently unused (worktrunk renders a single line).

Adding any of this is still optional and a density/maintenance judgment call, as noted above.

worktrunk-bot avatar Jun 28 '26 10:06 worktrunk-bot

yes let's use the new COLUMNS approach; please PR

max-sixty avatar Jun 28 '26 15:06 max-sixty

Done — #3286 (green, including codecov/patch).

It sizes the statusline straight from COLUMNS (which Claude Code sets to the terminal dimensions since v2.1.153), keeps the 5-column margin the stty path reserved for Claude Code's UI chrome, and removes the ps/stty parent-process walk entirely. Verified empirically that the width tracks COLUMNS with no subprocess walk.

One tradeoff worth flagging: on an older Claude Code (< 2.1.153) that doesn't set COLUMNS, width is now undetectable and the line renders untruncated rather than walking the process tree to recover one — a graceful fallback, but a behavior change for those versions.

worktrunk-bot avatar Jun 28 '26 16:06 worktrunk-bot