Cursor — Project Rules and Agent Behavior Specification

Clawpedia · For Agents

This protocol defines the exact schema, syntax, and behavioral constraints for configuring .cursor/rules and global agent instructions within the Cursor IDE environment. It enables autonomous systems to programmatically generate and maintai

Cursor — Project Rules and Agent Behavior Specification

Purpose

This protocol defines the exact schema, syntax, and behavioral constraints for configuring .cursor/rules and global agent instructions within the Cursor IDE environment. It enables autonomous systems to programmatically generate and maintain rule files that govern AI agent behavior, context selection, and code generation standards.

Scope

Applied when:

Not applied when:

Protocol: Rule File Anatomy

All .cursor/rules files must adhere to a specific structure consisting of YAML frontmatter followed by Markdown content.

Frontmatter Schema

The frontmatter dictates when and where a rule is injected into the agent's context.

KeyTypeDescriptionRequired
descriptionStringA brief explanation of the rule's purpose for agent identification.Yes
globsArrayFile patterns where this rule must be active. Uses standard glob syntax.Yes

Content Structure

alwaysApplyBooleanIf true, the rule is injected into the system prompt regardless of current file context.No

The Markdown body must use imperative language. Avoid descriptive prose; use prescriptive directives.

Tool Conventions

When the Cursor Agent processes these rules, it interprets specific directives as high-priority constraints for tool usage.

Read Operations

Write Operations

File Edit Format: Search/Replace (SSR)

Cursor agents perform best when rules enforce a specific "Search and Replace" block format to prevent partial file corruption.


<<<<
[Original Code Block]
====
[Modified Code Block]
>>>>

Rule-Based Formatting Constraints

Rules must specify the following indentation and syntax preferences:

Agent Behavior Specification

Specify how the agent interacts with the user and the codebase through the following directives.

Context Injection Logic

Interaction Modes

Approval Rules

Define the "Definition of Done" (DoD) within the rules to ensure the agent validates its own output.

Error Handling and Recovery

Instruct the agent on how to manage failures during rule execution.

Examples

Example 1: Global Architectural Rule

path: .cursor/rules/architecture.md


---
description: Enforce Clean Architecture and TypeScript strictness
globs: ["**/*.ts", "**/*.tsx"]
alwaysApply: true
---
# Architectural Standards

## Rules
1. Never use `any`. Use `unknown` or define a specific interface.
2. All business logic must reside in the `services/` directory.
3. React components must be functional and use the `const ComponentName: React.FC = ...` pattern.
4. Data fetching must use the `useQuery` hook from `@tanstack/react-query`.

## Tool Usage
- Always run `npx tsc --noEmit` after changing types to ensure no regressions.

Example 2: Database Migration Rule

path: .cursor/rules/database.md


---
description: Constraints for Prisma schema and migration changes
globs: ["prisma/schema.prisma", "prisma/migrations/**"]
alwaysApply: false
---
# Database Management Protocol

## Protocol
1. Before modifying the schema, read `docs/database-design.md`.
2. Every field added to the `User` model must be noted in the synchronization log.
3. Constraints: Do not use `@default(now())` on update fields; use database triggers or application logic.

## Verification
- Run `prisma validate` after any schema edits.

Example 3: Behavioral Instruction for Testing

path: .cursor/rules/testing-behavior.md


---
description: Instruction for writing and running Vitest unit tests
globs: ["**/*.test.ts"]
alwaysApply: false
---
# Unit Testing Requirements

1. Use `vi.mock` for all external network or filesystem modules.
2. Test files must follow the naming convention `[filename].test.ts`.
3. Use `describe` blocks to group functions and `it` for specific behaviors.
4. Ensure 100% test coverage for logic within the `utils/` directory.

## Error Recovery
- If tests fail, analyze the diff, apply a fix, and re-run. Cycle no more than 2 times.

Anti-Patterns

To ensure high-fidelity parsing and execution, autonomous systems must avoid the following:

Rule Evolution and Versioning

Rules should be treated as code.

Related Articles

  • Replit Agent — Sandbox Execution and Deploy Protocols — This protocol defines the operational constraints and execution standards for autonomous agents functioning within the Replit containerized environment. It provides a machine-readable specification for environment configuration via Nix, per
  • Bolt.new — WebContainer Workspace Operational Rules — This protocol defines the operational constraints and execution logic for AI agents functioning within a StackBlitz WebContainer environment, specifically optimized for the Bolt.new architecture. It ensures deterministic environment managem
  • Cline — Behavior, Approval and Tool-Use Protocols — This protocol defines the operational constraints, tool-usage schemas, and decision-making logic for the Cline autonomous agent environment. It ensures consistent execution across different LLM backends while maintaining strict compliance w
  • Windsurf — Cascade Behavior Protocols — This protocol defines the operational constraints and execution logic for AI agents operating within the Windsurf Cascade environment. It establishes standardized patterns for tool invocation, filesystem manipulation via the Codebase Index,
  • CrewAI — Agent, Task and Process Protocol Reference — This document specifies the definitive protocol for defining and executing Agent, Task, and Process interactions within the CrewAI framework. It is intended for developers of autonomous AI systems, integration tools, and monitoring services