Skip to main content
PraisonAI auto-discovers per-project instruction files (AGENTS.md, CLAUDE.md, .praisonai/rules/*.md) and injects them into every agent run — CLI and direct Agent(...) from Python. Opt out with rules=False when you need a sandboxed / reproducible run. The user works in a repo with instruction files; the agent discovers them and injects the rules into the system prompt on every run.
The Model Harness fragment sits before the rules block in the assembled system prompt, so family-tuned guidance comes first, then your project rules.

How It Works

always rules ship in the cached base prompt above; glob rules follow a second, per-turn path shown next.

Glob rules — per-turn

Supported Instruction Files

PraisonAI automatically loads these files from your project root and git root:
~/.praisonai/AGENTS.md is the global single-file layer used by load_context_files(). It is separate from the modular ~/.praisonai/rules/*.md files managed by RulesManager and has the lowest precedence — project-level files always override it.
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

1

Simple

Drop an instruction file in your project — the agent picks it up automatically.
2

With Configuration

Use RulesConfig when you need a character budget, extra rule files, or a different workspace root.
Opt out: pass rules=False for sandboxed / reproducible runs where project files must not leak into the prompt.

Precedence

rules= climbs the ladder from simplest to most explicit — Bool then RulesConfig — with rules=False as a standalone opt-out.

CLI Usage

Project instruction files are auto-injected into praisonai run, chat, and code — no Python required.

Rule File Format

Rules support YAML frontmatter for advanced configuration:
Glob rules are appended after the cached base prompt on every turn. This means:
  • Cache hits are unaffected — your always rules stay in the cached prefix.
  • Glob rules can appear or disappear between turns as the touched-files set changes — no restart needed.
Recursive globs (**/*.py) match both full paths (src/main.py) and bare filenames (foo.py). A user prompt like “open foo.py” is enough to activate the rule; a full path is not required.

Activation Modes

always rules ship in the cached base prompt. glob rules are evaluated per-turn and appended after the cache, so they can change from turn to turn as the agent opens new files. This is intentional — it keeps the cached prefix stable and lets path-scoped guidance follow the work.

How path-scoped rules activate

Rules with activation: glob fire the moment your agent reads or edits a matching file — no wiring needed.
The rule lives on disk as usual:
Pick an activation mode based on when the rule should apply:
Workspaces without any activation: glob rules pay zero cost — the whole path is gated on a cheap has_glob_rules() check.
A rule that is already emitted as always (or manually pinned) is not duplicated when a glob match also selects it. Path-scoped injection only adds rules not already present.

Path-Scoped Rules in Action

Requires praisonaiagents ≥ the release containing PR #3138. Earlier versions loaded glob rules but never injected them during agentic runs — only explicit agent.get_rules_context(file_path=...) calls activated them. Upgrade so a rule like .praisonai/rules/python.md (with activation: glob) fires as soon as the agent touches a .py file in a real run. Recursive globs (**/*.py) also match bare filenames (foo.py), fixed in the same release.
Author a glob rule and it fires the moment the agent touches a matching file during a run.
A rule with globs: ["**/*.py"] fires only when a filename token actually appears in the conversation:
Path collection is heuristic — it scans user prompts and tool result strings for tokens that look like a filename (something.ext, plus paths and quoted forms). Any tool that includes the file path in its result — the built-in file tools do — is enough for the matching glob rule to fire on the next turn. There is no need to thread paths through your own tools.

Configuration (RulesConfig)

Pass a RulesConfig when you need more than the default zero-config behaviour.
Discovery gate: the first time the agent runs, the workspace is scanned; if no instruction file is found, the RulesManager is dropped and every later run pays zero cost. Extra files are registered before the gate, so a workspace whose only rules are explicit files=[...] is never dropped. Programmatic equivalent: call RulesManager.add_rule_file(path) — the same machinery RulesConfig(files=[...]) uses under the hood.

Choose an option

@Import Syntax (like Claude Code)

Include other files in your rules using the @path/to/file syntax:
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:
Rules closer to the current working directory have higher priority than rules at the git root. The wrapper-layer load_context_files() (used by configure_host / context_paths) uses the same git-root walk-up and adds layered merge semantics — collecting AGENTS.md, CLAUDE.md, agents.md, and .agents/AGENTS.md at every directory level from ~/.praisonai/AGENTS.md (lowest) up through the git root to cwd (highest). See Context Files → CLI auto-loading for how chat, run, code, and tui automatically inject this context into the agent system prompt. Monorepos with per-subtree instruction files: see On-demand Subtree Attachment for how a sibling package’s AGENTS.md attaches the moment the agent opens a file inside it.

Storage Structure

Security & Path Safety

Enhanced in PR #1597: MCP praisonai.rules.* tools now validate rule_name against path traversal attacks.
The praisonai.rules.show, create, and delete MCP tools validate rule names to prevent path traversal: Rejected inputs:
  • Contains /, \, or \x00 (NUL byte)
  • Starts with . (blocks hidden files and ..)
  • Equals . or ..
  • The resolved path escapes ~/.praisonai/rules/ (symlink-safe)
Allowed pattern: Single filename with alphanumerics, underscores, hyphens, and dots (not leading), located strictly inside ~/.praisonai/rules/. Error format: Error: invalid rule_name: '<value>'

Programmatic Rules Management

The two glob helpers power the per-turn path-scoped injection shown in Path-Scoped Rules in Action.

Creating Rules Programmatically

AI Decision Activation

For ai_decision rules, PraisonAI can use an LLM to decide if a rule should be applied:
Without an LLM function, ai_decision rules default to being included. This ensures rules are not accidentally skipped.

Agent Integration

Rules are auto-applied on every .start() / .chat() / .run() call — no manual wiring needed.

Inspect what was loaded

CLI Integration

Project instruction files are auto-injected into praisonai run, praisonai chat, and praisonai code runs — no Python required.

CLI flags

Configuration

Global opt-out via ~/.praisonai/config.toml:
See CLI Config for the full TOML reference.

Cross-Tool Compatibility

PraisonAI rules are compatible with other AI coding assistants:
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 .praisonai/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.

Context Files

CLI auto-loading of AGENTS.md and CLAUDE.md

Hooks

Pre/post operation hooks for custom actions