WorktreeInitializer 1.4.0
dotnet tool install --global WorktreeInitializer --version 1.4.0
dotnet new tool-manifest
dotnet tool install --local WorktreeInitializer --version 1.4.0
#tool dotnet:?package=WorktreeInitializer&version=1.4.0
nuke :add-package WorktreeInitializer --version 1.4.0
WorktreeInitializer
A tool for copying gitignored files from a source repository to a new worktree. Works as both a CLI tool and an MCP (Model Context Protocol) server for AI agents.
When you create a git worktree, gitignored files like .env files, launchSettings.json with secrets, node_modules/, build outputs, and other local configuration are not included. This tool copies all of them over in one command.
Installation
dotnet tool install --global WorktreeInitializer
After installation, the wi command will be available globally.
To update to the latest version:
dotnet tool update --global WorktreeInitializer
To uninstall:
dotnet tool uninstall --global WorktreeInitializer
To register it as an MCP tool in Claude Code:
claude mcp add worktree-init -- wi --mcp
For Cursor or other MCP clients, add this to your MCP configuration:
{
"mcpServers": {
"worktree-init": {
"command": "wi",
"args": ["--mcp"]
}
}
}
Usage
wi init [--ignore <path>]... [--include <path>]...
wi init <source-path> <destination-path> [--ignore <path>]... [--include <path>]...
wi help
Examples
# Auto-detect: run inside a worktree to automatically find the source repo
cd ~/code/myproject-worktree
wi init
# Explicit paths: specify source and destination directly
wi init C:\code\myproject C:\code\myproject-worktree
# Exclude specific directories from copying
wi init ./myproject ./myproject-worktree --ignore node_modules --ignore .venv
# Re-include a path that would otherwise be ignored (include wins over ignore)
wi init ./myproject ./myproject-worktree --ignore node_modules --include node_modules
# Auto-detect with flags
wi init --ignore node_modules --ignore .venv
# Works with paths containing spaces (just quote them)
wi init "/home/user/my project" "/home/user/my project-wt"
# Unix paths work the same way
wi init ~/code/myproject ~/code/myproject-worktree
Auto-detect mode
When you run wi init with no paths inside a git worktree, it automatically detects the main repository as the source and uses the current directory as the destination. This is the simplest way to use the tool — just cd into your worktree and run wi init.
WorktreeConfig.json
You can place a WorktreeConfig.json file in the source repo root to define default ignores:
{
"ignores": ["node_modules", ".venv", "dist"]
}
- The file is optional — if missing, no default ignores are applied
- If present but malformed, an error is reported
- CLI
--ignoreflags are merged with config file ignores (union of both) --includeoverrides both CLI--ignoreand config file ignores (include always wins)
Behavior
Discovers ignored files using git
Runs git ls-files --others --ignored --exclude-standard in the source directory. This handles all .gitignore complexity: nested .gitignore files, global gitignore, .git/info/exclude, negation patterns, and every other gitignore feature.
Preserves directory structure
Files are copied to the same relative path in the destination. If src/bin/Debug/app.dll is ignored in the source, it will be copied to src/bin/Debug/app.dll in the destination.
Creates directories as needed
If the destination directory structure doesn't exist yet, it is created automatically during the copy.
Overwrites existing files
If a file already exists in the destination, it is overwritten. This makes it safe to re-run wi init if the source files have changed.
Partial failures are reported
If some files fail to copy (e.g. locked by another process), the rest are still copied. The output lists which files failed and why.
Requires git in PATH
Since the tool uses git ls-files to discover ignored files, git must be installed and available in PATH. If you're using git worktrees, you already have git installed.
As MCP Server
wi --mcp
When running as an MCP server, the following tools are available:
wi_init(sourcePath?, destinationPath?, ignorePaths?, includePaths?)- Copy all gitignored files from source to destination (paths auto-detected when omitted and server is running inside a worktree)wi_help()- Get help
Development
git clone <repository-url>
cd worktree-initializer
dotnet build WorktreeInitializer.slnx
dotnet test WorktreeInitializer.slnx
To run as MCP server during development:
dotnet run --project WorktreeInitializer.Cli/WorktreeInitializer.Cli.csproj -- --mcp
To package:
dotnet pack WorktreeInitializer.Cli/WorktreeInitializer.Cli.csproj --configuration Release
License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.