# Worktree Task

> Execute coding tasks in isolated git worktrees to keep your main branch clean and experiments safe.

Worktree Task is a free AI agent skill on Agensi by Harshit Vashistha, in Code Quality & Review. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Harshit Vashistha](https://www.agensi.io/creators/harshit-vashistha)
- Category: [Code Quality & Review](https://www.agensi.io/skills/code-quality-review)
- Version: 1.0
- Last updated: 2026-11-27
- Security: scan passed (2026-11-27); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/worktree-task
- Tags: code-review, git, refactoring, testing, workflow-automation

## About this skill

Running experimental refactors or risky migrations directly in your working directory leads to broken states and lost productivity. This skill automates the creation of isolated git worktrees to execute tasks on separate branches without touching your current files.

### What it does
- **Isolated execution** creates a temporary directory and branch for every task.
- **Environment validation** checks git status and branch state before starting work.
- **Automated testing** identifies and runs test suites within the worktree to validate changes.
- **Impact reporting** calculates exact line counts and file diffs against the base branch.
- **Workflow cleanup** handles the merging or deletion of worktrees based on your feedback.

### How it works
1. **Initialize** the skill by providing a coding task or refactor request.
2. **Setup** involves the agent creating a new worktree at `../<repo>-wt-<id>` on a fresh branch.
3. **Execution** occurs strictly within the worktree folder, including all commits and test runs.
4. **Review** the generated report containing diff stats and test results.
5. **Finalize** by choosing to merge the work, discard the branch, or continue iterating.

### Frameworks & tools
This skill works with any git-based project. It automatically detects test configurations in `package.json`, `pyproject.toml`, `Makefile`, and `README` files to ensure code quality.

### Why this beats prompting it yourself
Standard prompts often hallucinate paths or accidentally modify your local `HEAD` when trying to switch branches. This skill enforces strict directory isolation and automated cleanup logic that prevents your primary workspace from becoming inconsistent during complex tasks.

### Use cases
- **Risky refactors** where you want to see the impact before committing to the change.
- **Parallel prototyping** to compare two different implementation patterns side-by-side.
- **Dependency upgrades** to verify breaking changes without breaking your main dev environment.
- **Bug reproduction** on a clean branch while keeping your current work-in-progress stashed or active.

### Known limitations
Requires an initialized git repository. Uncommitted changes in the main directory are not automatically synced to the worktree.

## Requires

- Git

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Worktree Task skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill prevent my main workspace from getting cluttered during a refactor?

This skill eliminates the risk of a "dirty" workspace by creating physically separate directories for each coding task, allowing you to experiment and run tests without affecting your current local files or HEAD state.

### Which AI agents and programming languages are supported?

The skill is compatible with any AI agent that has file system and terminal access. It is language-agnostic and automatically detects test configurations in common files like package.json, pyproject.toml, and Makefiles.

### Will my uncommitted local changes be automatically moved to the new worktree?

No, the skill creates an isolated worktree. To maintain total safety, uncommitted changes in your main directory are not synced, ensuring your work-in-progress remains untouched and secure.

### What happens to the temporary worktree after the coding task is finished?

Once a task is complete, the skill provides a detailed impact report; you then have the option to automatically merge the changes into your target branch or delete the worktree to keep your environment clean.

### What is included with my purchase of the Worktree Task skill?

You receive the full skill logic, including the environment validation, automated testing, and worktree management protocols, along with documentation for integrating it into your preferred AI workflow.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
