Skip to content

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

Fix statusline dim in Claude Code terminals

Maximilian Roos94dc97b2ad8f
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index 7f0d5fa1e..44daeb399 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -200,9 +200,11 @@ pub fn run(claude_code: bool) -> Result<()> {
if !output.is_empty() {
if claude_code {
use std::io::Write;
+ use worktrunk::styling::fix_dim_after_color_reset;
let reset = anstyle::Reset;
// Bypass anstream - write directly to stdout to preserve ANSI codes
// regardless of TTY detection (Claude Code expects raw ANSI)
+ let output = fix_dim_after_color_reset(&output);
writeln!(std::io::stdout(), "{reset} {output}")?;
std::io::stdout().flush()?;
} else {
diff --git a/src/styling/mod.rs b/src/styling/mod.rs
index 150f347c2..18acb30a8 100644
--- a/src/styling/mod.rs
+++ b/src/styling/mod.rs
@@ -60,6 +60,15 @@ pub fn visual_width(s: &str) -> usize {
s.ansi_strip().width()
}
+/// Fix dim rendering for terminals that don't handle \e[2m after \e[39m.
+///
+/// Claude Code's terminal doesn't render dim (\e[2m) correctly when it follows
+/// a foreground color reset (\e[39m). This function replaces that sequence with
+/// a full reset (\e[0m) before dim, which works correctly.
+pub fn fix_dim_after_color_reset(s: &str) -> String {
+ s.replace("\x1b[39m\x1b[2m", "\x1b[0m\x1b[2m")
+}
+
// Re-export for tests
#[cfg(test)]
use format::wrap_styled_text;
@@ -772,4 +781,34 @@ cp -cR {{ repo_root }}/target/debug/.fingerprint {{ repo_root }}/target/debug/bu
result
);
}
+
+ #[test]
+ fn test_fix_dim_after_color_reset() {
+ // Basic case: foreground reset followed by dim
+ assert_eq!(
+ fix_dim_after_color_reset("\x1b[39m\x1b[2m"),
+ "\x1b[0m\x1b[2m"
+ );
+
+ // With surrounding content (cyan ? then dim ^)
+ assert_eq!(
+ fix_dim_after_color_reset("\x1b[36m?\x1b[39m\x1b[2m^\x1b[22m"),
+ "\x1b[36m?\x1b[0m\x1b[2m^\x1b[22m"
+ );
+
+ // Multiple occurrences
+ assert_eq!(
+ fix_dim_after_color_reset("a\x1b[39m\x1b[2mb\x1b[39m\x1b[2mc"),
+ "a\x1b[0m\x1b[2mb\x1b[0m\x1b[2mc"
+ );
+
+ // No matches - idempotent
+ assert_eq!(fix_dim_after_color_reset("no escapes"), "no escapes");
+
+ // Similar but different sequence (bold, not dim) - should not match
+ assert_eq!(
+ fix_dim_after_color_reset("\x1b[39m\x1b[1m"),
+ "\x1b[39m\x1b[1m"
+ );
+ }
}
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index c7e5770a3..a291cc456 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -169,7 +169,7 @@ fn test_statusline_claude_code_full_context() {
let output = run_statusline(&repo, &["--claude-code"], Some(&json));
claude_code_snapshot_settings(&repo).bind(|| {
- assert_snapshot!(output, @"[PATH] main ?^ | Opus");
+ assert_snapshot!(output, @"[PATH] main ?^ | Opus");
});
}