Skip to main content
Context files automatically inject markdown content into your agent’s instructions — drop an AGENTS.md in your project root and every run sees it, no config needed.
The user adds AGENTS.md or CLAUDE.md; discovery merges layered markdown into the agent instructions.

Quick Start

1

Drop an AGENTS.md in your project root

2

Run from any subdirectory — instructions load automatically

Or use the Python API:

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-subtree AGENTS.md / CLAUDE.md files the up-front walk-up missed, only when a file inside that subtree is actually touched.
1

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.
As of PraisonAI PR #2922 the AFTER_TOOL hook’s additional_context is now actually appended to the tool result. Earlier releases wired the hook but discarded its output, so subtree rules never reached the model — if you tried this recipe before and saw no effect, update to praisonaiagents 1.6.147 (PraisonAI release v4.6.144) and it will work as documented.
2

Attach for a single path (stateless)

3

Attach across many touches (session-scoped)

4

Wire it into an agent (auto-attach as tools run)

Register the hook on an agent and the nearest AGENTS.md attaches automatically the first time the agent reads or edits a file in a new subtree — no manual attach_for_path() calls.
The hook fires after each file tool, reads the touched path from filepath, file_path, path, filename, or target_file, and returns the nearest subtree rules as additional_context the first time that subtree is touched. Because it reads any of those keys, the hook fires correctly for both the wrapper file tools and the ACP-shaped tools without configuration.
The hook is session-scoped — its attacher owns the dedup and per-directory cache. Create one hook per session/agent run so state does not leak between users.
Register build_subtree_context_hook() on a dedicated per-session HookRegistry and pass that to Agent(hooks=…). Reusing the global default registry across sessions leaks the previous session’s attacher — the interactive core now does this automatically since PraisonAI PR #2922.

Behaviour guarantees

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

1

CLI flag

Pass --no-context to any of the four commands to skip all project-context loading for that invocation:
2

Environment variable

Set PRAISON_NO_CONTEXT=true in your shell or CI environment to disable auto-loading globally:
3

InteractiveConfig field

When using the interactive core programmatically:
4

configure_host() param

In host integrations, pass no_context=True directly or via agent_kwargs for backward compatibility:

Opt-out matrix

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 sessions
  • configure_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 no context_paths is given, these filenames are checked at every directory level:

Discovery Scope

When no git root is found, the walk-up is capped at 10 levels to avoid scanning unrelated system directories.

walk_up Parameter

The walk_up parameter is ignored when you pass an explicit paths list.

Explicit Paths (Backward Compatible)

Pass context_paths to skip auto-discovery entirely — files are read from cwd only:

Choosing a Mode

Context Loading Behavior

De-duplication is automatic: if cwd equals the git root, the same file is read only once (matched by inode, safe on case-insensitive volumes).

New public helpers

Two helpers wire the attacher into an agent’s hooks so subtree rules attach automatically as file tools run. Options for build_subtree_context_hook:

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:
Running from inside packages/frontend/ automatically merges both files — root guidelines first, frontend overrides last (winning):
No context_paths configuration needed.

User-Global Instructions

~/.praisonai/AGENTS.md applies across all your projects as the lowest-priority layer:
Every project you work in inherits these preferences unless overridden by a project-level file.

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 own AGENTS.md attaches the moment the agent touches a file there.
The agent picks up each package’s conventions the moment it opens 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

Structure your context files for maintainability:
Keep context files focused and well-organized:
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.
Version control your context files:
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.
For interactive sessions where the agent decides which files to touch, register build_subtree_context_hook() on HookEvent.AFTER_TOOL instead of calling attach_for_path() manually. The hook fires exactly when a file is touched, so the agent gets the nearest subtree rules just-in-time without you having to predict its path list up front. Pair with matcher=file_tool_matcher() so the hook skips non-file tools cheaply.
Validate context injection in development:

Host Integration

Configure context injection

Rules & Instructions

Auto-discovered instruction files