Last active
July 2, 2025 17:55
-
-
Save MatthewDailey/399a32818f70f30aa5adcc68df4179fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| if [ -z "$1" ]; then | |
| echo "Usage: $0 <branch-name>" | |
| exit 1 | |
| fi | |
| # Get editor command, default to claude | |
| EDITOR_CMD=${2:-claude} | |
| BRANCH_NAME=$1 | |
| MAIN_DIR=$(pwd) | |
| REPO_NAME=$(basename "$MAIN_DIR") | |
| PARENT_DIR=$(dirname "$MAIN_DIR") | |
| WORKTREE_DIR="${PARENT_DIR}/${REPO_NAME}-${BRANCH_NAME}-worktree" | |
| # Check if branch exists | |
| if git show-ref --verify --quiet refs/heads/$BRANCH_NAME; then | |
| echo "β Branch '$BRANCH_NAME' exists." | |
| else | |
| echo "π± Creating new branch '$BRANCH_NAME' from current HEAD..." | |
| git branch "$BRANCH_NAME" | |
| fi | |
| # Check if worktree already exists | |
| if [ -d "$WORKTREE_DIR" ]; then | |
| echo "β οΈ Worktree directory already exists at $WORKTREE_DIR" | |
| echo "Remove it with: git worktree remove \"$WORKTREE_DIR\"" | |
| exit 1 | |
| fi | |
| # Create worktree | |
| echo "π Adding worktree for branch '$BRANCH_NAME' at $WORKTREE_DIR..." | |
| git worktree add "$WORKTREE_DIR" "$BRANCH_NAME" | |
| cd $WORKTREE_DIR | |
| # unset keys | |
| unset GITHUB_TOKEN | |
| unset ANTHROPIC_API_KEY | |
| # Launch dev script in background | |
| echo "π Launching claude in $WORKTREE_DIR..." | |
| if [ -f "agent-setup.sh" ]; then | |
| echo "π§ Running agent setup script..." | |
| chmod +x agent-setup.sh | |
| ./agent-setup.sh | |
| fi | |
| $EDITOR_CMD . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment