Skip to main content

Rules & Instructions

PraisonAI automatically discovers and applies rules/instructions from multiple sources, similar to Cursor, Windsurf, Claude Code, and Codex CLI.

Supported Instruction Files

PraisonAI automatically loads these files from your project root and git root:
FileDescriptionPriority
PRAISON.mdPraisonAI native instructionsHigh (500)
PRAISON.local.mdLocal overrides (gitignored)Higher (600)
CLAUDE.mdClaude Code memory fileHigh (500)
CLAUDE.local.mdLocal overrides (gitignored)Higher (600)
AGENTS.mdOpenAI Codex CLI instructionsHigh (500)
GEMINI.mdGemini CLI memory fileHigh (500)
.cursorrulesCursor IDE rules (legacy)High (500)
.windsurfrulesWindsurf IDE rules (legacy)High (500)
.claude/rules/*.mdClaude Code modular rulesMedium (50)
.windsurf/rules/*.mdWindsurf modular rulesMedium (50)
.cursor/rules/*.mdcCursor modular rulesMedium (50)
.praison/rules/*.mdWorkspace rulesMedium (0)
~/.praison/rules/*.mdGlobal rulesLow (-1000)
Local Override Files: CLAUDE.local.md and PRAISON.local.md are personal overrides that should be gitignored. They have higher priority than the main files, allowing you to customize rules without affecting the shared project configuration.

Quick Start

Rules are automatically loaded when you create an Agent:
from praisonaiagents import Agent

# Create CLAUDE.md in your project root
# Agent auto-discovers and applies it
agent = Agent(
    name="Assistant",
    instructions="You are helpful."
)

# Rules are injected into system prompt automatically
response = agent.chat("Help me with Python")

Rule File Format

Rules support YAML frontmatter for advanced configuration:
# Project Guidelines

- Always use type hints for functions
- Follow PEP 8 style guide
- Write docstrings for public APIs
- Prefer async when possible

Activation Modes

ModeDescriptionUse Case
alwaysAlways applied (default)General guidelines
globApplied when file matches patternLanguage-specific rules
manualOnly via @mentionSecurity checklists, special procedures
ai_decisionAI decides when to applyContext-dependent rules

@Import Syntax (like Claude Code)

Include other files in your rules using the @path/to/file syntax:
# CLAUDE.md
See @README for project overview
See @docs/architecture.md for system design

# Additional Instructions
- Follow the patterns in @src/examples/
Import Depth Limit: Imports are limited to 5 levels deep to prevent circular dependencies. Code spans like `@org/package` are not treated as imports.

Git Root Discovery

PraisonAI automatically discovers rules from the git repository root, enabling monorepo support:
monorepo/                    # Git root
├── .git/
├── CLAUDE.md               # Discovered for all subdirs
├── .praison/rules/         # Discovered for all subdirs
├── packages/
│   ├── frontend/
│   │   ├── CLAUDE.md       # Higher priority for frontend
│   │   └── .praison/rules/
│   └── backend/
│       └── CLAUDE.md       # Higher priority for backend
Rules closer to the current working directory have higher priority than rules at the git root.

Storage Structure

project/
├── CLAUDE.md              # Auto-loaded (Claude Code compatible)
├── CLAUDE.local.md        # Local overrides (gitignored)
├── AGENTS.md              # Auto-loaded (Codex CLI compatible)
├── GEMINI.md              # Auto-loaded (Gemini CLI compatible)
├── PRAISON.md             # Auto-loaded (PraisonAI native)
├── PRAISON.local.md       # Local overrides (gitignored)
├── .cursorrules           # Auto-loaded (Cursor legacy)
├── .windsurfrules         # Auto-loaded (Windsurf legacy)
├── .claude/
│   └── rules/             # Claude Code modular rules
│       ├── code-style.md
│       └── testing.md
├── .windsurf/
│   └── rules/             # Windsurf modular rules
├── .cursor/
│   └── rules/             # Cursor modular rules
├── .praison/
│   ├── rules/             # Workspace rules
│   │   ├── python.md      # globs: ["**/*.py"]
│   │   ├── testing.md     # globs: ["**/*.test.*"]
│   │   └── security.md    # activation: manual
│   ├── workflows/         # Reusable workflows
│   └── hooks.json         # Pre/post operation hooks
└── ~/.praison/
    └── rules/             # Global rules (all projects)
        └── global.md

Programmatic Rules Management

from praisonaiagents.memory import RulesManager

# Create manager for your workspace
rules = RulesManager(workspace_path="/path/to/project")

# Get all loaded rules
all_rules = rules.get_all_rules()
for rule in all_rules:
    print(f"{rule.name}: {rule.description} (priority: {rule.priority})")

# Get active rules (always + ai_decision)
active = rules.get_active_rules()

# Get rules for a specific file (includes glob matches)
python_rules = rules.get_rules_for_file("src/main.py")

# Get a specific rule by name (for @mention)
security_rule = rules.get_rule_by_name("security")

# Build context string for LLM
context = rules.build_rules_context(
    file_path="src/main.py",
    include_manual=["security"]  # Include manual rules via @mention
)

Creating Rules Programmatically

from praisonaiagents.memory import RulesManager

rules = RulesManager(workspace_path="/path/to/project")

# Create a new rule
rules.create_rule(
    name="api_guidelines",
    content="""# API Guidelines
- Use RESTful conventions
- Version all endpoints
- Return proper status codes
- Document with OpenAPI
""",
    description="REST API development guidelines",
    globs=["**/api/**/*.py", "**/routes/**/*.py"],
    activation="glob",
    priority=15,
    scope="workspace"  # or "global"
)

# Delete a rule
rules.delete_rule("old_rule")

# Reload rules from disk
rules.reload()

# Get statistics
stats = rules.get_stats()
print(stats)
# {
#   'total_rules': 8,
#   'always_rules': 3,
#   'glob_rules': 2,
#   'manual_rules': 1,
#   'ai_decision_rules': 2,
#   'root_rules': 3,
#   'gitroot_rules': 1,
#   'workspace_rules': 2,
#   'claude_rules': 1,
#   'windsurf_rules': 1,
#   'global_rules': 0,
#   'sources': {'root': 3, 'workspace': 2, 'claude': 1, ...}
# }

AI Decision Activation

For ai_decision rules, PraisonAI can use an LLM to decide if a rule should be applied:
from praisonaiagents.memory import RulesManager

rules = RulesManager(workspace_path="/path/to/project")

# Get an ai_decision rule
rule = rules.get_rule_by_name("security")

# Evaluate if it should be applied to current context
def llm_func(prompt):
    return agent.chat(prompt)

should_apply = rules.evaluate_ai_decision(
    rule=rule,
    context="User is asking about database queries",
    llm_func=llm_func
)

if should_apply:
    print("Security rule should be applied")
Without an LLM function, ai_decision rules default to being included. This ensures rules are not accidentally skipped.

Agent Integration

The Agent class automatically initializes RulesManager:
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are helpful."
)

# Access rules manager
if agent._rules_manager:
    stats = agent._rules_manager.get_stats()
    print(f"Loaded {stats['total_rules']} rules")

# Get rules context manually
context = agent.get_rules_context(
    file_path="src/main.py",
    include_manual=["security"]
)
print(context)

Cross-Tool Compatibility

PraisonAI rules are compatible with other AI coding assistants:
ToolFileCompatibility
Claude CodeCLAUDE.md✅ Full
Codex CLIAGENTS.md✅ Full
Gemini CLIGEMINI.md✅ Full
Cursor.cursorrules, .cursor/rules/*.mdc✅ Partial
Windsurf.windsurfrules, .windsurf/rules/*.md✅ Partial
PraisonAI reads the same instruction files used by other AI coding assistants, making it easy to switch between tools while maintaining consistent behavior.

Best Practices

Create a PRAISON.md file in your project root with guidelines specific to your project. This file is automatically loaded with high priority.
Put language-specific rules in .praison/rules/ with appropriate glob patterns. For example, python.md with globs: ["**/*.py"].
Security checklists, deployment procedures, and other special rules should use activation: manual and be invoked via @mention when needed.
Use higher priority (50+) for critical rules that should override others. Default priority is 0 for workspace rules, -1000 for global rules.
Rules are injected into the system prompt, consuming context window. Keep rules focused and concise to leave room for conversation.

See Also