# Adding Worktrees

## Basic Usage

```bash
wt a <branch> [-b [<start-point>]]
```

## Examples

```bash
wt a main                    # checkout existing branch
wt a feature/new -b          # create new branch from HEAD
wt a feature/new -b main     # create new branch from main
wt a feature/new -b v1.0.0   # create new branch from tag
```

## Hooks

When `wt a` runs **from inside an existing worktree**, hooks from `.wt.lua` are applied to the new worktree.

Running from project root skips hooks with a warning.

### Hook Types

| Hook      | Purpose                                  |
| --------- | ---------------------------------------- |
| `copy`    | Copy files from source worktree          |
| `symlink` | Create symlinks to source worktree files |
| `run`     | Execute shell commands in new worktree   |

### Example `.wt.lua`

```lua
return {
    hooks = {
        copy = {"Makefile", "*.mk"},
        symlink = {".env", "config.toml", "node_modules"},
        run = {"make setup", "npm install"}
    }
}
```

### Hook Permissions

First time hooks run in a project, `wt` prompts for permission via `gum confirm`. Permissions stored in `~/.local/share/wt/hook-dirs.lua`.

## Branch Resolution

When adding without `-b`:

1. Checks local branches
2. Checks all remotes
3. Fails if branch exists on multiple remotes (ambiguous)

## Path Styles

Configured in `~/.config/wt/config.lua`:

| Style              | Example Branch | Result Path           |
| ------------------ | -------------- | --------------------- |
| `nested` (default) | `feature/foo`  | `project/feature/foo` |
| `flat`             | `feature/foo`  | `project_feature_foo` |

```lua
return {
    branch_path_style = "flat",
    flat_separator = "_"
}
```
