Skip to content

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

Merged
max-sixty merged 8 commits into
max-sixty:mainfrom
jradtilbrook:switch-no-cd-config
Mar 13, 2026
Merged

max-sixty merged 8 commits into
max-sixty:mainfrom
jradtilbrook:switch-no-cd-config

Conversation

@jradtilbrook

Copy link
Copy Markdown
Contributor

Summary

  • Add [switch] no-cd = true config option to disable directory change by default
  • Add --cd flag to override config when directory change is desired
  • Implement 3-way precedence: --cd flag → --no-cd flag → config → default (false)

Motivation

Users who manage worktrees via tmux sessions (one session per worktree) handle directory changes themselves. For these workflows, having wt switch automatically change directories is unnecessary — they switch tmux sessions instead. This config option lets users disable the default cd behavior while retaining --cd for occasional use.

Add `[switch] no-cd = true` config option for users who manage worktrees
via tmux sessions and handle directory changes themselves. Includes
`--cd` flag to override config when needed.
@jradtilbrook
jradtilbrook force-pushed the switch-no-cd-config branch from b187e7b to 19a53c0 Compare March 9, 2026 03:55

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean implementation — config plumbing follows existing patterns well. Two things worth addressing:

1. Project-specific config won't take effect (should fix)

handle_switch_command resolves config.resolved(None), so [switch] no-cd under a [projects."..."] override is silently ignored. Other commands go through CommandEnv::resolved() which passes the project identifier. This is a pre-existing limitation (the repo isn't opened yet at that point), but since the PR adds tests for project-level merging of SwitchConfig, it's worth either documenting the limitation or deferring the resolution until after the repo is available.

2. Missing integration tests for the new behavior (should fix)

The unit tests cover config parsing/merging thoroughly, but there are no integration tests for:

  • --cd flag overriding no-cd = true config
  • Config-based no-cd actually suppressing the cd directive
  • The 3-way precedence described in the PR summary

The existing --no-cd integration tests in directives.rs would be a natural place to add a config-driven variant.

3. Help snapshots (minor)

The --cd flag is added to the CLI definition but the help snapshots (help_switch_long.snap, help_switch_short.snap) aren't updated in the diff. These will need cargo insta accept after a test run — CI will likely catch this, but wanted to flag it.

Comment thread src/main.rs Resolved
@jradtilbrook
jradtilbrook marked this pull request as draft March 9, 2026 03:59
Move change_dir resolution from main.rs into handle_switch where the
repo is available, enabling project-specific [switch] no-cd config.
The picker path still uses global config since no repo context exists.
@jradtilbrook
jradtilbrook force-pushed the switch-no-cd-config branch from bf7955e to 5472a27 Compare March 9, 2026 04:53
@jradtilbrook
jradtilbrook marked this pull request as ready for review March 9, 2026 05:15
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Clean, well-structured PR. The config plumbing follows existing patterns nicely (accessor, merge, resolved), and the 3-way precedence logic is clear. CI is green including codecov/patch.

A few observations:

Integration test coverage gap — tests verify output, not directive behavior

The three new integration tests use snapshot_switch, which doesn't set up a WORKTRUNK_DIRECTIVE_FILE. They verify the output messages differ (e.g., --cd produces "Cannot change directory — shell integration not installed", while config-based no-cd omits that warning), which does prove the code path diverges.

However, the existing directives.rs tests verify the actual directive file content — asserting that cd '...' is present or absent. A directive-based test for config-driven no-cd would be a stronger assertion that the cd is actually suppressed end-to-end, not just that the output message changed. Something like the existing test_switch_no_cd_suppresses_directive but with config instead of --no-cd flag.

Not blocking — the current tests do cover the precedence logic. But worth considering.

Unrelated snapshot change: GIT_EDITOR removal

The help snapshots (help_switch_long.snap, help_switch_short.snap) drop GIT_EDITOR: "" from the env section. This looks like a snapshot refresh that picked up an unrelated change — not part of this PR's intent. Harmless, but noting it.

Picker path project-config limitation (acknowledged)

The comment at main.rs:496-497 documents that the picker path resolves config with None for project, so project-level [switch] no-cd won't take effect there. The bot review flagged this too — the comment is a reasonable way to document the limitation. If a user hits this, the workaround is --no-cd on the command line.

Overall: well done — the implementation is clean, precedence is correct, and the previous review's main asks (integration tests, help snapshots) are addressed.

Comment thread docs/content/switch.md Outdated
<b><span class=c>--clobber</span></b>
Remove stale paths at target

<b><span class=c>--cd</span></b>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@worktrunk-bot can you hide this option and put it into --no-cd, in the same way we do with --progressive (i.e. keep no-cd

(@jradtilbrook lmk if you disagree, you're welcome to revert)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No i was actually going to ask that. I think its a better approach 👍

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@worktrunk-bot all good bud?

(For the hourly reviewer — please evaluate what happened here!)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@worktrunk-bot the issue re you not seeing messages on fork-pr inline comments should now be fixed, please now do this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — I've hidden the --cd flag using the same overrides_with + hide = true pattern as --progressive/--no-progressive. The --cd flag still works but is hidden from help output, and --no-cd is the only visible flag with help text mentioning --cd as the override.

Since this is a fork PR, I can't push directly to the PR branch. I've pushed the commit to switch-no-cd-config on the main repo — @jradtilbrook can cherry-pick dccae85a, or the branch can be used directly.

Changes in the commit:

  • src/cli/mod.rs: --cd now uses hide = true and overrides_with = "no_cd" (matching the --progressive pattern)
  • --no-cd help text updated to mention Use --cd to override.
  • Docs, skill reference, and help snapshots updated to reflect the hidden flag

@cperalt

cperalt commented Mar 10, 2026

Copy link
Copy Markdown

just for my own learning, I also use tmux sessions + worktrees, and i use have an alias like:

alias wts="wt switch --no-cd"
alias wtn="wt switch --create --no-cd"

to use when I dont want to switch directories. Does this not accomplish the same thing? Or is it that user wants no cd to be the default for his config?

@jradtilbrook

Copy link
Copy Markdown
Contributor Author

just for my own learning, I also use tmux sessions + worktrees, and i use have an alias like:

alias wts="wt switch --no-cd" alias wtn="wt switch --create --no-cd"

to use when I dont want to switch directories. Does this not accomplish the same thing? Or is it that user wants no cd to be the default for his config?

@cperalt basically, I didn't want to add an alias 🤷‍♂️. I don't think there will ever be a time where I would want to allow it to cd either so wanted it globally configurable

@cperalt

cperalt commented Mar 10, 2026

Copy link
Copy Markdown

True thanks for the reply, yeah this makes sense! Ill probably also use this too since i also never cd lol

@max-sixty

Copy link
Copy Markdown
Owner

just for my own learning, I also use tmux sessions + worktrees, and i use have an alias like:

ha, thanks, that makes for a more compelling reason to merge, if multiple people are setting up aliases!

@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot please look at the messages above (I know you can't see inline review comments on forks...)

worktrunk-bot added a commit that referenced this pull request Mar 12, 2026
…rompt

Defense-in-depth for the recurring fork-PR push bug (#1434, #1411). The
skill-level instruction alone is insufficient — the model pushes to origin
before checking. Two changes:

1. Add a workflow step that detects fork PRs via `gh pr view` and sets an
   output flag before Claude runs.
2. When the flag is set, append "This is a FORK PR" to the system prompt so
   Claude sees the warning before any reasoning about pushing.
3. Move fork detection to the "First Steps" section of the running-in-ci
   skill and strengthen the Fork PRs section with recurrence history.

Evidence: run 22985929574 on PR #1401 (fork from jradtilbrook) — bot pushed
to origin creating a stray branch, then discovered the fork after the fact.
Third occurrence of this pattern.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
max-sixty and others added 2 commits March 11, 2026 21:58
Match the --progressive/--no-progressive pattern: the rarely-used
override (--cd) is hidden, the user-facing flag (--no-cd) is visible
with "Use --cd to override" in help text. Also switch from
conflicts_with to overrides_with for last-one-wins semantics.

Co-Authored-By: Claude <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot are the per-project overrides now working?

anything else to consider before we merge?

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Yes — per-project overrides are working for the main switch path. At handle_switch.rs:181-184, the repo is opened first and then config.resolved(project_id) is called, so project-level [switch] no-cd takes effect correctly.

The only place it doesn't apply is the picker path (no branch argument), which resolves config with resolved(None) before a repo is opened — documented with a comment at main.rs:499-502. That's a reasonable limitation since the picker is repo-agnostic at that point.

As for anything else before merging — I don't see blockers. CI is fully green (all platforms + codecov). The implementation is clean, the --cd flag was hidden per your request, and the precedence logic is well-tested. Good to merge.

@max-sixty

Copy link
Copy Markdown
Owner

The only place it doesn't apply is the picker path (no branch argument), which resolves config with resolved(None) before a repo is opened — documented with a comment at main.rs:499-502. That's a reasonable limitation since the picker is repo-agnostic at that point.

is this pre-existing? open a new PR to address it if so

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Not pre-existing — the no_cd config option itself is new to this PR, so the picker path never needed to resolve it before. On main, line 498 just uses !spec.no_cd (a raw CLI flag).

The fix is straightforward: handle_select already opens a repo via current_or_recover() and uses repo.config() (which resolves project overrides) for other config like list.branches. So instead of pre-resolving change_dir before entering handle_select, we pass the flag pair through and resolve it inside where project config is available.

Opened #1484 stacked on this branch.

@max-sixty

Copy link
Copy Markdown
Owner

can you push to this PR? I don't think the stacked PR is working given it's a fork

The picker path (wt switch without arguments) was resolving config with
resolved(None), missing project-specific [switch] no-cd overrides. Since
handle_select already opens a repo via current_or_recover(), pass the
flag pair through and resolve change_dir inside where repo.config()
provides project-aware resolution.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Done — cherry-picked the picker fix commit (154fdda) directly onto this branch and pushed. Closed #1484 as superseded.

CI is green across all platforms. The initial run hit transient infra failures (nushell install + flaky lychee), re-run passed cleanly.

@max-sixty
max-sixty merged commit 00eb04a into max-sixty:main Mar 13, 2026
28 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants