AGENTS.md in your project root and every run sees it, no config needed.
AGENTS.md or CLAUDE.md; discovery merges layered markdown into the agent instructions.
Quick Start
How It Works
load_context_files() walks up from your current directory to the git root, collecting candidates at each level and concatenating them with the nearest file winning (appended last):
The merged content is prepended to the agent’s instructions:
On-demand Subtree Attachment
On-demand attachment picks up per-subtreeAGENTS.md / CLAUDE.md files the up-front walk-up missed, only when a file inside that subtree is actually touched.
Zero-config in a monorepo
When your host wires the attacher into the CLI auto-loader, on-demand attachment runs for you — drop a
packages/foo/AGENTS.md and it appears the first time the agent edits a file inside packages/foo/. If your host has not wired it in yet, reach for the stateless helper or the session class below.Behaviour guarantees
| Guarantee | Plain language |
|---|---|
| Subtree file attached only after a file under it is touched | Nothing loads until the agent opens something in that folder. |
| Files already in the up-front load are not re-attached | No duplicate rules from what loaded at startup. |
| A file emitted for one directory is not re-emitted for another | The same rules file never shows up twice. |
| Repeated touches of the same directory hit the cache | Re-opening a folder costs nothing — no disk re-read. |
A sibling directory with no AGENTS.md returns an empty string | Empty folders add nothing. |
Total emitted text is bounded by max_chars | The attached context can never grow past the budget. |
load_context_files_for_path(...) is a stateless one-shot | Use it when you touch a single path. |
Returns "" when nothing new is found | Silent when there is nothing to add. |
When do I need on-demand attachment?
PathContextAttacher is session-scoped by design. Create a new instance per session/agent run so cache and dedup state do not leak between users. Not thread-safe.CLI Auto-loading
As of PraisonAI PR #2358,praisonai chat, praisonai run, praisonai code, and praisonai tui automatically discover and inject AGENTS.md-style project context into the system prompt — no flag required.
Opt-out
CLI flag
Pass
--no-context to any of the four commands to skip all project-context loading for that invocation:Environment variable
Set
PRAISON_NO_CONTEXT=true in your shell or CI environment to disable auto-loading globally:Opt-out matrix
| Surface | Opt-out |
|---|---|
| CLI flag | --no-context |
| Env var | PRAISON_NO_CONTEXT=true |
InteractiveConfig field | no_context=True |
configure_host() param | no_context=True (or agent_kwargs={"no_context": True}) |
Token budget and truncation
The default budget is 8000 characters. When discovered context exceeds the budget, it is truncated and\n... [project context truncated] is appended. Override via:
InteractiveConfig(context_token_budget=16000)for interactive sessionsconfigure_host(context_token_budget=16000)for host integrations
Discovery runs once per session and the result is cached. Editing
AGENTS.md mid-session requires restarting the CLI to pick up changes.Configuration Options
Default File Discovery
When nocontext_paths is given, these filenames are checked at every directory level:
| Path | Description |
|---|---|
CLAUDE.local.md | Local overrides (highest precedence, git-ignored) |
AGENTS.md | Primary agent context file (Codex CLI compatible) |
agents.md | Alternative casing |
.agents/AGENTS.md | Hidden directory structure |
CLAUDE.md | Claude Code memory file |
GEMINI.md | Gemini CLI context file |
Discovery Scope
| Layer | Location | Precedence |
|---|---|---|
| User-global | ~/.praisonai/AGENTS.md | Lowest (loaded first) |
| Git/project root | Root-level candidates | Low |
| Intermediate dirs | Each dir between root and cwd | Medium |
| cwd | Current working directory candidates | Highest (loaded last) |
| Touched-file subtree (on-demand) | Nearest AGENTS.md/CLAUDE.md above the touched file | Appended after all up-front layers |
When no git root is found, the walk-up is capped at 10 levels to avoid scanning unrelated system directories.
walk_up Parameter
| Value | Behavior |
|---|---|
True (default) | Walk up to git/project root, include ~/.praisonai/AGENTS.md |
False | Read only from cwd, skip global file |
walk_up parameter is ignored when you pass an explicit paths list.
Explicit Paths (Backward Compatible)
Passcontext_paths to skip auto-discovery entirely — files are read from cwd only:
Choosing a Mode
Context Loading Behavior
cwd equals the git root, the same file is read only once (matched by inode, safe on case-insensitive volumes).
File Structure Examples
Basic AGENTS.md
Monorepo Layering
Place org-wide guidelines at the repo root and package-specific overrides closer to the working directory:packages/frontend/ automatically merges both files — root guidelines first, frontend overrides last (winning):
context_paths configuration needed.
User-Global Instructions
~/.praisonai/AGENTS.md applies across all your projects as the lowest-priority layer:
Common Patterns
Environment-Specific Context
Monorepo with sibling subtrees
Start a session at the repo root, then let the agent open files in different packages — each package’s ownAGENTS.md attaches the moment the agent touches a file there.
Conditional Context Loading
CI / Snapshot Testing
When you don’t want ancestor files to influence a test run, disable walk-up:Best Practices
File Organization
File Organization
Structure your context files for maintainability:
Content Structure
Content Structure
Keep context files focused and well-organized:
When to use walk_up=False
When to use walk_up=False
Disable walk-up for isolated CI jobs, snapshot tests, or any run where you want to guarantee only the files in the current directory are loaded — no ancestor directories, no global user file.
Content Management
Content Management
Version control your context files:
Use PathContextAttacher in long-running sessions
Use PathContextAttacher in long-running sessions
When the agent will touch many files across a monorepo, create one
PathContextAttacher per session and reuse it. The per-directory cache
means repeated touches of the same subtree cost nothing, and the char
budget stops the attached context from growing unbounded across the run.
Pass already_loaded=up_front (the string returned by load_context_files())
so files discovered up front are not re-attached.Testing Context Changes
Testing Context Changes
Validate context injection in development:
Related
Host Integration
Configure context injection
Rules & Instructions
Auto-discovered instruction files

