Skip to content

Add post-switch hook support#5

Open
grauschnabel wants to merge 3 commits intoksred:mainfrom
grauschnabel:feat/use-worktree-relative-path
Open

Add post-switch hook support#5
grauschnabel wants to merge 3 commits intoksred:mainfrom
grauschnabel:feat/use-worktree-relative-path

Conversation

@grauschnabel
Copy link

Summary

  • Add configurable post_switch hook in ~/.ccswitch/config.yaml that runs after every worktree switch
  • Hook is triggered by create, checkout, switch, and list commands
  • Shell integration (Bash + Zsh) extracts and evaluates hook commands via #post-hook: markers
  • Refactor worktree base path logic into shared getWorktreeBasePath() helper

Example config

hooks:
  post_switch: "claude"

Test plan

  • Configure post_switch hook and verify it runs after ccswitch create
  • Verify hook runs after ccswitch switch, checkout, and list
  • Verify no hook runs when config is absent
  • Test with both Bash and Zsh shell integration

🤖 Generated with Claude Code

Allow users to configure a post_switch hook in ~/.ccswitch/config.yaml
that executes automatically after switching worktrees (create, checkout,
switch, list). This enables workflows like auto-starting Claude Code in
new worktree directories.

Also refactors worktree base path logic into a shared helper method.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@grauschnabel
Copy link
Author

Note: The refactoring in internal/session/manager.go (extracting getWorktreeBasePath()) is a separate cleanup — it deduplicates the worktree base path logic that was inline in CreateSession and repeated in GetSessionPath. No behavioral change, just reducing duplication. Could have been a separate commit.

Martin Kaffanke and others added 2 commits February 13, 2026 17:33
Automatically detects worktrees whose branch is merged into origin/main,
removes the worktree, deletes the local branch, and cleans up the remote
branch if it still exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
merge-base --is-ancestor only works for regular merges. Squash merges
create new commits on main, so original branch commits are never
ancestors. Fix by collapsing the branch into a single diff via
commit-tree and using git cherry to check if that patch already
exists in the target.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant