Skip to content

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

feat(switch): add no-cd config option (#1401)

Jarryd Tilbrook00eb04a0423b
diff --git a/dev/config.example.toml b/dev/config.example.toml
index e5ff36ba1..95560cc49 100644
--- a/dev/config.example.toml
+++ b/dev/config.example.toml
@@ -72,9 +72,10 @@
# remove = true # Remove worktree after merge (--no-remove to keep)
# verify = true # Run project hooks (--no-verify to skip)
#
-# ### Switch picker
+# ### Switch
#
-# Configuration for `wt switch` interactive picker.
+# [switch]
+# no-cd = true # Skip directory change after switching (--cd to override)
#
# [switch.picker]
# # Pager command for diff preview (overrides git's core.pager)
diff --git a/docs/content/config.md b/docs/content/config.md
index 6fee01e03..ac32034ef 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -150,11 +150,12 @@ remove = true # Remove worktree after merge (--no-remove to keep)
verify = true # Run project hooks (--no-verify to skip)
```
-### Switch picker
-
-Configuration for `wt switch` interactive picker.
+### Switch
```toml
+[switch]
+no-cd = true # Skip directory change after switching (--cd to override)
+
[switch.picker]
# Pager command for diff preview (overrides git's core.pager)
# pager = "delta --paging=never"
diff --git a/docs/content/switch.md b/docs/content/switch.md
index b5272a690..9778c5440 100644
--- a/docs/content/switch.md
+++ b/docs/content/switch.md
@@ -215,7 +215,7 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spa
Skip directory change after switching
Hooks still run normally. Useful when hooks handle navigation (e.g.,
- tmux workflows) or for CI/automation.
+ tmux workflows) or for CI/automation. Use --cd to override.
In picker mode (no branch argument), prints the selected branch name
and exits without switching. Useful for scripting.
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index b40af9c23..018fda14f 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -141,11 +141,12 @@ remove = true # Remove worktree after merge (--no-remove to keep)
verify = true # Run project hooks (--no-verify to skip)
```
-### Switch picker
-
-Configuration for `wt switch` interactive picker.
+### Switch
```toml
+[switch]
+no-cd = true # Skip directory change after switching (--cd to override)
+
[switch.picker]
# Pager command for diff preview (overrides git's core.pager)
# pager = "delta --paging=never"
diff --git a/skills/worktrunk/reference/switch.md b/skills/worktrunk/reference/switch.md
index 9fccc1388..da5b5d84a 100644
--- a/skills/worktrunk/reference/switch.md
+++ b/skills/worktrunk/reference/switch.md
@@ -185,7 +185,7 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spa
Skip directory change after switching
Hooks still run normally. Useful when hooks handle navigation (e.g.,
- tmux workflows) or for CI/automation.
+ tmux workflows) or for CI/automation. Use --cd to override.
In picker mode (no branch argument), prints the selected branch name
and exits without switching. Useful for scripting.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 32838315b..124fd1589 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -449,13 +449,17 @@ To change which branch a worktree is on, use `git switch` inside that worktree.
/// Skip directory change after switching
///
/// Hooks still run normally. Useful when hooks handle navigation
- /// (e.g., tmux workflows) or for CI/automation.
+ /// (e.g., tmux workflows) or for CI/automation. Use --cd to override.
///
/// In picker mode (no branch argument), prints the selected branch
/// name and exits without switching. Useful for scripting.
- #[arg(long)]
+ #[arg(long, overrides_with = "cd")]
no_cd: bool,
+ /// Change directory after switching
+ #[arg(long, overrides_with = "no_cd", hide = true)]
+ cd: bool,
+
/// Skip approval prompts
#[arg(short, long, help_heading = "Automation")]
yes: bool,
@@ -1656,11 +1660,12 @@ remove = true # Remove worktree after merge (--no-remove to keep)
verify = true # Run project hooks (--no-verify to skip)
```
-### Switch picker
-
-Configuration for `wt switch` interactive picker.
+### Switch
```toml
+[switch]
+no-cd = true # Skip directory change after switching (--cd to override)
+
[switch.picker]
# Pager command for diff preview (overrides git's core.pager)
# pager = "delta --paging=never"
diff --git a/src/commands/handle_switch.rs b/src/commands/handle_switch.rs
index 85234fd4a..99e986f6b 100644
--- a/src/commands/handle_switch.rs
+++ b/src/commands/handle_switch.rs
@@ -29,8 +29,8 @@ pub struct SwitchOptions<'a> {
pub execute_args: &'a [String],
pub yes: bool,
pub clobber: bool,
- /// Whether to change directory after switching (default: true)
- pub change_dir: bool,
+ /// Resolved from --cd/--no-cd flags: Some(true) = cd, Some(false) = no cd, None = use config
+ pub change_dir: Option<bool>,
pub verify: bool,
}
@@ -171,12 +171,19 @@ pub fn handle_switch(
execute_args,
yes,
clobber,
- change_dir,
+ change_dir: change_dir_flag,
verify,
} = opts;
let (repo, is_recovered) = current_or_recover().context("Failed to switch worktree")?;
+ // Resolve change_dir: explicit CLI flags > project config > global config > default (true)
+ // Now that we have the repo, we can resolve project-specific config.
+ let change_dir = change_dir_flag.unwrap_or_else(|| {
+ let project_id = repo.project_identifier().ok();
+ !config.resolved(project_id.as_deref()).switch.no_cd()
+ });
+
// Run pre-switch hooks before anything else (before branch validation, planning, etc.)
// Skip when recovered — the source worktree is gone, nothing to run hooks against.
if verify && !is_recovered {
@@ -249,8 +256,9 @@ pub fn handle_switch(
// Offer shell integration if not already installed/active
// (only shows prompt/hint when shell integration isn't working)
// With --execute: show hints only (don't interrupt with prompt)
+ // Skip when change_dir is false — user opted out of cd, so shell integration is irrelevant
// Best-effort: don't fail switch if offer fails
- if !is_shell_integration_active() {
+ if change_dir && !is_shell_integration_active() {
let skip_prompt = execute.is_some();
let _ = prompt_shell_integration(config, binary_name, skip_prompt);
}
diff --git a/src/commands/select/mod.rs b/src/commands/select/mod.rs
index d652b84e8..0d7ccd813 100644
--- a/src/commands/select/mod.rs
+++ b/src/commands/select/mod.rs
@@ -41,7 +41,7 @@ enum PickerAction {
pub fn handle_select(
cli_branches: bool,
cli_remotes: bool,
- change_dir: bool,
+ change_dir_flag: Option<bool>,
) -> anyhow::Result<()> {
// Interactive picker requires a terminal for the TUI
if !std::io::stdin().is_terminal() {
@@ -50,8 +50,9 @@ pub fn handle_select(
let (repo, is_recovered) = current_or_recover()?;
- // Merge CLI flags with resolved config
+ // Merge CLI flags with resolved config (project-specific config is now available)
let config = repo.config();
+ let change_dir = change_dir_flag.unwrap_or_else(|| !config.switch.no_cd());
let show_branches = cli_branches || config.list.branches();
let show_remotes = cli_remotes || config.list.remotes();
diff --git a/src/config/user/accessors.rs b/src/config/user/accessors.rs
index 99e71cc7c..ec32c7fdb 100644
--- a/src/config/user/accessors.rs
+++ b/src/config/user/accessors.rs
@@ -11,7 +11,8 @@ use crate::config::expansion::expand_template;
use super::UserConfig;
use super::merge::{Merge, merge_optional};
use super::sections::{
- CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SelectConfig, SwitchPickerConfig,
+ CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SelectConfig, SwitchConfig,
+ SwitchPickerConfig,
};
/// Default worktree path template
@@ -112,6 +113,17 @@ impl UserConfig {
merge_optional(self.configs.merge.as_ref(), project_config)
}
+ /// Returns the switch config for a specific project.
+ ///
+ /// Merges project-specific settings with global settings, where project
+ /// settings take precedence for fields that are set.
+ pub fn switch(&self, project: Option<&str>) -> Option<SwitchConfig> {
+ let project_config = project
+ .and_then(|p| self.projects.get(p))
+ .and_then(|c| c.overrides.switch.as_ref());
+ merge_optional(self.configs.switch.as_ref(), project_config)
+ }
+
/// Returns the select config for a specific project (deprecated path).
///
/// Merges project-specific settings with global settings, where project
diff --git a/src/config/user/resolved.rs b/src/config/user/resolved.rs
index dd375896b..d4dfc14ef 100644
--- a/src/config/user/resolved.rs
+++ b/src/config/user/resolved.rs
@@ -6,7 +6,7 @@
use super::UserConfig;
use super::sections::{
- CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SwitchPickerConfig,
+ CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SwitchConfig, SwitchPickerConfig,
};
/// All resolved configuration for a specific project context.
@@ -22,6 +22,7 @@ use super::sections::{
/// let stage = resolved.commit.stage(); // StageMode, default applied
/// let pager = resolved.switch_picker.pager(); // Option<&str>
/// let timeout = resolved.switch_picker.picker_command_timeout(); // Option<Duration>
+/// let no_cd = resolved.switch.no_cd(); // bool, default applied
/// ```
#[derive(Debug, Clone, PartialEq)]
pub struct ResolvedConfig {
@@ -32,6 +33,8 @@ pub struct ResolvedConfig {
pub commit_generation: CommitGenerationConfig,
/// Resolved switch picker config (handles deprecated `[select]` fallback)
pub switch_picker: SwitchPickerConfig,
+ /// Resolved switch config
+ pub switch: SwitchConfig,
}
impl ResolvedConfig {
@@ -43,6 +46,7 @@ impl ResolvedConfig {
commit: config.commit(project).unwrap_or_default(),
commit_generation: config.commit_generation(project),
switch_picker: config.switch_picker(project),
+ switch: config.switch(project).unwrap_or_default(),
}
}
}
diff --git a/src/config/user/sections.rs b/src/config/user/sections.rs
index 849c1a682..cef664058 100644
--- a/src/config/user/sections.rs
+++ b/src/config/user/sections.rs
@@ -365,14 +365,26 @@ impl Merge for SwitchPickerConfig {
/// Configuration for the `wt switch` command
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, JsonSchema)]
pub struct SwitchConfig {
+ /// Skip directory change after switch (equivalent to --no-cd)
+ #[serde(rename = "no-cd", default, skip_serializing_if = "Option::is_none")]
+ pub no_cd: Option<bool>,
+
/// Picker settings for the interactive selector
#[serde(default, skip_serializing_if = "Option::is_none")]
pub picker: Option<SwitchPickerConfig>,
}
+impl SwitchConfig {
+ /// Skip directory change (default: false)
+ pub fn no_cd(&self) -> bool {
+ self.no_cd.unwrap_or(false)
+ }
+}
+
impl Merge for SwitchConfig {
fn merge_with(&self, other: &Self) -> Self {
Self {
+ no_cd: other.no_cd.or(self.no_cd),
picker: match (&self.picker, &other.picker) {
(None, None) => None,
(Some(s), None) => Some(s.clone()),
diff --git a/src/config/user/tests.rs b/src/config/user/tests.rs
index 2a97685d1..aac494b79 100644
--- a/src/config/user/tests.rs
+++ b/src/config/user/tests.rs
@@ -1122,12 +1122,14 @@ fn test_switch_config_merge() {
pager: Some("delta".to_string()),
timeout_ms: None,
}),
+ ..Default::default()
};
let other = SwitchConfig {
picker: Some(SwitchPickerConfig {
pager: None,
timeout_ms: Some(300),
}),
+ ..Default::default()
};
let merged = base.merge_with(&other);
assert_eq!(
@@ -1137,7 +1139,7 @@ fn test_switch_config_merge() {
assert_eq!(merged.picker.as_ref().unwrap().timeout_ms, Some(300));
// Base has picker, other doesn't
- let other_none = SwitchConfig { picker: None };
+ let other_none = SwitchConfig::default();
let merged = base.merge_with(&other_none);
assert_eq!(
merged.picker.as_ref().unwrap().pager.as_deref(),
@@ -1145,11 +1147,84 @@ fn test_switch_config_merge() {
);
// Neither has picker
- let base_none = SwitchConfig { picker: None };
- let merged = base_none.merge_with(&other_none);
+ let merged = SwitchConfig::default().merge_with(&other_none);
assert!(merged.picker.is_none());
}
+#[test]
+fn test_switch_config_no_cd_accessor() {
+ use crate::config::user::SwitchConfig;
+
+ // Default is false
+ let config = SwitchConfig::default();
+ assert!(!config.no_cd());
+
+ // Explicit false
+ let config = SwitchConfig {
+ no_cd: Some(false),
+ ..Default::default()
+ };
+ assert!(!config.no_cd());
+
+ // Explicit true
+ let config = SwitchConfig {
+ no_cd: Some(true),
+ ..Default::default()
+ };
+ assert!(config.no_cd());
+}
+
+#[test]
+fn test_switch_config_no_cd_merge() {
+ use crate::config::user::{Merge, SwitchConfig};
+
+ // Other overrides base
+ let base = SwitchConfig {
+ no_cd: Some(false),
+ ..Default::default()
+ };
+ let other = SwitchConfig {
+ no_cd: Some(true),
+ ..Default::default()
+ };
+ let merged = base.merge_with(&other);
+ assert!(merged.no_cd());
+
+ // Base preserved when other is None
+ let base = SwitchConfig {
+ no_cd: Some(true),
+ ..Default::default()
+ };
+ let merged = base.merge_with(&SwitchConfig::default());
+ assert!(merged.no_cd());
+
+ // Neither set
+ let merged = SwitchConfig::default().merge_with(&SwitchConfig::default());
+ assert!(!merged.no_cd()); // default false
+}
+
+#[test]
+fn test_switch_config_no_cd_from_toml() {
+ let toml = r#"
+[switch]
+no-cd = true
+"#;
+ let config = UserConfig::load_from_str(toml).unwrap();
+ let switch = config.switch(None).unwrap();
+ assert!(switch.no_cd());
+}
+
+#[test]
+fn test_switch_config_no_cd_resolved() {
+ let toml = r#"
+[switch]
+no-cd = true
+"#;
+ let config = UserConfig::load_from_str(toml).unwrap();
+ let resolved = config.resolved(None);
+ assert!(resolved.switch.no_cd());
+}
+
#[test]
fn test_switch_picker_fallback_from_select() {
// When only [select] is configured, switch_picker() should use its pager
@@ -1185,6 +1260,7 @@ fn test_switch_picker_prefers_new_over_select() {
pager: Some("delta".to_string()),
timeout_ms: Some(100),
}),
+ ..Default::default()
}),
select: Some(SelectConfig {
pager: Some("bat".to_string()),
@@ -1210,6 +1286,7 @@ fn test_switch_picker_project_override() {
pager: Some("delta".to_string()),
timeout_ms: Some(200),
}),
+ ..Default::default()
}),
..Default::default()
},
@@ -1225,6 +1302,7 @@ fn test_switch_picker_project_override() {
pager: Some("bat".to_string()),
timeout_ms: None, // Fall back to global
}),
+ ..Default::default()
}),
..Default::default()
},
@@ -1250,6 +1328,7 @@ fn test_switch_picker_project_fallback_from_select() {
pager: Some("delta".to_string()),
timeout_ms: Some(300),
}),
+ ..Default::default()
}),
..Default::default()
},
@@ -1298,6 +1377,7 @@ fn test_resolved_config_for_project() {
pager: Some("less".to_string()),
timeout_ms: Some(300),
}),
+ ..Default::default()
}),
..Default::default()
},
@@ -1314,6 +1394,7 @@ fn test_resolved_config_for_project() {
assert_eq!(resolved.commit.stage(), StageMode::None);
assert_eq!(resolved.switch_picker.pager(), Some("less"));
assert_eq!(resolved.switch_picker.timeout_ms, Some(300));
+ assert!(!resolved.switch.no_cd()); // Default false
}
// =========================================================================
diff --git a/src/main.rs b/src/main.rs
index eda339850..b2a74765a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -462,7 +462,7 @@ fn handle_list_command(
fn handle_select_command(branches: bool, remotes: bool) -> anyhow::Result<()> {
// Deprecated: show warning and delegate to handle_select
warn_select_deprecated();
- handle_select(branches, remotes, true)
+ handle_select(branches, remotes, None)
}
#[cfg(not(unix))]
@@ -483,6 +483,7 @@ struct SwitchCommandArgs {
execute_args: Vec<String>,
yes: bool,
clobber: bool,
+ cd: bool,
no_cd: bool,
verify: bool,
}
@@ -492,17 +493,19 @@ fn handle_switch_command(spec: SwitchCommandArgs) -> anyhow::Result<()> {
.context("Failed to load config")
.and_then(|mut config| {
// No branch argument: open interactive picker
+ let change_dir_flag = flag_pair(spec.cd, spec.no_cd);
+
let Some(branch) = spec.branch else {
#[cfg(unix)]
{
- return handle_select(spec.branches, spec.remotes, !spec.no_cd);
+ return handle_select(spec.branches, spec.remotes, change_dir_flag);
}
#[cfg(not(unix))]
{
use worktrunk::git::WorktrunkError;
// Suppress unused variable warnings on Windows
- let _ = (spec.branches, spec.remotes);
+ let _ = (spec.branches, spec.remotes, change_dir_flag);
print_windows_picker_unavailable();
return Err(WorktrunkError::AlreadyDisplayed { exit_code: 2 }.into());
@@ -518,7 +521,7 @@ fn handle_switch_command(spec: SwitchCommandArgs) -> anyhow::Result<()> {
execute_args: &spec.execute_args,
yes: spec.yes,
clobber: spec.clobber,
- change_dir: !spec.no_cd,
+ change_dir: change_dir_flag,
verify: spec.verify,
},
&mut config,
@@ -906,6 +909,7 @@ fn main() {
execute_args,
yes,
clobber,
+ cd,
no_cd,
verify,
} => handle_switch_command(SwitchCommandArgs {
@@ -918,6 +922,7 @@ fn main() {
execute_args,
yes,
clobber,
+ cd,
no_cd,
verify,
}),
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index efee3d655..9265e270c 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -336,6 +336,42 @@ fn test_switch_no_cd_execute_runs_in_target_worktree(#[from(repo_with_remote)] r
});
}
+/// Config-driven no-cd suppresses the cd directive (same as --no-cd flag)
+#[rstest]
+fn test_switch_no_cd_config_suppresses_directive(#[from(repo_with_remote)] mut repo: TestRepo) {
+ let _feature_wt = repo.add_worktree("feature");
+ let (directive_path, _guard) = directive_file();
+
+ // Set up config with no-cd = true
+ repo.write_test_config(
+ r#"worktree-path = "../{{ repo }}.{{ branch }}"
+
+[switch]
+no-cd = true
+"#,
+ );
+
+ let settings = setup_snapshot_settings(&repo);
+
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ configure_directive_file(&mut cmd, &directive_path);
+ cmd.args(["switch", "feature"])
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+
+ // Verify directive file does NOT contain cd command
+ let directives = std::fs::read_to_string(&directive_path).unwrap_or_default();
+ assert!(
+ !directives.contains("cd '"),
+ "Directive file should NOT contain cd command with no-cd config, got: {}",
+ directives
+ );
+ });
+}
+
// ============================================================================
// Non-Directive Mode Tests (no WORKTRUNK_DIRECTIVE_FILE)
// ============================================================================
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 747f0c1e1..4524202d4 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -3350,3 +3350,56 @@ fn test_switch_base_without_create_warns_not_errors(repo: TestRepo) {
&["base-test", "--base", "-"],
);
}
+
+/// Test that `--cd` flag overrides `[switch] no-cd = true` config
+#[rstest]
+fn test_switch_cd_flag_overrides_no_cd_config(repo: TestRepo) {
+ // Set up config with no-cd = true
+ repo.write_test_config(
+ r#"worktree-path = "../{{ repo }}.{{ branch }}"
+
+[switch]
+no-cd = true
+"#,
+ );
+
+ repo.run_git(&["branch", "cd-override-test"]);
+
+ // --cd should override the config and include cd directive
+ snapshot_switch(
+ "switch_cd_flag_overrides_config",
+ &repo,
+ &["cd-override-test", "--cd"],
+ );
+}
+
+/// Test that `--no-cd` flag works (explicit flag, no config)
+#[rstest]
+fn test_switch_no_cd_flag_explicit(repo: TestRepo) {
+ repo.run_git(&["branch", "no-cd-explicit"]);
+
+ // --no-cd should skip the cd directive
+ snapshot_switch(
+ "switch_no_cd_flag_explicit",
+ &repo,
+ &["no-cd-explicit", "--no-cd"],
+ );
+}
+
+/// Test that `[switch] no-cd = true` config is respected when no flags provided
+#[rstest]
+fn test_switch_no_cd_config_default(repo: TestRepo) {
+ // Set up config with no-cd = true
+ repo.write_test_config(
+ r#"worktree-path = "../{{ repo }}.{{ branch }}"
+
+[switch]
+no-cd = true
+"#,
+ );
+
+ repo.run_git(&["branch", "no-cd-config-test"]);
+
+ // Without any cd flags, config should be respected (no cd directive)
+ snapshot_switch("switch_no_cd_config_default", &repo, &["no-cd-config-test"]);
+}
diff --git a/tests/snapshots/integration__integration_tests__directives__switch_no_cd_config_suppresses_directive.snap b/tests/snapshots/integration__integration_tests__directives__switch_no_cd_config_suppresses_directive.snap
new file mode 100644
index 000000000..528978d61
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__directives__switch_no_cd_config_suppresses_directive.snap
@@ -0,0 +1,46 @@
+---
+source: tests/integration_tests/directives.rs
+info:
+ program: wt
+ args:
+ - switch
+ - feature
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_DIRECTIVE_FILE: "[DIRECTIVE_FILE]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Switched to worktree for feature @ _REPO_.feature
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
index 240bc593d..2a6d2b04c 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
@@ -131,9 +131,10 @@ Creates ~/.config/worktrunk/config.toml with the following content:
  # remove = true # Remove worktree after merge (--no-remove to keep)
  # verify = true # Run project hooks (--no-verify to skip)
  #
-  # ### Switch picker
+  # ### Switch
  #
-  # Configuration for `wt switch` interactive picker.
+  # [switch]
+  # no-cd = true # Skip directory change after switching (--cd to override)
  #
  # [switch.picker]
  # # Pager command for diff preview (overrides git's core.pager)
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index c42d4825b..383981d57 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -176,10 +176,11 @@ All flags are on by default. Set to false to change default behavior.
  remove = true # Remove worktree after merge (--no-remove to keep)
  verify = true # Run project hooks (--no-verify to skip)
-Switch picker
-
-Configuration for wt switch interactive picker.
+Switch
+  [switch]
+  no-cd = true # Skip directory change after switching (--cd to override)
+ 
  [switch.picker]
  # Pager command for diff preview (overrides git's core.pager)
  # pager = "delta --paging=never"
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
index 4d890dc40..570aa1ff6 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
@@ -77,7 +77,7 @@ Usage: wt switch [OPTIONS] [BRANCH] [--
--no-cd
Skip directory change after switching
- Hooks still run normally. Useful when hooks handle navigation (e.g., tmux workflows) or for CI/automation.
+ Hooks still run normally. Useful when hooks handle navigation (e.g., tmux workflows) or for CI/automation. Use --cd to override.
In picker mode (no branch argument), prints the selected branch name and exits without switching. Useful for scripting.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_cd_flag_overrides_config.snap b/tests/snapshots/integration__integration_tests__switch__switch_cd_flag_overrides_config.snap
new file mode 100644
index 000000000..e90618bb7
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_cd_flag_overrides_config.snap
@@ -0,0 +1,47 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - cd-override-test
+ - "--cd"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Created worktree for cd-override-test @ _REPO_.cd-override-test
+▲ Cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_cd_config_default.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_cd_config_default.snap
new file mode 100644
index 000000000..211dc5a22
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_cd_config_default.snap
@@ -0,0 +1,45 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - no-cd-config-test
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Created worktree for no-cd-config-test @ _REPO_.no-cd-config-test
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_no_cd_flag_explicit.snap b/tests/snapshots/integration__integration_tests__switch__switch_no_cd_flag_explicit.snap
new file mode 100644
index 000000000..8c84fe459
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_no_cd_flag_explicit.snap
@@ -0,0 +1,46 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - no-cd-explicit
+ - "--no-cd"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Created worktree for no-cd-explicit @ _REPO_.no-cd-explicit