๐Ÿšซ

.claudeignore โ€” Block Unnecessary File Reading

Claude Code

Prevent 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?

  1. Token savings โ€” large files (logs, datasets, binaries) fill up the context window quickly
  2. Security โ€” block Claude from reading .env, credentials, secret key files
  3. Better accuracy โ€” excluding irrelevant files lets Claude focus on what matters
  4. 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

1

Create .claudeignore file at project root

2

Write ignore patterns using same syntax as .gitignore

3

Add large files, build outputs, sensitive files, unnecessary data

4

.claudeignore itself can be Git committed and shared with team

Tags

#claudeignore #ignore #token #security #optimization #performance

Source

Anthropic Docs