# Cursor does not ignore files in .gitignore

**URL:** <https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430>\
**Category:** Bug Reports\
**Tags:** indexing, context, security\
**Created:** [March 11, 2026, 2:37pm UTC](https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430 "2026-03-11T14:37:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickredmark](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/nickredmark/32/101338_2.png) [@nickredmark](https://forum.cursor.com/u/nickredmark)\
**Post date:** [March 11, 2026, 2:37pm UTC](https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430/1 "2026-03-11T14:37:35Z")

</div>

### Where does the bug appear (feature/product)?

Cursor IDE

### Describe the Bug

In the ignore-files documentation it says that .gitignore is respected for the files cursor ignores: [Ignore files | Cursor Docs](https://cursor.com/help/customization/ignore-files) but it doesn’t thus leaking secrets to models used for autocomplete and agents…

### Steps to Reproduce

create .gitignore with content .env  
create .env  
no lock appearing next to file name  
start typing, you see tab completion  
ask agent the content of .env, it knows (without using terminal)

workaround: add .env to .cursorignore  
that works

### Operating System

MacOS

### Version Information

Version: 2.6.18  
VSCode Version: 1.105.1  
Commit: 68fbec5aed9da587d1c6a64172792f505bafa250  
Date: 2026-03-10T02:01:17.430Z (1 day ago)  
Build Type: Stable  
Release Track: Default  
Electron: 39.6.0  
Chromium: 142.0.7444.265  
Node.js: 22.22.0  
V8: 14.2.231.22-electron.0  
OS: Darwin arm64 24.6.0

### Does this stop you from using Cursor

No - Cursor works, but with this issue

---

<div class="post-metadata">

**Author:** ![deanrie](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/deanrie/32/1263_2.png) [@deanrie](https://forum.cursor.com/u/deanrie)\
**Post date:** [March 11, 2026, 3:55pm UTC](https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430/3 "2026-03-11T15:55:11Z")

</div>

Hey, this is a known issue. Quick summary: `.gitignore` and the default ignore list currently apply only to indexing, not to agent tools (Read file) and Tab completion. There’s more detail here: [Cursor IDE Agent Reads .env file!](https://forum.cursor.com/t/cursor-ide-agent-reads-env-file/151913)

You already found the right workaround, `.cursorignore`. If you don’t want to add it to every project, you can set it globally: VS Code Settings \> General \> Global Cursor Ignore List, then add ` **/.env` and `** /.env.*`.

One limitation: `.cursorignore` doesn’t block the agent’s terminal and MCP tools, so in theory the agent could run something like `cat .env` via the terminal. More info in the docs: [Ignore files | Cursor Docs](https://cursor.com/help/customization/ignore-files)

The team is aware of this gap between indexing ignores and agent tool ignores. Let me know if the global ignore list helps.

---

<div class="post-metadata">

**Author:** ![nickredmark](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/nickredmark/32/101338_2.png) [@nickredmark](https://forum.cursor.com/u/nickredmark)\
**Post date:** [March 11, 2026, 4:29pm UTC](https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430/5 "2026-03-11T16:29:42Z")

</div>

Thanks for the reply. When you say “known issue”, does it mean it’s a bug that the team is planning to fix, or an issue that confuses people but is going to stay as is?

I’m assuming it’s a bug because I seem to remember it having worked before (seeing the little forbidden icon next to .env, and we never used .cursorignore).

If it’s the latter, I’d recommend updating the documentation wherever .gitignore is mentioned, that this is only about indexing, that cursor can still read the file (without using terminal commands) and that it is feeded to the tab completion ai.

---

<div class="post-metadata">

**Author:** ![fenmati](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fenmati](https://forum.cursor.com/u/fenmati)\
**Post date:** [March 13, 2026, 2:32pm UTC](https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430/7 "2026-03-13T14:32:06Z")

</div>

This has to be changed asap in my opinion. Why would it not be a default setting to ignore anything .env? Especially because this behaviour changed. I remember tab and indexing not being available in my .env files in the past, probably because of my .gitignore files.  
And why is the global ignore setting in the VS Code settings and not the Cursor Settings. Why would I look in the VS Code settings to change the behaviour of Cursor? This seems almost like it’s intentionally hard not to leak my secrets.

---

<div class="post-metadata">

**Author:** ![deanrie](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/deanrie/32/1263_2.png) [@deanrie](https://forum.cursor.com/u/deanrie)\
**Post date:** [March 18, 2026, 6:11pm UTC](https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430/9 "2026-03-18T18:11:04Z")

</div>

Hey @nickredmark, per the docs the current behavior is expected. `.gitignore` and the default ignore list which includes `.env*` only apply to indexing. To block access for Agent, Tab, and Inline Edit, you need `.cursorignore`. It’s a separate, stricter mechanism.

From the docs: [Ignore File | Cursor Docs](https://cursor.com/docs/reference/ignore-file)

> `.cursorignore` blocks access from: Semantic search, Tab, Agent, Inline Edit, and @ mentions.  
> Default ignore list and `.gitignore` apply to indexing only.

So `.cursorignore` isn’t a workaround, it’s the intended tool for this. If you don’t want to add it to every project, there’s a global option: VS Code Settings \> General \> Global Cursor Ignore List, add ` **/.env` and `** /.env.*`.

I agree the line “Cursor already ignores .env files” in the docs can be confusing because it doesn’t clarify the scope.

@fenmati, about where this setting lives in VS Code Settings, I get that it’s not obvious. I passed the feedback to the team.

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/system/32/99069_2.png) [@system](https://forum.cursor.com/u/system)\
**Post date:** [April 9, 2026, 6:11pm UTC](https://forum.cursor.com/t/cursor-does-not-ignore-files-in-gitignore/154430/10 "2026-04-09T18:11:10Z")

</div>

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.
