[BUG] Claude code does not respect .gitignore and project rules while exploring
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 agent regularly calls "Glob" tool as well as find and grep bash command listing and reading sensitive and ignored files like .env and node_modules. The files were included in the .gitignore and the agent was explicitly told not to in the CLAUDE.md to respect the .gitignore and to not touch the sensitive files. Closer investigation revealed that
1) .gitignore is not respected in the Glob (file listing / search) tool
2) The agent uses the built-in "Explore" sub-agent which ignores the project and user level CLAUDE.md and does not respect the project's .gitignore file.
What Should Happen?
- All agents should either respect the CLAUDE.md file or have another option to inject system prompt into them
- All agents and tools should respect .gitignore or at least be instructed to use it in for commands like
findand others.
Error Messages/Logs
Steps to Reproduce
Create a test repo containing .gitignore, put some files there and ask the agent to explore the project.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
v2.1.42
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗