# Worktree

> Use when the user wants to work in an isolated branch, start a safe development environment, or avoid polluting the main branch.

- **Type:** Skill
- **Install:** `agentstack add skill-huzaifa525-claude-code-optimizer-worktree`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [huzaifa525](https://agentstack.voostack.com/s/huzaifa525)
- **Installs:** 0
- **Category:** [Developer Tools](https://agentstack.voostack.com/c/developer-tools)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [huzaifa525](https://github.com/huzaifa525)
- **Source:** https://github.com/huzaifa525/claude-code-optimizer/tree/master/templates/.claude/skills/worktree
- **Website:** https://www.npmjs.com/package/claude-code-optimizer

## Install

```sh
agentstack add skill-huzaifa525-claude-code-optimizer-worktree
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

Create an isolated git worktree for safe development on: **$ARGUMENTS**

## Iron Law

> **All new feature work happens in a worktree. The main branch stays clean.**

If you think "this change is small enough to do on main" — you are wrong. Worktrees cost 5 seconds. Debugging a polluted main branch costs hours.

## Steps

### 1. Verify Clean Baseline

Before creating the worktree:

```bash
# Ensure we're in a git repo
git rev-parse --is-inside-work-tree

# Check for uncommitted changes
git status --porcelain
```

If there are uncommitted changes, ask the user whether to stash or commit them first. Do NOT proceed with dirty state.

### 2. Create the Worktree

Sanitize the branch name from the user's description:
- Lowercase everything
- Replace spaces and special characters with hyphens
- Remove consecutive hyphens
- Example: "User Notifications!" → `feature/user-notifications`

```bash
# Create worktree on a new branch
git worktree add "../$(basename $PWD)-feature-$BRANCH_NAME" -b "feature/$BRANCH_NAME"
```

### 3. Verify Test Baseline

Run the project's test suite in the new worktree BEFORE making any changes:

```bash
cd "../$(basename $PWD)-$BRANCH_NAME"
# Run tests (detect test command from package.json, Makefile, etc.)
```

If tests fail BEFORE any changes, the baseline is broken. Stop and report.

### 4. Work in the Worktree

- Make all changes in the worktree directory
- Commit frequently with descriptive messages
- Run tests after each meaningful change

### 5. Finish

When work is complete, present options:

| Option | Command | When |
|--------|---------|------|
| **Merge** | `git checkout main && git merge $BRANCH_NAME` | Feature is complete and tested |
| **PR** | `gh pr create` from the worktree branch | Needs review before merge |
| **Keep** | Leave worktree as-is | Work in progress, will continue later |
| **Discard** | `git worktree remove ../worktree-dir` | Experiment failed, throw it away |

## Red Flags

- "Let me just make this quick fix on main" — NO. Use a worktree.
- "The tests were already failing" — Then fix the baseline FIRST.
- "I'll clean up the branch later" — You won't. Clean it now.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [huzaifa525](https://github.com/huzaifa525)
- **Source:** [huzaifa525/claude-code-optimizer](https://github.com/huzaifa525/claude-code-optimizer)
- **License:** MIT
- **Homepage:** https://www.npmjs.com/package/claude-code-optimizer

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-huzaifa525-claude-code-optimizer-worktree
- Seller: https://agentstack.voostack.com/s/huzaifa525
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
