Cursor Implementation

Cursor-specific optimization including scoped .mdc rules, glob-based activation, Hooks-based enforcement, and subagent isolation

Token Optimization Guide / Cursor Implementation

Cursor Token Optimization

Layer 1 β€” Platform Mechanics

This is the one tool where scoped loading is the native primitive rather than an add-on: .mdc rules carry globs and description frontmatter, so a rule for src/api/** or drizzle/** only enters context when the agent is actually touching those files, instead of sitting in every session’s prefix like a flat file would. Use numbered filename prefixes (000-project.mdc, 100-typescript.mdc, 200-api-security.mdc…) to control concatenation order β€” earlier rules win on conflict. Delegate isolated or parallel work to subagents in .cursor/agents/*.md (review, verify, test personas), and reserve Skills (.cursor/skills/) for on-demand procedures β€” Cursor can even load Skills straight from ~/.claude/skills/ if you’re already maintaining those for Claude Code.

Key Strategies:

  • Scoped Rules as Native Primitive: .mdc rules with globs and description
    • Rules only load when matching files are touched
    • Eliminates always-loaded tax for irrelevant rules
    • Example: Rule for src/api/** only loads when working on API files
  • Filename Prefix Ordering: Numbered prefixes control concatenation order
    • 000-project.mdc, 100-typescript.mdc, 200-api-security.mdc
    • Earlier rules win on conflict
    • Predictable rule application
  • Subagent Delegation: Isolated or parallel work to subagents
    • .cursor/agents/*.md for review/verify/test personas
    • Isolated contexts for parallel execution (Cursor 2.4+)
    • Different model tiers per subagent
  • Skills Integration: Reserve Skills for on-demand procedures
    • .cursor/skills/ for Cursor-specific skills
    • Can load from ~/.claude/skills/ for cross-tool compatibility
    • Progressive disclosure reduces token overhead

Layer 2 β€” Agent Operation

There’s no dedicated plan-mode artifact like Antigravity’s; the equivalent operational control is Hooks, which can hard-block an expensive or destructive action (a force-push, a migration) before it runs rather than relying on the model to self-police. Team Rules β†’ Project Rules β†’ User Rules precedence means org-wide guardrails should live at the team level so individual projects can’t silently loosen them.

Operational Best Practices:

  • Hooks for Operational Control: Hooks replace plan-mode enforcement
    • Hard-block expensive/destructive actions before execution
    • Examples: force-push, database migrations
    • Don’t rely on model self-policing
  • Rule Precedence Hierarchy: Team Rules β†’ Project Rules β†’ User Rules
    • Org-wide guardrails at team level
    • Project-specific rules at project level
    • User personalizations at user level
    • Earlier wins on conflict
  • Guardrail Placement: Org-wide guardrails at team level
    • Prevents individual projects from silently loosening constraints
    • Consistent enforcement across organization
    • Team-level rules override project/user rules

Layer 3 β€” Codebase Architecture

Cursor’s own guidance is explicit: put the broad, human-readable operating model (architecture map, ownership, “do not touch” zones β€” i.e. your Layer 3 conventions) in AGENTS.md, and reserve .cursor/rules/ for instructions you want actively applied while the agent is editing or reviewing code. Don’t duplicate one into the other.

Architecture Rules:

  • AGENTS.md for Operating Model: Broad, human-readable architecture guidance
    • Architecture map, ownership, “do not touch” zones
    • Layer 3 conventions
    • Human-readable documentation
  • .cursor/rules/ for Active Instructions: Instructions applied during editing/reviewing
    • Task-specific guidance
    • Code review standards
    • Active enforcement rules
  • No Duplication: Don’t duplicate between AGENTS.md and .cursor/rules/
    • Each file has distinct purpose
    • Avoid redundant token consumption
    • Clear separation of concerns

Cursor-Specific Features

Scoped .mdc Rules

Cursor’s .mdc rule format with frontmatter provides sophisticated control:

  • Four Activation Modes: Controlled by frontmatter keys
    • alwaysApply: Always loads
    • globs: Loads when matching files are touched
    • description: Agent-decided based on description
    • Manual @mention: Explicit user invocation
  • Glob-Based Activation: Fine-grained file matching
    • src/api/** for API-specific rules
    • drizzle/** for database schema rules
    • Eliminates irrelevant context loading
  • Description-Based Activation: Agent decides based on task description
    • Intelligent rule selection
    • Reduces manual management
    • Agent-aware context loading

Practical .mdc Examples

000-project.mdc - Always-Apply Entry Point

---
description: Project overview and pointer to canonical rules
alwaysApply: true
---

# Project Rules β€” Entry Point

<!--
  Cursor loads this on every request (alwaysApply: true), so keep it
  minimal. Broad, human-readable operating context (architecture map,
  ownership, "do not touch" zones, conventions) belongs in AGENTS.md β€”
  don't duplicate it here. This file exists only to point at it and to
  hold the handful of things that genuinely apply to every single
  request regardless of which files are touched.
-->

See `AGENTS.md` at the project root for conventions, commands, and
guardrails.

## Always true, regardless of task

- [Package manager] only β€” never fall back to another one even if a
  lockfile for it appears.
- Stop and report on the first failing test or build error rather than
  attempting speculative fixes.

For anything file-specific or directory-specific, add a **scoped** rule
(with real `globs`) instead of adding another paragraph here β€” see
`200-high-risk-paths.mdc` for the pattern.

200-high-risk-paths.mdc - Scoped Rule Example

---
description: Guardrails for auth, billing, and migration code
globs:
  - "src/api/auth/**"
  - "src/billing/**"
  - "**/migrations/**"
alwaysApply: false
---

# High-risk paths

<!--
  This only enters context when the agent is actually editing a file
  matching one of the globs above β€” not on every request like
  000-project.mdc. That's the entire point of using a scoped rule
  instead of adding "oh, and be careful with billing code" to the
  always-apply file: the tax is paid only when it's relevant.
-->

- Never modify a migration file that has already been merged β€” create a
  new migration instead, even to fix a mistake in the previous one.
- Any change touching `src/billing/**` requires a corresponding test in
  the same PR; do not mark the task complete without one.
- Auth changes must not weaken an existing check (session validation,
  role checks, rate limiting) without an explicit instruction to do so.
- Flag, but do not silently fix, any hardcoded credential or API key you
  encounter in these paths β€” report it and stop.

Key Pattern: The scoped rule only loads when editing files matching the globs, eliminating the always-loaded token tax for irrelevant code paths.

Hooks System

Cursor’s Hooks provide operational control without plan mode:

  • Pre-Execution Blocking: Hard-block operations before they run
    • Force-push protection
    • Migration guards
    • Destructive operation prevention
  • Hook Types: Various hook points for different controls
    • Pre-execution hooks
    • Post-execution hooks
    • File-operation hooks
  • Model-Independent Enforcement: Hard enforcement regardless of model behavior
    • Don’t rely on model self-policing
    • Deterministic operational control
    • Reliable guardrails

Subagent System

Cursor’s subagent system (.cursor/agents/*.md) supports isolated parallel work:

  • Isolated Contexts: Each subagent has separate context
  • Parallel Execution: Multiple subagents can run in parallel (Cursor 2.4+)
  • Persona-Based Agents: Review, verify, test personas
  • Independent Model Configuration: Different models per subagent

Skills Integration

Cursor’s Skills system with cross-tool compatibility:

  • Native Skills: .cursor/skills/ for Cursor-specific procedures
  • Claude Skills Loading: Can load from ~/.claude/skills/
  • On-Demand Loading: Skills only load when relevant
  • Progressive Disclosure: Reduces always-loaded token overhead

Rule Precedence

Cursor’s hierarchical rule loading with conflict resolution:

  • Three-Tier Hierarchy: Team Rules β†’ Project Rules β†’ User Rules
  • Merge Behavior: Rules are merged, earlier wins on conflict
  • Org-Wide Enforcement: Team rules ensure consistent standards
  • Project Flexibility: Project rules can add, not remove, team constraints
  • User Personalization: User rules for individual preferences

Interactive Tools

Practical tools to help you think systematically, build better AI agents, and master prompt engineering.

Software Engineering Playbooks

Practical, End-to-End implementation guides for building Production-ready Software. Each playbook includes working code, architecture diagrams, and step-by-step instructions.

πŸ€–

Research Agent with Gateway

Build a production-ready AI research agent using Agent Gateway for unified traffic management, authentication, and observability across LLM providers.

Agent Gateway A2A Protocol Multi-Agent
πŸ”—

RAG Pipeline with Vector Database

Implement a complete Retrieval-Augmented Generation pipeline with vector embeddings, semantic search, and context injection for accurate AI responses.

RAG Vector DB Embeddings
πŸ”„

Multi-Agent Orchestration

Create a coordinated multi-agent system with specialized agents, task distribution, and result synthesis for complex problem-solving.

Orchestration Task Distribution Synthesis
1 / 2

Future References

Explore these resources for deeper learning on AI agent development, spec-driven development, and prompt engineering tools.

Spec-Driven Development

Comprehensive guide on Spec-Driven Development practices and methodologies.

Awesome Copilot

Curated list of GitHub Copilot resources, extensions, and best practices.

Promptfoo

Tool for testing, evaluating, and improving LLM prompts and applications.

Prompts.chat

Collection of prompt engineering resources and templates.

Agent Skills

Agent skills resources and documentation for building AI agent skills.

Awesome Skills

Curated list of awesome skill repositories and collections.

Agent Skills Topic

GitHub topic for discovering agent-related skills and repositories.

AI Agent Topic

Trendshift topic for discovering AI agents.

AI Skills Topic

Trendshift topic for discovering AI skills.

Agent Governance Toolkit

Agent governance toolkit.

Pattern Sources

Our patterns are curated from industry-leading sources with proper attribution and licensing compliance.

Refactoring.Guru

Classic GoF design patterns, code smells catalog, and refactoring techniques (https://refactoring.guru).

Enterprise Integration Patterns

65 messaging patterns for integrating enterprise applications by Gregor Hohpe and Bobby Woolf (CC BY 4.0).

Microservices.io

Comprehensive patterns for microservice architectures by Chris Richardson.

Agent Catalog Patterns

Patterns for agentic systems from agentpatternscatalog.org (CC BY 4.0).

OWASP Foundation

Security patterns from OWASP Top 10 for Web Applications, LLM Applications, and Agentic Applications (CC BY-SA 4.0).

Industry Research

ML/AI patterns from Microsoft, Google, Anthropic, and academic research.

AI Agent Patterns

Spec-driven development patterns from Claude, Gemini, OpenAI, and GitHub Copilot on github/spec-kit and OpenSpec.

Data Engineering Leaders

Data platform patterns from Martin Fowler (Data Mesh), Kimball Group (Dimensional Modeling), and cloud providers.

MLOps Best Practices

Data science patterns from MLflow, Great Expectations, and MLOps practitioners.

Streaming & Analytics

Real-time patterns from Confluent/Kafka, Apache projects, and serverless analytics platforms.

Academic Papers

Rigorous ML patterns from peer-reviewed research including data leakage prevention and active learning.

5-Day AI Agents Course

Intensive Vibe Coding Course With Google by Brenda Flynn et al. (2026) on Kaggle.

The Agent Loop

Foundational Agent Definition (Perceive + Act):
Russell, S. J., & Norvig, P. (1995). Artificial Intelligence: A Modern Approach. Prentice Hall. (Current edition: 4th Ed., Pearson, 2020)

Modern Iterative LLM Agent Loop:
Yao, S., Zhao, J., Yu, D., et al. (2022). ReAct: Synergizing Reasoning and Acting in Language Models. arXiv:2210.03629.

Historical Context:
Incorporating AIMA's perceive/act model, Classical robotics' Sense-Plan-Act loop (Brooks, 1986), and ReAct's Thought→Action→Observation cycle.