Repository navigation
Description
Description
The read tool does not respect .gitignore patterns, allowing agents to read sensitive files that should be ignored (e.g., .env files, credentials, secrets). This contradicts user expectations and the documentation about ignore patterns.
Impact
Security risk: Agents can read sensitive files even when they are explicitly listed in .gitignore, potentially exposing:
- Environment variables (
.env,.env.*) - Credentials and secrets
- Private configuration files
- Any other files intended to be excluded from version control
Steps to Reproduce
- Add a directory to
.gitignore:
.scratch/- Create a file with sensitive content in that directory:
mkdir -p .scratch/test
echo "SECRET_API_KEY=super-secret-123" > .scratch/test/secrets.txt- Test different tools:
Tools that WORK correctly (respect .gitignore):
# glob tool - returns "No files found" ✅
glob pattern="**/.scratch/test/*.txt"
# grep tool - returns "No files found" ✅
grep pattern="super-secret" path="."Tool that FAILS (ignores .gitignore):
# read tool - successfully reads the file ❌
read filePath="/full/path/to/.scratch/test/secrets.txt"
# Returns: SECRET_API_KEY=super-secret-123Expected Behavior
The read tool should respect .gitignore patterns by default, just like glob, grep, and list tools do. If a file is in .gitignore, agents should not be able to read it unless explicitly permitted.
Actual Behavior
The read tool can read ANY file with an absolute path, regardless of .gitignore patterns.
Current Documentation
The docs at https://opencode.ai/docs/tools/#ignore-patterns state:
"Internally, tools like
grep,glob, andlistuse ripgrep under the hood. By default, ripgrep respects.gitignorepatterns"
However, the documentation does NOT mention that the read tool bypasses ignore patterns entirely.
Proposed Solutions
- Preferred: Make
readrespect.gitignorepatterns by default (consistent with other tools) - Alternative: Add a permission setting like
permission.read.respectIgnoreFiles(default: true) - Minimum: Update documentation to clearly warn users that
readbypasses.gitignore
Environment
- OpenCode version: Latest (as of Feb 4, 2026)
- Platform: macOS
- Configuration: Default tool permissions
Additional Context
This was discovered while testing ignore patterns for sensitive evaluation documents. The inconsistency between tools creates a false sense of security - users expect .gitignore to protect sensitive files from agents, but read silently bypasses this protection.
Common sensitive files that may be exposed:
.env,.env.local,.env.productioncredentials.json,secrets.yaml*.pem,*.key(private keys).aws/credentials- Any custom paths in
.gitignore
Activity
github-actions commentedon Feb 4, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
tredondo commentedon Feb 17, 2026
This is an important issue. Related: #4961. CC @rekram1-node
github-actions commentedon Apr 19, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.