npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

worktree-for-agents

v1.2.3

Published

Standalone Git worktree manager with a stdio MCP service usable by any coding agent

Readme

Worktree manager

Standalone manager to create, complete, clean up, and recover worktrees of a Git repository. It ships a stdio MCP service that any coding agent can use.

Requirements

  • Python 3.9 or later. The entrypoint only checks that python3 is available on the PATH; the 3.9 floor is validated by the package postinstall and node <package>/setup.mjs. The package uses only the standard library.
  • Git 2.17.0 or later, for git worktree remove, which is the most recent command used by the manager. The test baseline is Git 2.54.0. The manager does not check the Git version at runtime.
  • Node 18 or later for the mcp-server.mjs, worktree.mjs and setup.mjs launchers.
  • bash to run the test suites.

Installation

The manager is distributed as the npm package worktree-for-agents, with no bin or npx:

npm install -g worktree-for-agents@latest
pnpm add -g worktree-for-agents@latest

Check the installation diagnostics:

node <package>/setup.mjs

Register the MCP service in each environment with the included writers:

node <package>/setup.mjs --write-opencode
cd <project> && node <package>/setup.mjs --write-claude

The guarantees of each registration are documented in the installation guide.

The repository clone is for development only. There is no pip install and no dependencies to resolve: the manager uses only the Python standard library. Once installed, the manager works without a network.

Quick start

Global options go before the subcommand and --repo requires an absolute path.

worktree.sh [--repo ABS] [--config ABS] [--json] create <id> [--base BRANCH] [--init-submodules] [--prepare] [--verify]
worktree.sh [globals] complete <id> [--base BRANCH] [--preserve-dirty] [--title TEXT] [--body TEXT] [--merge-strategy squash|preserve-history]
worktree.sh [globals] cleanup <id> [--discard]
worktree.sh [globals] recover [<transaction-id>]
worktree.sh [globals] prune
worktree.sh [globals] list

complete integrates only when the current base tip is an ancestor of the worktree branch, so the integrated tree is exactly the branch tree that was built and validated. If the base moved after the branch was created, it fails closed with base_changed (exit code 5) and changes nothing: merge or rebase the base into the branch, commit, and run complete again. See the CLI contract.

create --init-submodules initializes the declared submodules inside the new worktree. It also fingerprints the module directories that already exist in the main worktree: one that is already incomplete rejects the request before the worktree exists, and one that changes or disappears during initialization fails the request with the affected paths and retains the worktree and its branch. The check never restores or deletes module directories.

Target-direct operates on the repository given in --repo and does not create a parent worktree nor modify its HEAD. Its syntax places --parent-repo after the action and requires --submodule-path in create:

worktree.sh [--repo ABS] target-direct <action> <id> --parent-repo <parent> [--target submodule] [--submodule-path <REL>] [--base BRANCH] [--link-parent staged-only] [--descriptor PATH]

The actions are create, link-parent, abort, complete and recover, and the only supported link mode is --link-parent staged-only.

--json publishes a single JSON document. --request-json <file|-> publishes the same nine-key envelope used by the MCP transport, and optionally accepts --json. A dry run of create publishes planned: true and creates no worktree or branch.

The MCP service is published over stdio. From the installed package it is launched without bin:

node <package>/mcp-server.mjs

The CLI is used the same way:

node <package>/worktree.mjs --version

The MCP initialize publishes the guide in instructions:

Before you touch the main branch, offer to create an isolated worktree: create it with worktree_create, do all the work inside it, and close it with worktree_complete to integrate or worktree_cleanup to discard. If the worktree cannot be created or closed, correct the cause named in the error message before retrying.

For development, the transport also starts from the checkout:

PYTHONPATH=. python3 -m worktree_manager.mcp_transport

Configuration

The configuration is an optional key=value file, selected with --config or taken from .worktree-manager.conf at the repository root. The eleven keys and their default values are:

| Key | Default | Restriction | |---|---|---| | worktrees_dir | .worktrees | Must not start with - | | branch_prefix | worktree/ | — | | state_dir | worktree-manager | Safe relative path | | backup_dir | backups | Not an absolute path and contains no .. | | backup_ref_prefix | worktree-manager/backups | No .. | | lock_dir | locks | Safe relative path | | prepare_command | '' (empty) | Required when prepare_enabled=true | | verify_command | '' (empty) | Required when verify_enabled=true | | prepare_enabled | false | true or false | | verify_enabled | false | true or false | | preserve_dirty | false | true or false |

Each key may appear only once. Unknown keys, malformed lines, invalid booleans, and unsafe paths are rejected as invalid_configuration with exit code 3. The environment variable WORKTREE_MANAGER_<KEY>, with the key in uppercase, overrides the value read from the file.

Architecture

worktree.sh is the entrypoint and delegates the lifecycle to the Python package worktree_manager, which runs with python3 -m worktree_manager. The package is the only lifecycle implementation: there is no alternative shell engine.

The package is organized in modules with one responsibility each:

| Module | Responsibility | | --- | --- | | worktree_manager.cli | Command dispatcher, target-direct dispatch, and output contract. | | worktree_manager.configuration | Reading and validating the key=value configuration. | | worktree_manager.models | Shared domain values: results, errors, and identities. | | worktree_manager.output | Publishing the result as readable text or as JSON. | | worktree_manager.git_repository | Shared Git access for the lifecycle modules. | | worktree_manager.worktree_lifecycle | create, complete, cleanup, and prune operations. | | worktree_manager.commit_message | Deterministic closing message composition and neutral fallback. | | worktree_manager.target_direct_adapter | Target-direct operations on a submodule. | | worktree_manager.recovery_manager | Recovery of pending transactions. | | worktree_manager.transaction_journal | Durable transaction and link journal. | | worktree_manager.backup_store | Retained backup references. | | worktree_manager.lock_manager | Mutual exclusion between processes. | | worktree_manager.state_digest | Canonical digest of the repository state, the closure state of one worktree, and a plan. | | worktree_manager.mcp_server | MCP service published over stdio. | | worktree_manager.mcp_contract | Strict versioned request and envelope contracts. | | worktree_manager.mcp_operations | Facade over the lifecycle and recovery services. | | worktree_manager.mcp_transport | Stdio transport entrypoint. |

The package also contains the package marker __init__.py and the entrypoint __main__.py, which is what python3 -m worktree_manager runs.

Tests

bash tests/cli-usage.sh
bash tests/cli-json.sh
bash tests/compatibility.sh
bash tests/smoke.sh
bash tests/parity.sh
PYTHONPATH=. python3 -m unittest discover -s tests -p 'test_*.py'
PYTHONPATH=. python3 -m unittest discover -s tests -p 'test_mcp*.py' -v

Documentation

Contracts pin the verifiable behavior. The guide explains how to use it. The history records the transition and does not replace the contracts.

Source and distribution

This repository is the source of truth for the implementation, the contracts, the installation, and the manager history. The npm package is the only distribution channel; the manager does not keep a vendored copy of itself.