Skip to content

Commit 0679e6d

Browse files
max-sixtyclaude
andauthored
perf(config): speed up wt config show by avoiding claude --version (#883)
Replace `claude --version` (1.2s Node.js startup) with `which::which("claude")` (instant PATH lookup) for detecting Claude Code availability. Performance: ~1.2s → ~150ms (8x faster) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9267cd3 commit 0679e6d

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/commands/config/show.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ pub fn handle_config_show(full: bool) -> anyhow::Result<()> {
7373

7474
/// Check if Claude Code CLI is available
7575
fn is_claude_available() -> bool {
76-
Cmd::new("claude")
77-
.arg("--version")
78-
.run()
79-
.map(|o| o.status.success())
80-
.unwrap_or(false)
76+
// Allow tests to override detection
77+
if let Ok(val) = std::env::var("WORKTRUNK_TEST_CLAUDE_INSTALLED") {
78+
return val == "1";
79+
}
80+
which::which("claude").is_ok()
8181
}
8282

8383
/// Get the home directory for Claude Code config detection

tests/common/mod.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ pub fn configure_cli_command(cmd: &mut Command) {
685685
cmd.env("WT_TEST_EPOCH", TEST_EPOCH.to_string());
686686
// Enable warn-level logging so diagnostics show up in test failures
687687
cmd.env("RUST_LOG", "warn");
688+
// Treat Claude as not installed by default (tests can override with "1")
689+
cmd.env("WORKTRUNK_TEST_CLAUDE_INSTALLED", "0");
688690

689691
// Apply shared static env vars (see STATIC_TEST_ENV_VARS)
690692
for &(key, value) in STATIC_TEST_ENV_VARS {
@@ -999,6 +1001,8 @@ pub struct TestRepo {
9991001
git_config_path: PathBuf,
10001002
/// Path to mock bin directory for gh/glab commands
10011003
mock_bin_path: Option<PathBuf>,
1004+
/// Whether Claude CLI should be treated as installed
1005+
claude_installed: bool,
10021006
/// Snapshot settings guard - keeps insta filters active for this repo's lifetime
10031007
_snapshot_guard: insta::internals::SettingsBindDropGuard,
10041008
}
@@ -1044,6 +1048,7 @@ impl TestRepo {
10441048
test_config_path,
10451049
git_config_path,
10461050
mock_bin_path: None,
1051+
claude_installed: false,
10471052
_snapshot_guard: snapshot_guard,
10481053
};
10491054

@@ -1087,6 +1092,7 @@ impl TestRepo {
10871092
test_config_path,
10881093
git_config_path,
10891094
mock_bin_path: None,
1095+
claude_installed: false,
10901096
_snapshot_guard: snapshot_guard,
10911097
};
10921098

@@ -1803,10 +1809,7 @@ impl TestRepo {
18031809
.command("auth", MockResponse::exit(1))
18041810
.write(&mock_bin);
18051811

1806-
// claude: not installed
1807-
MockConfig::new("claude")
1808-
.command("_default", MockResponse::exit(1))
1809-
.write(&mock_bin);
1812+
// claude: not installed (don't create mock - which::which won't find it)
18101813

18111814
self.mock_bin_path = Some(mock_bin);
18121815
}
@@ -1816,18 +1819,8 @@ impl TestRepo {
18161819
/// Call this after setup_mock_ci_tools_unauthenticated() to simulate
18171820
/// Claude Code being available on the system.
18181821
pub fn setup_mock_claude_installed(&mut self) {
1819-
use crate::common::mock_commands::{MockConfig, MockResponse};
1820-
1821-
let mock_bin = self
1822-
.mock_bin_path
1823-
.as_ref()
1824-
.expect("Call setup_mock_ci_tools_unauthenticated first");
1825-
1826-
// claude: installed
1827-
MockConfig::new("claude")
1828-
.version("Claude Code 1.0.0 (mock)")
1829-
.command("_default", MockResponse::exit(0))
1830-
.write(mock_bin);
1822+
// Mark Claude as installed for test environment
1823+
self.claude_installed = true;
18311824
}
18321825

18331826
/// Setup the worktrunk plugin as installed in Claude Code
@@ -2073,6 +2066,11 @@ impl TestRepo {
20732066
let new_path = std::env::join_paths(&paths).unwrap();
20742067
cmd.env(&path_var_name, new_path);
20752068
}
2069+
2070+
// Override Claude installed status if setup_mock_claude_installed() was called
2071+
if self.claude_installed {
2072+
cmd.env("WORKTRUNK_TEST_CLAUDE_INSTALLED", "1");
2073+
}
20762074
}
20772075

20782076
/// Set a marker for a branch.

0 commit comments

Comments
 (0)