Skip to content

fix(git-worktree): auto-copy .env files when creating worktrees#27

Merged
kieranklaassen merged 2 commits intoEveryInc:mainfrom
skinnyandbald:fix/git-worktree-env-copy
Dec 2, 2025
Merged

fix(git-worktree): auto-copy .env files when creating worktrees#27
kieranklaassen merged 2 commits intoEveryInc:mainfrom
skinnyandbald:fix/git-worktree-env-copy

Conversation

@skinnyandbald
Copy link
Copy Markdown
Contributor

Summary

This PR fixes a common issue where .env files aren't automatically copied when creating git worktrees, causing development setup failures in new worktrees.

Problem

When Claude Code users create worktrees using raw git worktree add commands (instead of the manager script), environment files are not copied over. This leads to:

  • Development servers failing to start
  • Missing API keys and configuration
  • Confusion about why the new worktree isn't working

Solution

1. Enhanced SKILL.md documentation

Added a prominent "CRITICAL: Always Use the Manager Script" section that:

  • Explicitly instructs Claude to NEVER use git worktree add directly
  • Shows correct vs incorrect examples
  • Explains what the script handles (env files, .gitignore, directory structure)

2. Script already had the functionality

The worktree-manager.sh script already included:

  • copy_env_files() function that copies .env* files
  • Automatic env file copying during create command
  • A copy-env command for existing worktrees that missed the copy

The issue was that the SKILL.md didn't make it clear enough that Claude MUST use the script, leading Claude to call raw git commands instead.

Changes

  • skills/git-worktree/SKILL.md - Added CRITICAL section, updated all examples to use script path, added troubleshooting section for missing env files
  • (No changes to worktree-manager.sh - the functionality already existed)

Testing

Verified that:

  • Creating a worktree via the script copies .env, .env.local, .env.test files
  • The copy-env command works for existing worktrees
  • The SKILL.md examples all use the correct script path

Problem:
When Claude creates worktrees, it sometimes calls `git worktree add` directly
instead of using the worktree-manager.sh script. This means .env files don't
get copied to the new worktree, causing the app to fail on startup.

Solution:
1. Add copy_env_files() function to worktree-manager.sh that copies all .env*
   files (except .env.example) from main repo to new worktree
2. Call copy_env_files() automatically during worktree creation
3. Add new 'copy-env' command to manually copy env files to existing worktrees
4. Update SKILL.md with CRITICAL section instructing Claude to NEVER call
   git worktree add directly - always use the manager script
5. Update all code examples to use ${CLAUDE_PLUGIN_ROOT} for portability
6. Add troubleshooting section for missing .env files

Features:
- Automatically copies .env, .env.local, .env.test, etc.
- Skips .env.example (should be in git)
- Creates .backup if destination already exists
- New 'copy-env' command for manual copying to existing worktrees
@kieranklaassen
Copy link
Copy Markdown
Collaborator

Thanks!

@kieranklaassen kieranklaassen merged commit 4b49e53 into EveryInc:main Dec 2, 2025
@skinnyandbald
Copy link
Copy Markdown
Contributor Author

Thanks!

Np, great work @kieranklaassen !

armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 18, 2026
Graduated compression plan (Approach C) for non-Schelling instruction
content across 28 review agents and top 5 skills. Three phases: category-name
compression, enumeration+example compression, process compression -- each
validated by ablation. Blocked on EveryInc#19+EveryInc#27 execution.

Conservative post-EveryInc#19+EveryInc#27 savings estimate: ~15-20KB.
armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 19, 2026
…egative-space agent optimization

Classify all 28 review agents into Schelling tiers and apply graduated
compression. T1 (8 agents): full negative-space rewrite (75% reduction).
T2 (9 agents): graduated compression retaining load-bearing sections (27%).
T3/T4 (11 agents): identity-only compression (3%).

Total: 36,219 bytes saved (26% of 137,595B agent content).
Ablation-validated on 4 agents spanning all tiers -- no quality regression.
Unblocks EveryInc#18 Kolmogorov Compression.
armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 19, 2026
armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 19, 2026
Apply four compression patterns (category-name, enumeration, example,
process) across 20 non-T1 review agents and 5 top skills. Graduated
three-phase execution with ablation validation at each phase.

Total: 90,771 bytes saved (33% of 273,888B instruction corpus).
Combined with EveryInc#19+EveryInc#27: ~127KB total agent+skill reduction.

Phase 1 (P1 category-name): 12,977B across 17 agents.
Phase 2 (P2+P4 enum+example): 21,565B across 10 files.
Phase 3 (P3 process): 57,812B across 11 files.

Ablation noise floor calibrated at 0.47 composite (identical-content
self-comparison), rendering the plan's 0.95 threshold unreachable
with single-run evaluations. All scores within noise floor range.
762/764 tests pass (2 pre-existing resolve-base.sh failures).
armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 21, 2026
Graduated compression plan (Approach C) for non-Schelling instruction
content across 28 review agents and top 5 skills. Three phases: category-name
compression, enumeration+example compression, process compression -- each
validated by ablation. Blocked on EveryInc#19+EveryInc#27 execution.

Conservative post-EveryInc#19+EveryInc#27 savings estimate: ~15-20KB.
armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 21, 2026
…egative-space agent optimization

Classify all 28 review agents into Schelling tiers and apply graduated
compression. T1 (8 agents): full negative-space rewrite (75% reduction).
T2 (9 agents): graduated compression retaining load-bearing sections (27%).
T3/T4 (11 agents): identity-only compression (3%).

Total: 36,219 bytes saved (26% of 137,595B agent content).
Ablation-validated on 4 agents spanning all tiers -- no quality regression.
Unblocks EveryInc#18 Kolmogorov Compression.
armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 21, 2026
armstrongl added a commit to nuggylib/compound-engineering-plugin that referenced this pull request Apr 21, 2026
Apply four compression patterns (category-name, enumeration, example,
process) across 20 non-T1 review agents and 5 top skills. Graduated
three-phase execution with ablation validation at each phase.

Total: 90,771 bytes saved (33% of 273,888B instruction corpus).
Combined with EveryInc#19+EveryInc#27: ~127KB total agent+skill reduction.

Phase 1 (P1 category-name): 12,977B across 17 agents.
Phase 2 (P2+P4 enum+example): 21,565B across 10 files.
Phase 3 (P3 process): 57,812B across 11 files.

Ablation noise floor calibrated at 0.47 composite (identical-content
self-comparison), rendering the plan's 0.95 threshold unreachable
with single-run evaluations. All scores within noise floor range.
762/764 tests pass (2 pre-existing resolve-base.sh failures).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants