Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(statusline): dim the dev-server URL until its port answers (#3561)

Maximilian Roosf3e5c8260436
diff --git a/docs/content/claude-code.md b/docs/content/claude-code.md
index 06605956d..58bcb5e4d 100644
--- a/docs/content/claude-code.md
+++ b/docs/content/claude-code.md
@@ -109,7 +109,7 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !🤖 @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇡1</span> <span style='color:#0a0'>#3035</span> Opus 🌔 65% <span style='color:#a70'>1.4×(10am–3pm)</span></code>
-The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](@/list.md) collapses to a clickable `:3000` instead of rendering in full. Both are OSC 8 hyperlinks: underlined and clickable in terminals that support them, plain text everywhere else.
+The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](@/list.md) shows as its port — `:3000`, dim until something answers on it. Both links are OSC 8, which Claude Code re-emits to the terminal rather than drawing itself: underlined and clickable where the terminal supports them, the same text unclickable where it doesn't.
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (🌕→🌑 as context fills). A `<n>×(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset — `1.4×(10am–3pm)` reads as 1.4× the pace that would exactly fill that window. Its colour deepens with severity — dim, then dim-yellow, then yellow — as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace — `93%(10am–3pm)` — near the cap, how much is left matters more than how fast it's going.
diff --git a/plugins/worktrunk/skills/worktrunk/reference/claude-code.md b/plugins/worktrunk/skills/worktrunk/reference/claude-code.md
index 53905c1dc..e840e8ced 100644
--- a/plugins/worktrunk/skills/worktrunk/reference/claude-code.md
+++ b/plugins/worktrunk/skills/worktrunk/reference/claude-code.md
@@ -111,7 +111,7 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !🤖 @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇡1</span> <span style='color:#0a0'>#3035</span> Opus 🌔 65% <span style='color:#a70'>1.4×(10am–3pm)</span></code>
-The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](https://worktrunk.dev/list/) collapses to a clickable `:3000` instead of rendering in full. Both are OSC 8 hyperlinks: underlined and clickable in terminals that support them, plain text everywhere else.
+The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](https://worktrunk.dev/list/) shows as its port — `:3000`, dim until something answers on it. Both links are OSC 8, which Claude Code re-emits to the terminal rather than drawing itself: underlined and clickable where the terminal supports them, the same text unclickable where it doesn't.
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (🌕→🌑 as context fills). A `<n>×(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset — `1.4×(10am–3pm)` reads as 1.4× the pace that would exactly fill that window. Its colour deepens with severity — dim, then dim-yellow, then yellow — as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace — `93%(10am–3pm)` — near the cap, how much is left matters more than how fast it's going.
diff --git a/skills/worktrunk/reference/claude-code.md b/skills/worktrunk/reference/claude-code.md
index 53905c1dc..e840e8ced 100644
--- a/skills/worktrunk/reference/claude-code.md
+++ b/skills/worktrunk/reference/claude-code.md
@@ -111,7 +111,7 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !🤖 @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇡1</span> <span style='color:#0a0'>#3035</span> Opus 🌔 65% <span style='color:#a70'>1.4×(10am–3pm)</span></code>
-The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](https://worktrunk.dev/list/) collapses to a clickable `:3000` instead of rendering in full. Both are OSC 8 hyperlinks: underlined and clickable in terminals that support them, plain text everywhere else.
+The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](https://worktrunk.dev/list/) shows as its port — `:3000`, dim until something answers on it. Both links are OSC 8, which Claude Code re-emits to the terminal rather than drawing itself: underlined and clickable where the terminal supports them, the same text unclickable where it doesn't.
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (🌕→🌑 as context fills). A `<n>×(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset — `1.4×(10am–3pm)` reads as 1.4× the pace that would exactly fill that window. Its colour deepens with severity — dim, then dim-yellow, then yellow — as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace — `93%(10am–3pm)` — near the cap, how much is left matters more than how fast it's going.
diff --git a/src/cli/list.rs b/src/cli/list.rs
index 25270635c..02a61bb21 100644
--- a/src/cli/list.rs
+++ b/src/cli/list.rs
@@ -8,9 +8,11 @@ pub enum ListSubcommand {
/// Single-line status for shell prompts
#[command(after_long_help = r#"## Output formats
-- `table` (default): `branch status ±working commits upstream ci`
+- `table` (default): `branch status ±working commits upstream ci url`
- `json`: Same structure as `wt list --format=json` but for the current worktree only
-- `claude-code`: `dir branch status ±working commits upstream ci model context pace`
+- `claude-code`: `dir branch status ±working commits upstream ci url model context pace`
+
+The CI reference links to its PR/MR, and a dev server URL carrying a port shows as `:3000` linking to the URL in full, dim until something answers on that port — the same cells `wt list` renders. Both links are OSC 8, which a terminal that doesn't support them discards, leaving the same text unclickable.
## Claude Code mode
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index 0a13de14a..7aeb2695c 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -606,12 +606,16 @@ struct PendingColumn<'a> {
/// URL's. Without links, or when the URL carries no parseable port, there is
/// nowhere to hide the URL, so it renders in full and stays copyable.
///
-/// Callers pass the decision rather than probing the terminal here: the
-/// statusline's stdout is a pipe to its editor, so `supports_hyperlinks` reports
-/// false there even though the consumer renders OSC 8.
-///
-/// [`estimate_url_width`] budgets the column against this, so the two have to
-/// agree on when a cell collapses to `:port` — hence the adjacency.
+/// `wt list` passes the terminal probe, because there the answer changes what
+/// the reader gets: [`estimate_url_width`] reserves a column wide enough for the
+/// full URL, so an unlinked cell can print it (the two have to agree on when a
+/// cell collapses to `:port`, hence the adjacency). The statusline passes
+/// `true`. It has no column to reserve — it fits a fixed-width line by dropping
+/// its worst-priority segment, and the URL is the worst — so an unlinked cell
+/// would grow past the budget and be dropped entirely, trading a port for
+/// nothing. A terminal that doesn't implement OSC 8 discards the escape and
+/// renders the same `:3000`, so emitting it unconditionally costs that reader
+/// nothing.
pub(crate) fn format_url_cell(url: &str, include_link: bool) -> String {
if include_link && let Some(port) = parse_port_from_url(url) {
return format!(
diff --git a/src/commands/list/model/item.rs b/src/commands/list/model/item.rs
index 37194bfdc..b4621034f 100644
--- a/src/commands/list/model/item.rs
+++ b/src/commands/list/model/item.rs
@@ -5,6 +5,7 @@
use std::path::PathBuf;
+use color_print::cformat;
use worktrunk::git::{IntegrationReason, IntegrationSignals, LineDiff, check_integration};
use super::state::{ActiveGitOperation, Divergence, MainState, OperationState, WorktreeState};
@@ -465,9 +466,9 @@ impl ListItem {
self.is_potentially_removable() == Some(true)
}
- /// Format this item as a single-line statusline string with clickable links.
+ /// Format this item as a single-line statusline string.
///
- /// Format: `branch status @working commits ^branch_diff upstream ci`
+ /// Format: `branch status @working commits ^branch_diff upstream ci url`
/// Uses 2-space separators between non-empty parts.
pub fn format_statusline(&self) -> String {
use super::statusline_segment::StatuslineSegment;
@@ -478,6 +479,12 @@ impl ListItem {
///
/// Returns segments with priorities matching `wt list` column priorities.
/// Use [`super::statusline_segment::StatuslineSegment::fit_to_width`] to truncate intelligently.
+ ///
+ /// The CI reference and the dev-server port always carry their OSC 8 link:
+ /// a terminal without OSC 8 discards the escape and renders the same text,
+ /// and the alternative rendering `wt list` uses when links are unavailable
+ /// (the URL in full) would outgrow this line's budget. See
+ /// [`format_url_cell`].
pub fn format_statusline_segments(&self) -> Vec<super::statusline_segment::StatuslineSegment> {
use super::statusline_segment::StatuslineSegment;
@@ -552,10 +559,16 @@ impl ListItem {
));
}
- // 8. URL (priority 9) — the port as a link to the dev server, as in `wt list`
+ // 8. URL (priority 9) — the dev server, as in `wt list`: the port as a
+ // link, dimmed unless the health check found something listening on it.
if let Some(ref url) = self.url {
+ let cell = format_url_cell(url, true);
segments.push(StatuslineSegment::from_column(
- format_url_cell(url, true),
+ if self.url_active == Some(true) {
+ cell
+ } else {
+ cformat!("<dim>{cell}</>")
+ },
ColumnKind::Url,
));
}
@@ -920,6 +933,30 @@ mod tests {
assert_eq!(ci.width(), "#123".len());
}
+ /// A URL nothing answers on is dim, as in `wt list` — the port is still
+ /// worth showing, but it isn't somewhere to go yet.
+ #[test]
+ fn test_statusline_url_segment_dims_until_the_port_answers() {
+ let mut item = ListItem::new_branch("abc123".to_string(), "feature".to_string());
+ item.url = Some("http://127.0.0.1:17913".to_string());
+
+ let url_cell = |active| {
+ let mut item = item.clone();
+ item.url_active = active;
+ item.format_statusline_segments()
+ .into_iter()
+ .find(|s| s.kind == Some(ColumnKind::Url))
+ .expect("URL segment present when a URL is known")
+ .content
+ };
+
+ let plain = format_url_cell("http://127.0.0.1:17913", true);
+ let dim = cformat!("<dim>{plain}</>");
+ assert_eq!(url_cell(Some(false)), dim, "a dead port should dim");
+ assert_eq!(url_cell(None), dim, "an unfinished health check should dim");
+ assert_eq!(url_cell(Some(true)), plain, "a live port should not dim");
+ }
+
#[test]
fn test_list_item_counts() {
// New items have no counts computed yet
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index da4deb9a9..44d8e7391 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -1,7 +1,7 @@
//! Statusline output for shell prompts and editors.
//!
//! Outputs a single-line status for the current worktree:
-//! `branch status ±working commits upstream [ci]`
+//! `branch status ±working commits upstream [ci] [url]`
//!
//! This command reuses the data collection infrastructure from `wt list`,
//! avoiding duplication of git operations.
diff --git a/src/testing/mod.rs b/src/testing/mod.rs
index 2b212cda1..898c34b0e 100644
--- a/src/testing/mod.rs
+++ b/src/testing/mod.rs
@@ -352,7 +352,7 @@ fn default_llvm_profile_file_with(inherited: Option<std::ffi::OsString>) -> std:
/// Prepare a subprocess to run with a clean wt environment.
///
/// Strips every `GIT_*` and `WORKTRUNK_*` from the parent env, plus
-/// `NO_COLOR` / `SHELL` / `PSModulePath`, then points the three
+/// `NO_COLOR` / `FORCE_HYPERLINK` / `SHELL` / `PSModulePath`, then points the three
/// `WORKTRUNK_*_PATH` env vars at known locations:
///
/// - `WORKTRUNK_CONFIG_PATH` ← `user_config` (or [`DEFAULT_ISOLATED_USER_CONFIG`])
@@ -392,6 +392,10 @@ where
}
}
cmd.env_remove("NO_COLOR");
+ // Overrides the OSC 8 probe, so an inherited value changes whether `wt
+ // list` links its CI cell and shortens its URL cell to `:port`. The
+ // statusline links unconditionally and is unaffected.
+ cmd.env_remove("FORCE_HYPERLINK");
cmd.env_remove("SHELL");
// PSModulePath being inherited triggers false PowerShell detection on
// CI environments where PowerShell Core is installed but not in use.
@@ -3099,11 +3103,12 @@ mod tests {
.collect();
// Scrubbed: GIT_*, WORKTRUNK_* (overwritten path vars also appear here),
- // NO_COLOR, SHELL, PSModulePath.
+ // NO_COLOR, FORCE_HYPERLINK, SHELL, PSModulePath.
assert_eq!(removed.get("GIT_DIR"), Some(&None));
assert_eq!(removed.get("GIT_AUTHOR_DATE"), Some(&None));
assert_eq!(removed.get("WORKTRUNK_HISTORY"), Some(&None));
assert_eq!(removed.get("NO_COLOR"), Some(&None));
+ assert_eq!(removed.get("FORCE_HYPERLINK"), Some(&None));
// Not scrubbed: vars that don't match either prefix.
assert!(!removed.contains_key("PATH"));
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index 60000bc8c..50b5e5ad1 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -402,7 +402,7 @@ url = "http://{{ branch }}.localhost:3000"
let output = run_statusline(&repo, &[], None);
// Shows `?` because writing project config creates uncommitted file
- assert_snapshot!(output, @r" main ?^| @+2 ]8;;http://main.localhost:3000\:3000]8;;\");
+ assert_snapshot!(output, @r" main ?^| @+2 ]8;;http://main.localhost:3000\:3000]8;;\");
}
#[rstest]
@@ -423,7 +423,28 @@ url = "http://{{ branch }}.localhost:3000"
// Run statusline from feature worktree
let output = run_statusline_from_dir(&repo, &[], None, &feature_path);
- assert_snapshot!(output, @r" feature _ ]8;;http://feature.localhost:3000\:3000]8;;\");
+ assert_snapshot!(output, @r" feature _ ]8;;http://feature.localhost:3000\:3000]8;;\");
+}
+
+/// The URL segment lands after the CI reference and before the model in Claude
+/// Code mode, where the directory and model segments share the line with it.
+#[rstest]
+fn test_statusline_claude_code_url_placement(repo: TestRepo) {
+ repo.write_project_config(
+ r#"[list]
+url = "http://{{ branch }}.localhost:3000"
+"#,
+ );
+
+ let escaped_path = escape_path_for_json(repo.root_path());
+ let json = format!(
+ r#"{{"model": {{"display_name": "Opus"}}, "workspace": {{"current_dir": "{escaped_path}"}}}}"#
+ );
+
+ let output = run_statusline(&repo, &["--format=claude-code"], Some(&json));
+ claude_code_snapshot_settings().bind(|| {
+ assert_snapshot!(output, @r" [PATH] main ?^| @+2 ]8;;http://main.localhost:3000\:3000]8;;\ Opus");
+ });
}
// --- JSON Format Tests ---