ide-context-guard

ide-context-guard is a cursor rule for Cursor from TashanGKD/tashan-cursor-skills. It costs 1,223 tokens per session, scanned A, original, MIT.

A rule for keeping an agent’s task separate from unrelated files currently open in an IDE. An IDE is a code editor such as Cursor that may automatically show recently opened files to the agent.

In plain words
What is it for?
Use it when deciding which files belong to the current task, particularly in multi-project workspaces or when the instruction is vague.
Why use it?
It reduces confusion when the editor contains documents from another task or project by making the user’s request the only source of scope.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when deciding which files belong to the current task, particularly in multi-project workspaces or when the instruction is vague.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/tashangkd/tashan-cursor-skills/ide-context-guard
Install

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.

Clone the repo
git clone --depth 1 https://github.com/TashanGKD/tashan-cursor-skills

Made for: Cursor.

Wrote 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.

agentmods badge for ide-context-guard

README.md
[![agentmods](https://agentmods.dev/badge/rules/tashangkd/tashan-cursor-skills/ide-context-guard/github.svg)](https://agentmods.dev/rules/tashangkd/tashan-cursor-skills/ide-context-guard)
Your own site
<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.

agentmods 80×15 button for ide-context-guard

Your own site · 80×15
<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>
Per session 1,223 This file is loaded in full into every session.
When invoked 1,223 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce 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

Measured 9d ago against content hash 246336ee78a9, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

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.

rules/ide-context-guard.mdc · 89 lines

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 内容做出反应
  • 负向:用户 @ 某文件或明确提及时,该文件正常参与

验证状态:🔵 待验证

Changes

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.

  1. 9d ago First seen · 89 lines · 1,223 tokens per session scan A 246336ee78a9

Subscribe to this mod's changes

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.