Keeping CLAUDE.md out of shared Git repos
Add it to $GIT_DIR/info/exclude so it stays local
Adding a CLAUDE.md
file to your project directory is a great way to give Claude Code context and instructions about the repository that persist across sessions. But you might not want to add it to your Git repository if you’re working in a shared codebase. You also can’t just edit the .gitignore
file, since it’s tracked by Git.
A simple solution is to add CLAUDE.md
to your user-local Git exclude file, which is located at $GIT_DIR/info/exclude
.
From Git’s gitignore docs: “Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow) should go into the $GIT_DIR/info/exclude file.”
This file works like .gitignore
but isn’t tracked by Git and applies only to your local repository.
Run this command after executing the /init
command in Claude Code:
echo "CLAUDE.md" >> "$(git rev-parse --git-dir)/info/exclude"
git rev-parse --git-dir
outputs $GIT_DIR, which is usually .git
in the root of your repository.