agentsclimarketplace

Worktree

Skill huzaifa525/claude-code-optimizer/templates/.claude/skills/worktree

Optimize Claude Code token usage — 22 skills, 8 hooks, 6 rules. One npm install. Zero manual steps. Cut costs by 67%.

Install
npx -y skills add huzaifa525/claude-code-optimizer --skill worktree

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 9 stars9 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

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

SKILL.md

2.5 KB, as published. Nobody here has run it

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:

# 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
# 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:

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:

OptionCommandWhen
Mergegit checkout main && git merge $BRANCH_NAMEFeature is complete and tested
PRgh pr create from the worktree branchNeeds review before merge
KeepLeave worktree as-isWork in progress, will continue later
Discardgit worktree remove ../worktree-dirExperiment 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.
<!-- Skill by Huzefa Nalkheda Wala | github.com/huzaifa525 | claude-code-optimizer -->

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.