> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Rules

> Auto-discovered instruction files for agent behavior

The `rules` command manages auto-discovered instruction files that control agent behavior.

## Quick Start

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# List all loaded rules
praisonai rules list
```

<Frame>
  <img src="https://mintcdn.com/praisonai/2OBv0nvWLwS-3tNQ/docs/cli/rules-list-auto-discovered-rules.gif?s=959a215a3598f03ddd565ac05574e00a" alt="List auto-discovered rules example" width="1497" height="1104" data-path="docs/cli/rules-list-auto-discovered-rules.gif" />
</Frame>

## Usage

<img src="https://mintcdn.com/praisonai/fT4nF3hY6KPMOPvS/docs/cli/rules-manage-auto-discovered-rules.gif?s=3bb833ee70e604ad4f6f9d3a7089868a" alt="Manage Auto-Discovered Rules" width="1497" height="1104" data-path="docs/cli/rules-manage-auto-discovered-rules.gif" />

### List Rules

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai rules list
```

**Expected Output:**

```
╭─ Loaded Rules ───────────────────────────────────────────────────────────────╮
│  📜 PRAISON.md (project root)                                               │
│  📜 CLAUDE.md (project root)                                                │
│  📜 .cursorrules (project root)                                             │
│  📜 python-guidelines.md (.praison/rules/)                                  │
╰──────────────────────────────────────────────────────────────────────────────╯
```

### Show Rule Details

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai rules show <rule_name>
```

### Create Rule

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai rules create my_rule "Always use type hints"
```

### Delete Rule

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai rules delete my_rule
```

### Show Statistics

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai rules stats
```

### Include Rules with Prompts

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Task" --include-rules security,testing
```

## Auto-Discovered Files

PraisonAI automatically discovers instruction files from your project root and git root:

| File                      | Description                   | Priority |
| ------------------------- | ----------------------------- | -------- |
| `PRAISON.md`              | PraisonAI native instructions | High     |
| `PRAISON.local.md`        | Local overrides (gitignored)  | Higher   |
| `CLAUDE.md`               | Claude Code memory file       | High     |
| `CLAUDE.local.md`         | Local overrides (gitignored)  | Higher   |
| `AGENTS.md`               | OpenAI Codex CLI instructions | High     |
| `GEMINI.md`               | Gemini CLI memory file        | High     |
| `.cursorrules`            | Cursor IDE rules              | High     |
| `.windsurfrules`          | Windsurf IDE rules            | High     |
| `.claude/rules/*.md`      | Claude Code modular rules     | Medium   |
| `.windsurf/rules/*.md`    | Windsurf modular rules        | Medium   |
| `.cursor/rules/*.mdc`     | Cursor modular rules          | Medium   |
| `.praison/rules/*.md`     | Workspace rules               | Medium   |
| `~/.praisonai/rules/*.md` | Global rules                  | Low      |

## Rule File Format

### Basic Format

```markdown theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Guidelines

- Use type hints for all functions
- Follow PEP 8 style guide
- Include docstrings for public methods
```

### With YAML Frontmatter

```markdown theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
---
description: Python coding guidelines
globs: ["**/*.py"]
activation: always  # always, glob, manual, ai_decision
---

# Guidelines

- Use type hints
- Follow PEP 8
```

### @Import Syntax

Reference other files in your rules:

```markdown theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# CLAUDE.md
See @README for project overview
See @docs/architecture.md for system design
@~/.praisonai/my-preferences.md
```

## How It Works

1. **Discovery**: Scans project root and git root for rule files
2. **Priority**: Higher priority rules override lower priority
3. **Injection**: Rules are injected into agent system prompts
4. **Activation**: Rules activate based on globs or manual selection

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
flowchart LR
    A[Project Root] --> B[Scan Files]
    B --> C[PRAISON.md]
    B --> D[CLAUDE.md]
    B --> E[.cursorrules]
    B --> F[.praison/rules/]
    C --> G[Merge by Priority]
    D --> G
    E --> G
    F --> G
    G --> H[Inject into Agent]
```

## Activation Modes

| Mode          | Description                           |
| ------------- | ------------------------------------- |
| `always`      | Rule is always active                 |
| `glob`        | Active when file matches glob pattern |
| `manual`      | Only active when explicitly included  |
| `ai_decision` | AI decides when to apply              |

## Programmatic Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

# Agent auto-discovers CLAUDE.md, AGENTS.md, GEMINI.md, etc.
agent = Agent(name="Assistant", instructions="You are helpful.")
# Rules are injected into system prompt automatically
```

## Agent-Requested Rules

Agents can create, read, and manage rules dynamically using built-in tools:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonaiagents.tools.rules_tools import (
    create_rule_tool,
    list_rules_tool,
    get_rule_tool,
    delete_rule_tool,
    get_active_rules_tool
)

# Create an agent that can manage rules
agent = Agent(
    name="RulesManager",
    role="Rules Administrator",
    tools=[create_rule_tool, list_rules_tool, get_rule_tool, delete_rule_tool]
)

# Agent can now create rules dynamically
response = agent.chat("Create a rule for Python coding standards")
```

### Available Tools

| Tool                    | Description                                       |
| ----------------------- | ------------------------------------------------- |
| `create_rule_tool`      | Create a new rule with name, content, and options |
| `list_rules_tool`       | List all available rules                          |
| `get_rule_tool`         | Get content of a specific rule                    |
| `delete_rule_tool`      | Delete a rule                                     |
| `get_active_rules_tool` | Get rules active for current context              |

### Tool Parameters

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
create_rule_tool(
    name="python-style",           # Rule name (filename)
    content="- Use type hints",    # Rule content
    description="Python standards", # Short description
    globs="**/*.py",               # Comma-separated glob patterns
    activation="glob",             # always, glob, manual, ai_decision
    priority=10,                   # Higher = applied first
    scope="workspace"              # workspace or global
)
```

## Best Practices

<Tip>
  Use `.local.md` files for personal preferences that shouldn't be committed to git.
</Tip>

<Warning>
  High-priority rules override lower-priority ones. Be careful with conflicting instructions.
</Warning>

| Do                                    | Don't                              |
| ------------------------------------- | ---------------------------------- |
| Use PRAISON.md for project-wide rules | Put personal prefs in shared files |
| Use .local.md for personal overrides  | Commit .local.md files             |
| Use globs for language-specific rules | Apply all rules to all files       |
| Keep rules concise and actionable     | Write verbose instructions         |

## Related

* [Rules Feature](/features/rules)
* [Hooks CLI](/cli/hooks)
* [Workflow CLI](/cli/workflow)
