Skip to content

feat(shell): auto-cd to newly created worktree after add#100

Merged
satococoa merged 6 commits intomainfrom
codex/issue-90-auto-cd
Mar 3, 2026
Merged

feat(shell): auto-cd to newly created worktree after add#100
satococoa merged 6 commits intomainfrom
codex/issue-90-auto-cd

Conversation

@satococoa
Copy link
Owner

@satococoa satococoa commented Feb 27, 2026

Summary

  • extend shell hooks (bash/zsh/fish) to handle wtp add
  • in interactive TTY sessions, run wtp add ... --quiet and cd to the created path on success
  • keep non-TTY behavior unchanged (no auto-cd)
  • update docs and hook tests for add auto-cd behavior

Closes #90

Summary by CodeRabbit

  • New Features

    • Added auto-switching to newly created worktrees when using wtp add -b in interactive shells.
    • Clarified that wtp add does not auto-switch directories when stdout is not a TTY.
  • Documentation

    • Updated guides to highlight shell navigation hooks and auto-switching capabilities.
    • Added interactive workflow examples demonstrating worktree creation and automatic directory switching.
  • Tests

    • Added test coverage for auto-directory switching after creating worktrees across bash, zsh, and fish shells.

Copilot AI review requested due to automatic review settings February 27, 2026 15:19
@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Warning

Rate limit exceeded

@satococoa has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 24 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3eafedd and 2a9c8db.

📒 Files selected for processing (3)
  • cmd/wtp/completion_config.go
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
📝 Walkthrough

Walkthrough

The changes add auto-directory-switching functionality after wtp add in interactive shell environments by implementing add subcommand handling in bash, zsh, and fish hook scripts. When stdout is a TTY, wtp add with --quiet flag returns a target directory, which the shell hook then changes into. Updates include comprehensive test coverage and documentation clarifications regarding shell navigation hooks and TTY behavior.

Changes

Cohort / File(s) Summary
Hook Script Implementation
cmd/wtp/hook.go
Added handling for the "add" subcommand across bash, zsh, and fish with logic to detect help flags, check TTY status, invoke wtp add --quiet to obtain target directory, and auto-cd on success.
Hook Script Tests
cmd/wtp/hook_test.go
New test suite TestHookScripts_AutoCdAfterAdd validating auto-cd behavior after add action for all three shell variants, checking guard logic, help flag handling, TTY checks, and directory changes.
Help Text and Documentation
cmd/wtp/shell_init.go, README.md, docs/architecture.md
Updated command descriptions from "cd functionality" to "shell navigation hooks," added notes on TTY behavior for auto-switching, introduced interactive workflow example with wtp add -b, and clarified documentation about auto-directory-switching in TTY sessions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

A rabbit adds with branch in mind,
One swift command, no pause to find,
The hook springs forth, TTY divine,
The burrow shifts—a new design! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding auto-cd functionality when creating a worktree via the add command in shell environments.
Linked Issues check ✅ Passed The PR implementation directly addresses issue #90 by extending wtp add to automatically change directory to the newly created worktree in interactive TTY sessions, eliminating the need for separate add and cd commands.
Out of Scope Changes check ✅ Passed All changes align with the stated objective of implementing auto-cd after wtp add, including hook scripts, tests, documentation updates, and user-facing help text describing the new behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/issue-90-auto-cd

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d0782a6a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements automatic directory switching after successful wtp add commands in interactive TTY sessions, addressing issue #90. The feature extends shell hooks for bash, zsh, and fish to intercept wtp add commands, execute them with the --quiet flag to get clean path output, and automatically cd to the newly created worktree. Non-TTY contexts (pipes, command substitution) maintain standard CLI behavior without auto-switching.

Changes:

  • Extended shell hooks (bash/zsh/fish) to detect wtp add commands and perform auto-cd in interactive TTY sessions
  • Updated documentation to explain the new auto-cd behavior and clarify shell integration capabilities
  • Added unit tests verifying the shell hook scripts contain correct TTY guards, quiet flag usage, and cd logic

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cmd/wtp/hook.go Added wtp add auto-cd logic to bash, zsh, and fish shell hooks with TTY detection and quiet mode
cmd/wtp/hook_test.go Added test cases verifying shell hooks generate correct auto-cd patterns for all three shells
cmd/wtp/shell_init.go Updated command descriptions to reflect expanded shell integration capabilities beyond just cd
docs/architecture.md Documented that shell hooks now support auto-switching after successful wtp add in interactive sessions
README.md Added usage example and explanation of auto-cd behavior for wtp add with TTY detection note

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@satococoa satococoa force-pushed the codex/issue-90-auto-cd branch from 0d0782a to 92f7c52 Compare March 1, 2026 14:21
Base automatically changed from codex/issue-91-add-quiet to main March 1, 2026 15:05
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/wtp/hook.go`:
- Around line 95-107: The wrapper currently returns the original `wtp` exit code
(`status`) even if `cd "$target_dir"` fails, so update the auto-switch flow (the
`elif [[ "$1" == "add" ]]` block and the similar blocks at the other
occurrences) to capture the `cd` command's exit status and return that if
non-zero; specifically, after computing `target_dir` and verifying `$status -eq
0` and `-n "$target_dir"`, run `cd "$target_dir"` and if `cd` fails propagate
its exit code (e.g., assign and return the `cd` exit code) instead of always
returning the original `status`.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77273d0 and 129b89b.

📒 Files selected for processing (5)
  • README.md
  • cmd/wtp/hook.go
  • cmd/wtp/hook_test.go
  • cmd/wtp/shell_init.go
  • docs/architecture.md

@satococoa satococoa merged commit 8e071a2 into main Mar 3, 2026
7 checks passed
@satococoa satococoa deleted the codex/issue-90-auto-cd branch March 3, 2026 14:38
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.

[Feature Request] add + cd

2 participants