Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/TashanGKD/tashan-cursor-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/tashangkd/tashan-cursor-skills/ide-context-guard)<a href="https://agentmods.dev/rules/tashangkd/tashan-cursor-skills/ide-context-guard"><img src="https://agentmods.dev/badge/rules/tashangkd/tashan-cursor-skills/ide-context-guard/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/rules/tashangkd/tashan-cursor-skills/ide-context-guard"><img src="https://agentmods.dev/badge/rules/tashangkd/tashan-cursor-skills/ide-context-guard.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.01223 | $0.01223 |
| Opus 5 | $0.00611 | $0.00611 |
| Sonnet 5 | $0.00245 | $0.00245 |
| Haiku 4.5 | $0.00122 | $0.00122 |
Grade A, and why
ide-context-guard scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
IDE 上下文隔离规则(ide-context-guard)
核心问题:Cursor 会将「当前打开的文件」和「最近查看的文件」自动注入到每次对话的 context 中。当你在执行 B 任务时,若 IDE 仍打开着 A 任务的文档,AI 会「看到」A 文档的内容,容易将其混入 B 任务的推理,导致任务混乱。
强制原则(每次收到用户消息时生效)
任务范围由「用户消息 + 对话历史」唯一决定,IDE 打开状态不得改写任务边界。
✅ 正确:用户说「帮我修改组织协作模式文档」→ 当前任务 = 该文档,与消息一致
❌ 错误:用户说「帮我修改组织协作模式文档」,但 IDE 开着技术架构.md → 不得把技术架构.md 混入本任务
❌ 错误:用户说「继续」+ 对话历史是认知文档操作,但 IDE 开着产品定义.md → 不得假定「继续」= 继续写产品定义
激活后立即执行(在序列 A 其他步骤之前)
Step 0 从「用户消息 + 最近 3 轮对话」推断:当前任务的主题/范围/涉及文档
- 用户是否 @ 了某文件?→ 该文件属于任务
- 用户是否明确了路径/项目/文档名?→ 属于任务
- 对话历史中上一轮在做什么?→ 延续则属于任务
Step 1 对比:IDE 当前打开/最近查看的文件 与 Step 0 推断的任务范围
- 若某文件不在任务范围内 → 视为「无关上下文」,本回合执行中忽略
- 不得因为「context 里有」就假定用户想操作该文件
- 不得用无关文件的内容去回答、修改、或引导任务方向
Step 2 若存在「打开文件与任务不匹配」的情况:
- 静默执行:不向用户输出「我忽略了 XXX 文件」(避免干扰)
- 内部约束:本回合的 Read/StrReplace/Write 仅针对任务范围内的文件
- 若任务范围无法确定(模糊指令 + 打开文件暗示不同任务)→ 必须先向用户确认(见 session-bootstrap A2)
典型禁止场景
❌ 用户说「帮我整理一下认知结构」,IDE 开着 项目A/技术架构.md
→ 不得去读/改技术架构.md,除非用户明确 @ 或提到
❌ 用户说「按规范执行」,对话历史是「刚更新了 L1 某文档」
→ 当前任务 = 认知文档后续操作,不是 IDE 打开的 产品定义.md
❌ 用户说「继续写」,上一轮在写 B 项目的功能
→ 当前任务 = B 项目,IDE 打开的 A 项目文件不参与
❌ 多项目 workspace:用户说「更新技术架构」
→ 必须根据对话历史确定项目,不能因为「IDE 打开了某项目的技术架构」就默认操作该项目
与其他规则的关系
| 规则 | 关系 |
|---|---|
session-bootstrap.mdc A2 |
本规则是 A2 的扩大版:A2 仅针对模糊指令,本规则针对所有消息的 IDE 上下文隔离 |
role-menu.mdc 规则12(IDE 状态不劫持意图) |
本规则是规则12的执行层落地,每次消息都强制执行 |
multi-project-file-guard.mdc |
多项目场景下,本规则保证「项目上下文」不来自 IDE 打开文件 |
变更记录
2026-03-21 — v1.0 — 初始创建
根因:用户反馈「执行 B 任务时,若打开了 A 任务的文档,B 任务会搞混」。Cursor 会自动注入 open_and_recently_viewed_files 到 context,AI 难以完全忽略已看到的内容。原有规则12和 session-bootstrap A2 仅覆盖「模糊指令」场景,且未在每次任务开始前强制做 IDE 关联性检查。
修改内容:
- 新增:ide-context-guard.mdc,alwaysApply: true
- 核心:每次消息先推断任务范围,IDE 打开的文件若不在范围内则隔离
验证方法:
- 正向:执行 B 任务时开着 A 文档,AI 不应读/改 A 文档,输出不应对 A 内容做出反应
- 负向:用户 @ 某文件或明确提及时,该文件正常参与
验证状态:🔵 待验证
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 9d ago First seen · 89 lines · 1,223 tokens per session scan A 246336ee78a9
ide-context-guard is a cursor rule published in the GitHub repository TashanGKD/tashan-cursor-skills (20 stars, last pushed 5mo ago), licensed MIT. It adds 1,223 tokens to every session, about $0.0061 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other cursor rules, from other repositories
10-feature-development
Feature implementation workflow and engineering mindset.
11-template-conventions
Reusable building blocks shipped with this template - use them instead of writing new ones.
03-ui
UI, layout, theming and localization standards.
12-new-project
Workflow for starting a new app from this template - rebranding, identity, cleanup and first feature.
13-updating-project
Workflow for updating an existing project - dependency and SDK upgrades, migrations, refactors, bug fixes.
01-tech-stack
Android tech stack and project standards.