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-setup

v0.1.3

Published

Automatic setup for Git worktrees via post-checkout hook

Readme

worktree-setup

Automatic setup for Git worktrees via post-checkout hook. Works with any tool that creates worktrees - Cursor, Codex, wt CLI, or plain git worktree add.

Why?

Git worktrees are great for parallel development, but each new worktree needs setup:

  • Copy environment files (.env.local, etc.)
  • Install dependencies
  • Run build scripts

This package automates that by hooking into Git's native post-checkout hook.

Installation

bun add -D worktree-setup

Setup

1. Add configuration to package.json

{
  "worktreeSetup": {
    "copy": [
      ".env.local",
      ".vscode/settings.json"
    ],
    "run": [
      "bun install",
      "bun run prepare"
    ]
  }
}

2. Initialize hooks automatically

bunx worktree-setup init

This creates .git/hooks/post-checkout and adds .worktree-setup.log to .gitignore.

3. Configure the post-checkout hook manually (optional)

Using simple-git-hooks:

{
  "simple-git-hooks": {
    "post-checkout": "bunx worktree-setup"
  }
}

Using husky:

echo "bunx worktree-setup" > .husky/post-checkout

Or manually in .git/hooks/post-checkout:

#!/bin/sh
bunx worktree-setup

4. Add setup log file to .gitignore

.worktree-setup.log

Configuration

Add a worktreeSetup key to your package.json:

| Option | Type | Description | | ------ | ---------- | ------------------------------------------------- | | copy | string[] | Files/folders to copy from the main worktree | | run | string[] | Commands to run after copying (in the worktree) |

Example

{
  "worktreeSetup": {
    "copy": [
      ".env.local",
      ".env.development.local",
      ".claude/settings.local.json"
    ],
    "run": [
      "pnpm install --frozen-lockfile",
      "pnpm run build"
    ]
  }
}

How It Works

  1. When Git checks out a branch (including worktree creation), the post-checkout hook runs
  2. The script detects if it's in a linked worktree (not the main repo)
  3. Reads worktreeSetup config from the main worktree's package.json
  4. Copies specified files that don't already exist
  5. Runs specified commands
  6. Appends WORKTREE_SETUP_STATUS=success to .worktree-setup.log so it only runs once

CLI Options

bunx worktree-setup [options]
bunx worktree-setup init [options]

Options:
  -v, --verbose  Show detailed output
  --force        Overwrite existing post-checkout hook (init only)

Programmatic Usage

import { runSetup, detectWorktree } from 'worktree-setup'

// Run setup
const result = await runSetup({ verbose: true })
if (result.performed) {
  console.log('Setup completed!')
  console.log('Copied:', result.copiedFiles)
  console.log('Ran:', result.ranCommands)
}

// Just detect worktree info
const info = detectWorktree()
if (info?.isLinkedWorktree) {
  console.log('In worktree:', info.worktreeRoot)
  console.log('Main repo:', info.mainRoot)
}

Compatibility

Works with any tool that creates Git worktrees:

License

MIT