This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
simple-worktree is a Node.js CLI tool that simplifies Git worktree management by automatically syncing local development files (like .env files, certificates, etc.) between worktrees via symbolic links or one-time copies.
- CLI Entry Point:
bin/simple-worktree- Commander.js based CLI with command aliases - Main Library:
lib/directory containing modular functionality:create-worktree.js- Creates new worktrees with file syncingdelete-worktree.js- Safely removes worktreessync-files.js- Handles symbolic linking and file copying based on patternsconfig.js- TOML configuration managementgit-utils.js- Git operations wrapperinit-hooks.js- Sets up Git hooks for automatic syncingshell-functions.js- Shell integration for directory navigationlist-worktrees.js,cd-worktree.js,home.js- Utility commands
- Pattern-based file management: Uses gitignore-style patterns for flexible file matching
- Two sync modes:
- Symbolic links (
filesToSync) for shared files - One-time copies (
filesToCopy) for independent files
- Symbolic links (
- TOML configuration: Human-readable config in
swtconfig.toml - Git hooks integration: Optional automatic syncing via post-checkout hook
# Install dependencies
npm install
# Local development (symlink to global)
npm link
# Install from local directory
./install-local.shCurrently no automated tests are configured. Manual testing workflow:
# Create test worktree
swt create test-feature
# Verify file syncing
ls -la ../test-feature/.env # Should be symlink if configured
# Delete test worktree
swt delete test-feature# Version bump and publish to npm
npm version patch/minor/major
npm publishThe tool uses swtconfig.toml for configuration. Key fields:
defaultWorktreeDir- Where to create worktrees (default: "../")filesToSync- Array of patterns for files to symlinkfilesToCopy- Array of patterns for files to copy onceaddToGitignore- Auto-add synced files to .gitignore (default: true)
- Create new module in
lib/(e.g.,lib/new-command.js) - Export from
lib/index.js - Add command handler in
bin/simple-worktreeusing Commander.js pattern - Follow existing error handling patterns with chalk for colored output
File syncing logic is in lib/sync-files.js. Key functions:
syncPattern()- Creates symbolic linkscopyPattern()- Copies files onceupdateGitignore()- Updates .gitignore with synced paths
Pattern matching uses the minimatch library with gitignore-style syntax.
Git operations are wrapped in lib/git-utils.js. Always use these utilities rather than direct execSync calls for consistency and error handling.
- Always preserve backwards compatibility with existing
swtconfig.tomlfiles - File patterns should follow gitignore syntax exactly
- Symbolic links must point to absolute paths for reliability
- Windows compatibility requires special handling for symlinks
- The tool should only sync files NOT tracked by Git (Git handles tracked files automatically)