[BUG] "Respect Git Ignore" setting doesn't prevent access to gitignored files via Bash tool
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The "Respect Git Ignore" setting does not prevent Claude Code from accessing files listed in .gitignore when using the Bash tool to directly read them.
Actual Behavior:
Gitignored files can be accessed via Bash commands despite the "Respect Git Ignore" setting being enabled. This allows Claude Code to access sensitive credential files (.env, .pem, private keys, etc.) that users reasonably expect to be protected by the gitignore setting.
Environment:
Claude Code version: 1.0.120 (Claude Code)
VS Code version: 1.96.4
What Should Happen?
Expected Behavior:
The "Respect Git Ignore" setting should block ALL access to gitignored files, including:
Direct file reads via the Bash tool
Read tool access
Grep tool access
Any other method of file access
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce:
Enable "Respect Git Ignore" setting in Claude Code preferences
Ensure a file (e.g., .env) is listed in the repository's .gitignore
Ask Claude Code to run a bash command that directly accesses the gitignored file (e.g., grep -n "PATTERN" .env)
Observe that the command executes successfully and returns the file contents
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
1.0.120
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗