.claudeignore โ Block Unnecessary File Reading
Claude CodePrevent token waste + protect sensitive files
Claude Code reads project files during work. But if it reads node_modules/, build outputs, large data files, and sensitive files, the context window gets wasted with unnecessary tokens.
Create a .claudeignore file at the project root and Claude won't read files matching the specified patterns. Syntax is identical to .gitignore.
Why Is It Needed?
- Token savings โ large files (logs, datasets, binaries) fill up the context window quickly
- Security โ block Claude from reading
.env, credentials, secret key files - Better accuracy โ excluding irrelevant files lets Claude focus on what matters
- Speed improvement โ smaller search scope means faster Glob/Grep operations
Relationship with .gitignore
Files already in .gitignore are ignored by Claude by default. .claudeignore is for files tracked by Git but that you don't want Claude to see. For example, large fixture files or generated code may be in Git but Claude doesn't need to read them.
Recommended .claudeignore Template
# === Large / Unnecessary ===
node_modules/
vendor/bundle/
tmp/
log/
coverage/
.git/
# === Build Outputs ===
public/assets/
dist/
build/
*.min.js
*.min.css
# === Data / Binaries ===
*.sql
*.sqlite3
*.csv
*.xlsx
storage/
# === Sensitive ===
.env*
config/master.key
# === Generated Code ===
db/schema.rb
yarn.lock
Gemfile.lock
# === Media ===
*.mp4
*.mp3
*.png
*.jpg
*.pdf
How to Use
Create .claudeignore file at project root
Write ignore patterns using same syntax as .gitignore
Add large files, build outputs, sensitive files, unnecessary data
.claudeignore itself can be Git committed and shared with team
Tags
Source
Anthropic Docs