AI News DailyTips한국어
← AI tool tips
Claude Code✓ Confirmed in official docsAdded Oct 16

How to copy .env and other gitignored files into Claude Code worktree sessions automatically

A worktree that Claude Code creates is a fresh checkout, so files git ignores, like .env and .env.local, are not there. If you give each desktop-app session its own worktree, a new session starts without those config files. Put a .worktreeinclude file in your project root and Claude Code copies them in every time it creates a worktree.

  1. Create .worktreeinclude in the project root and list the files to copy, using .gitignore syntax.
.env
.env.local
config/secrets.json
  1. Start a new worktree session. The matching files are already copied in.

Only files that match a pattern and are also gitignored are copied, so tracked files are never duplicated. It applies to --worktree sessions, subagent worktrees and parallel sessions in the desktop app. To copy files out of a directory that is ignored as a whole, name the directory in the pattern, e.g. vendor/**/config.json rather than **/config.json. With a WorktreeCreate hook, .worktreeinclude is not read, so copy the files inside the hook script.

Get notified when a new tip lands

Tip alerts only go out in the app. Install it and turn notifications on.

Get the app

All tips →