|
| 1 | +# Guidelines for AI Coding Agents |
| 2 | + |
| 3 | +This document provides guidelines for AI coding agents (like Claude Code, Cursor, GitHub Copilot, etc.) working on the `wt` project. |
| 4 | + |
| 5 | +## Golden Rule: Use Worktrees! |
| 6 | + |
| 7 | +**IMPORTANT:** As an AI agent, you should practice what this tool preaches - use worktrees for your work! |
| 8 | + |
| 9 | +### ❌ DON'T: Switch branches in the main repository |
| 10 | +```bash |
| 11 | +# BAD - Don't do this! |
| 12 | +cd /path/to/main/wt/repo |
| 13 | +git checkout -b feature/new-branch |
| 14 | +``` |
| 15 | + |
| 16 | +This leaves the user's main working directory on a feature branch. |
| 17 | + |
| 18 | +### ✅ DO: Create worktrees for each task |
| 19 | +```bash |
| 20 | +# GOOD - Use wt to create isolated worktrees! |
| 21 | +wt create feature/new-branch |
| 22 | +# This creates: ~/dev/worktrees/wt/feature/new-branch |
| 23 | +# Main repo stays on main branch |
| 24 | +``` |
| 25 | + |
| 26 | +## Agent Workflow |
| 27 | + |
| 28 | +### 1. Starting New Work |
| 29 | + |
| 30 | +When beginning a new feature or fix: |
| 31 | + |
| 32 | +```bash |
| 33 | +# Create a worktree for your feature |
| 34 | +wt create feat/your-feature-name |
| 35 | + |
| 36 | +# The worktree is automatically checked out to: |
| 37 | +# ~/dev/worktrees/wt/feat/your-feature-name |
| 38 | +``` |
| 39 | + |
| 40 | +### 2. Working in the Worktree |
| 41 | + |
| 42 | +All file operations (Read, Write, Edit) should use paths in the worktree: |
| 43 | + |
| 44 | +```bash |
| 45 | +# Work in the worktree location |
| 46 | +/Users/username/dev/worktrees/wt/feat/your-feature-name/ |
| 47 | + |
| 48 | +# NOT in the main repo: |
| 49 | +# /Users/username/src/github/wt/ ❌ |
| 50 | +``` |
| 51 | + |
| 52 | +### 3. Committing and Creating PRs |
| 53 | + |
| 54 | +```bash |
| 55 | +# From within the worktree directory |
| 56 | +git add . |
| 57 | +git commit -m "feat: your feature description" |
| 58 | +git push -u origin feat/your-feature-name |
| 59 | + |
| 60 | +# Create PR |
| 61 | +gh pr create --title "feat: your feature" --body "Description" |
| 62 | +``` |
| 63 | + |
| 64 | +### 4. Cleaning Up |
| 65 | + |
| 66 | +After the PR is merged: |
| 67 | + |
| 68 | +```bash |
| 69 | +# Remove the worktree |
| 70 | +wt remove feat/your-feature-name |
| 71 | +# or use the short alias: |
| 72 | +wt rm feat/your-feature-name |
| 73 | +``` |
| 74 | + |
| 75 | +## Why This Matters for Agents |
| 76 | + |
| 77 | +### Benefits of Worktree-based Workflow |
| 78 | + |
| 79 | +1. **Non-disruptive:** User's main repository stays on `main` branch |
| 80 | +2. **Isolated:** Each feature gets its own directory |
| 81 | +3. **Parallel work:** Can work on multiple features simultaneously |
| 82 | +4. **Clean state:** No branch switching confusion |
| 83 | +5. **Predictable:** Always know where files are located |
| 84 | + |
| 85 | +### Common Pitfalls to Avoid |
| 86 | + |
| 87 | +❌ **Checking out branches in main repo** |
| 88 | +```bash |
| 89 | +# This disrupts the user's workspace |
| 90 | +cd /path/to/main/repo |
| 91 | +git checkout feature-branch |
| 92 | +``` |
| 93 | + |
| 94 | +❌ **Forgetting where you are** |
| 95 | +```bash |
| 96 | +# Always be aware of your current location |
| 97 | +# Are you in main repo or a worktree? |
| 98 | +``` |
| 99 | + |
| 100 | +❌ **Mixing work across locations** |
| 101 | +```bash |
| 102 | +# Don't edit files in main repo while working on a worktree feature |
| 103 | +``` |
| 104 | + |
| 105 | +✅ **Use wt commands consistently** |
| 106 | +```bash |
| 107 | +# Create worktrees |
| 108 | +wt create feat/new-feature |
| 109 | + |
| 110 | +# Check existing worktrees |
| 111 | +wt list |
| 112 | + |
| 113 | +# Remove when done |
| 114 | +wt rm feat/new-feature |
| 115 | +``` |
| 116 | + |
| 117 | +## Interactive Commands |
| 118 | + |
| 119 | +When run without arguments, several commands provide interactive selection: |
| 120 | + |
| 121 | +```bash |
| 122 | +# Interactively select a branch to checkout |
| 123 | +wt checkout |
| 124 | + |
| 125 | +# Interactively select a worktree to remove |
| 126 | +wt remove |
| 127 | + |
| 128 | +# Interactively select a PR to work on (requires gh CLI) |
| 129 | +wt pr |
| 130 | + |
| 131 | +# Interactively select an MR to work on (requires glab CLI) |
| 132 | +wt mr |
| 133 | +``` |
| 134 | + |
| 135 | +## Working with PRs and MRs |
| 136 | + |
| 137 | +### GitHub Pull Requests |
| 138 | +```bash |
| 139 | +# List and select from open PRs |
| 140 | +wt pr # Interactive selection |
| 141 | + |
| 142 | +# Or specify PR number/URL directly |
| 143 | +wt pr 123 |
| 144 | +wt pr https://github.com/owner/repo/pull/123 |
| 145 | +``` |
| 146 | + |
| 147 | +This creates a worktree at `~/dev/worktrees/wt/pr-123` |
| 148 | + |
| 149 | +### GitLab Merge Requests |
| 150 | +```bash |
| 151 | +# List and select from open MRs |
| 152 | +wt mr # Interactive selection |
| 153 | + |
| 154 | +# Or specify MR number/URL directly |
| 155 | +wt mr 456 |
| 156 | +wt mr https://gitlab.com/owner/repo/-/merge_requests/456 |
| 157 | +``` |
| 158 | + |
| 159 | +This creates a worktree at `~/dev/worktrees/wt/mr-456` |
| 160 | + |
| 161 | +## Project-Specific Guidelines |
| 162 | + |
| 163 | +### Branch Naming |
| 164 | +Follow the project's convention: |
| 165 | +- `feat/description` - New features |
| 166 | +- `fix/description` - Bug fixes |
| 167 | +- `docs/description` - Documentation |
| 168 | +- `refactor/description` - Refactoring |
| 169 | +- `chore/description` - Maintenance |
| 170 | + |
| 171 | +### Commit Messages |
| 172 | +Use [Conventional Commits](https://www.conventionalcommits.org/): |
| 173 | +- `feat: add interactive selection` |
| 174 | +- `fix: handle edge case in branch filtering` |
| 175 | +- `docs: update agent guidelines` |
| 176 | + |
| 177 | +### Before Creating PR |
| 178 | + |
| 179 | +1. ✅ Ensure all tests pass: `go test ./...` |
| 180 | +2. ✅ Run linter: `golangci-lint run` (or let CI do it) |
| 181 | +3. ✅ Build succeeds: `go build -o bin/wt .` |
| 182 | +4. ✅ Commit messages follow convention |
| 183 | + |
| 184 | +## Shell Integration Note |
| 185 | + |
| 186 | +The `wt` tool has shell integration that auto-navigates to worktrees: |
| 187 | + |
| 188 | +```bash |
| 189 | +# If user has shell integration enabled |
| 190 | +wt create my-feature |
| 191 | +# Shell automatically cd's to the worktree! |
| 192 | +``` |
| 193 | + |
| 194 | +However, as an agent executing commands, you need to explicitly use the worktree paths in subsequent file operations. |
| 195 | + |
| 196 | +## Example Agent Session |
| 197 | + |
| 198 | +Here's a complete example of an agent working on a feature: |
| 199 | + |
| 200 | +```bash |
| 201 | +# 1. Create worktree for new feature |
| 202 | +wt create feat/add-awesome-feature |
| 203 | +# Creates: ~/dev/worktrees/wt/feat/add-awesome-feature |
| 204 | + |
| 205 | +# 2. Work in that directory |
| 206 | +# All file operations use: |
| 207 | +# /Users/username/dev/worktrees/wt/feat/add-awesome-feature/ |
| 208 | + |
| 209 | +# 3. Make changes (Read, Write, Edit tools) |
| 210 | +# Edit /Users/username/dev/worktrees/wt/feat/add-awesome-feature/main.go |
| 211 | + |
| 212 | +# 4. Run tests in worktree |
| 213 | +cd /Users/username/dev/worktrees/wt/feat/add-awesome-feature |
| 214 | +go test ./... |
| 215 | + |
| 216 | +# 5. Commit and push |
| 217 | +git add . |
| 218 | +git commit -m "feat: add awesome feature" |
| 219 | +git push -u origin feat/add-awesome-feature |
| 220 | + |
| 221 | +# 6. Create PR |
| 222 | +gh pr create --title "feat: add awesome feature" \ |
| 223 | + --body "This adds an awesome feature that does X, Y, Z" |
| 224 | + |
| 225 | +# 7. After merge, clean up |
| 226 | +wt rm feat/add-awesome-feature |
| 227 | +``` |
| 228 | + |
| 229 | +## Questions? |
| 230 | + |
| 231 | +If you have questions about using `wt` as an agent: |
| 232 | +1. Read the main [README.md](README.md) |
| 233 | +2. Check [CONTRIBUTING.md](CONTRIBUTING.md) for workflow details |
| 234 | +3. Review examples in the documentation |
| 235 | + |
| 236 | +## Summary for Agents |
| 237 | + |
| 238 | +**Key Principle:** Use `wt` to create isolated worktrees for each task. Never switch branches in the user's main repository directory. |
| 239 | + |
| 240 | +This keeps the user's workspace clean and demonstrates best practices for the very tool you're helping to build! |
0 commit comments