Created
November 27, 2025 17:44
-
-
Save itissid/14e852472dd4e6a03901eeb0a2fba1ff to your computer and use it in GitHub Desktop.
Worktree detection for slash command
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
| # Global Worktree Script Access Implementation Plan | |
| ## Overview | |
| Enable the `/create_worktree` slash command to work in any project by: | |
| 1. Fixing the hardcoded `--directory humanlayer` in the bash script | |
| 2. Making the script globally accessible via symlink | |
| 3. Leveraging the existing `humanlayer claude init` command for slash command portability | |
| ## Current State Analysis | |
| ### What Exists: | |
| - `hack/create_worktree.sh` - Worktree creation script with one hardcoded value | |
| - `hack/cleanup_worktree.sh` - Cleanup script (no hardcoded values) | |
| - `.claude/commands/create_worktree.md` - Slash command that calls the script | |
| - `humanlayer claude init` - Already copies `.claude/commands/` to other projects | |
| ### Key Discovery: | |
| **`humanlayer claude init --all` already distributes slash commands!** (`hlyr/src/commands/claude/init.ts:294-367`) | |
| Users can run this in any project to get all HumanLayer slash commands including `/create_worktree`. | |
| ### The Problem: | |
| Line 123 of `hack/create_worktree.sh`: | |
| ```bash | |
| if humanlayer thoughts init --directory humanlayer > /dev/null 2>&1; then | |
| ``` | |
| This hardcoded `humanlayer` breaks the script for other repos. | |
| ## Desired End State | |
| After this plan is complete: | |
| 1. User can run `humanlayer claude init --all` in any project to get slash commands | |
| 2. The `/create_worktree` command works for any repository | |
| 3. The script auto-detects the repo name for thoughts initialization | |
| 4. A global symlink allows direct script invocation: `create-worktree [name] [branch]` | |
| ### Verification: | |
| ```bash | |
| # In a different project (not humanlayer) | |
| cd ~/workspace/other-project | |
| humanlayer claude init --all | |
| # Now /create_worktree is available | |
| # Run the slash command - should work without error | |
| ``` | |
| ## What We're NOT Doing | |
| - Not creating a `humanlayer worktree` CLI command (future enhancement) | |
| - Not modifying the hlyr TypeScript codebase | |
| - Not changing the cleanup script (already repo-agnostic) | |
| - Not adding new dependencies | |
| ## Implementation Approach | |
| Minimal changes to make the existing system work across projects: | |
| 1. Fix the one hardcoded value in the bash script | |
| 2. Document the global symlink setup | |
| 3. Update slash command to handle any repo | |
| --- | |
| ## Phase 1: Fix the Bash Script | |
| ### Overview | |
| Change the hardcoded `--directory humanlayer` to use the dynamically detected repo name. | |
| ### Changes Required: | |
| #### 1. Fix hardcoded directory in create_worktree.sh | |
| **File**: `hack/create_worktree.sh` | |
| **Line**: 123 | |
| **Change**: Replace hardcoded `humanlayer` with `$REPO_BASE_NAME` | |
| **Current code (line 123):** | |
| ```bash | |
| if humanlayer thoughts init --directory humanlayer > /dev/null 2>&1; then | |
| ``` | |
| **New code:** | |
| ```bash | |
| if humanlayer thoughts init --directory "$REPO_BASE_NAME" > /dev/null 2>&1; then | |
| ``` | |
| **Note**: `$REPO_BASE_NAME` is already defined at line 44 as `$(basename "$(pwd)")`, so this variable is available. | |
| ### Success Criteria: | |
| #### Automated Verification: | |
| - [ ] Script passes bash syntax check: `bash -n hack/create_worktree.sh` | |
| - [ ] Script is executable: `test -x hack/create_worktree.sh` | |
| #### Manual Verification: | |
| - [ ] Run script in humanlayer repo - still works as before | |
| - [ ] Variable expansion confirmed: add `echo "Using directory: $REPO_BASE_NAME"` temporarily to verify | |
| **Implementation Note**: This is a 1-line change. After automated verification passes, test manually in humanlayer repo. | |
| --- | |
| ## Phase 2: Create Global Symlink Documentation | |
| ### Overview | |
| Document how users should set up global access to the script. | |
| ### Changes Required: | |
| #### 1. Add setup instructions to README | |
| **File**: `README.md` (or create `docs/worktree-setup.md`) | |
| **Location**: After the MULTICLAUDE feature description (~line 42) | |
| **Add section:** | |
| ```markdown | |
| ### Global Worktree Script Setup | |
| To use the worktree creation script from any project: | |
| 1. **Create the symlink** (one-time setup): | |
| ```bash | |
| ln -s /path/to/humanlayer/hack/create_worktree.sh ~/bin/create-worktree | |
| # Or wherever your PATH includes | |
| ``` | |
| 2. **Create base directory** for each repo you want to use worktrees with: | |
| ```bash | |
| mkdir -p ~/wt/your-repo-name | |
| ``` | |
| 3. **Initialize thoughts directory** (if using thoughts system): | |
| Ensure `~/thoughts/repos/your-repo-name/` exists before running the script. | |
| 4. **Get slash commands in your project**: | |
| ```bash | |
| cd ~/workspace/your-project | |
| humanlayer claude init --all | |
| ``` | |
| This copies `/create_worktree` and other useful commands to your project. | |
| ``` | |
| ### Success Criteria: | |
| #### Automated Verification: | |
| - [ ] README lint passes (if applicable) | |
| #### Manual Verification: | |
| - [ ] Instructions are clear and complete | |
| - [ ] Following the steps works on a fresh project | |
| --- | |
| ## Phase 3: Update Slash Command for Multi-Repo | |
| ### Overview | |
| The slash command at `.claude/commands/create_worktree.md` has hardcoded paths. Update to be repo-agnostic. | |
| ### Changes Required: | |
| #### 1. Update create_worktree.md | |
| **File**: `.claude/commands/create_worktree.md` | |
| **Changes**: Replace hardcoded `humanlayer` references with dynamic detection | |
| **Key lines to update:** | |
| Line 27 (example worktree path): | |
| ```markdown | |
| # Before: | |
| worktree path: ~/wt/humanlayer/ENG-XXXX | |
| # After: | |
| worktree path: ~/wt/$REPO_NAME/ENG-XXXX | |
| ``` | |
| Lines 36-41 (launch command): | |
| ```markdown | |
| # Before: | |
| humanlayer launch --model opus -w ~/wt/humanlayer/ENG-XXXX "/implement_plan..." | |
| # After: | |
| humanlayer launch --model opus -w ~/wt/$REPO_NAME/ENG-XXXX "/implement_plan..." | |
| ``` | |
| **Note**: The slash command template uses placeholders that Claude Code interprets. Use `$REPO_NAME` or instruct the user/Claude to detect it via `basename $(git rev-parse --show-toplevel)`. | |
| ### Success Criteria: | |
| #### Automated Verification: | |
| - [ ] Markdown syntax valid | |
| - [ ] No hardcoded `/humanlayer/` paths remain | |
| #### Manual Verification: | |
| - [ ] Slash command works in humanlayer repo | |
| - [ ] Slash command generates correct paths for other repos | |
| --- | |
| ## Phase 4: Test End-to-End in Another Project | |
| ### Overview | |
| Validate the complete flow works in a non-humanlayer project. | |
| ### Test Steps: | |
| 1. **Setup test project:** | |
| ```bash | |
| cd ~/workspace | |
| git init test-worktree-project | |
| cd test-worktree-project | |
| mkdir -p ~/wt/test-worktree-project | |
| ``` | |
| 2. **Initialize thoughts (if applicable):** | |
| ```bash | |
| mkdir -p ~/thoughts/repos/test-worktree-project/shared | |
| mkdir -p ~/thoughts/repos/test-worktree-project/itissid | |
| ``` | |
| 3. **Get slash commands:** | |
| ```bash | |
| humanlayer claude init --all | |
| ``` | |
| 4. **Run the script directly:** | |
| ```bash | |
| ~/bin/create-worktree test-feature main | |
| # Should create ~/wt/test-worktree-project/test-feature/ | |
| ``` | |
| 5. **Verify:** | |
| - [ ] Worktree created at correct path | |
| - [ ] Branch created | |
| - [ ] Thoughts initialized (if directory exists) | |
| - [ ] .claude directory copied | |
| ### Success Criteria: | |
| #### Manual Verification: | |
| - [ ] Worktree creation works for non-humanlayer repo | |
| - [ ] Thoughts init uses correct directory name | |
| - [ ] No errors or hardcoded path references | |
| --- | |
| ## Testing Strategy | |
| ### Unit Tests: | |
| None required - this is a bash script fix. | |
| ### Integration Tests: | |
| None automated - manual verification sufficient for this scope. | |
| ### Manual Testing Steps: | |
| 1. Test in humanlayer repo (regression) | |
| 2. Test in fresh git repo (new functionality) | |
| 3. Test with `--no-thoughts` flag | |
| 4. Test with existing branch name | |
| 5. Test with auto-generated name | |
| ## Migration Notes | |
| - Existing worktrees are unaffected | |
| - Users with custom setups may need to update their symlinks | |
| - No breaking changes to the script interface | |
| ## References | |
| - Research document: `thoughts/shared/research/2025-11-27-git-worktree-usage.md` | |
| - Thoughts init implementation: `hlyr/src/commands/thoughts/init.ts:319-728` | |
| - Claude init implementation: `hlyr/src/commands/claude/init.ts:48-384` | |
| - Existing script: `hack/create_worktree.sh` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment