Learning resourcesReviewed · Pydantic

RepoContext guide for Pydantic AI Harness

This guide helps Python developers reuse repository instructions in Pydantic AI coding assistants, but safe use depends on trusting the files being loaded. It explains instruction loading, optional discovery of assistant assets, nested directory context, and configuration limits.

Researched 25 Nov 2026

In short.

This guide explains repository context loading for developers building Pydantic AI coding assistants, but the files it loads must be trusted. RepoContext loads working-directory instructions by default, can include ancestor instructions, and surfaces nested instructions as files and directories are accessed. Optional inventory locates skills, agents and hooks without parsing them. Important limits include backend-dependent symlink protection, changing 0.x APIs, and accepted-file pinning that RepoContext does not yet enforce. The documented behavior and benchmark claims were not independently tested.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete documentation page at [https://pydantic.dev/docs/ai/harness/repo-context/index.md], including its examples, API reference, trust warnings, cache discussion, deprecation notices and upgrade guidance. Linked pages, source code and benchmark details are excluded. Exact release compatibility, licensing, monetary costs and real-world behavior remain unknown or unassessed where the page does not establish them. Nothing was executed.

The overview

Identity

Repo Context is a documentation guide for RepoContext, a capability in Pydantic AI Harness that discovers and loads a repository's coding-assistant context. Here, context means instruction files such as AGENTS.md and CLAUDE.md, plus assistant assets under .claude, .agents, .codex and .grok.

The guide includes configuration examples, trust explanations, upgrade notes and an API reference. Its address is [https://pydantic.dev/docs/ai/harness/repo-context/index.md].

Assessment

The guide is useful when a Pydantic AI coding assistant needs to reuse instructions already distributed across a repository. It explains which files reach the model, their order, and when nested instructions appear.

Its main adoption concern is authority: files loaded at run start become agent instructions. The documentation also warns that RepoContext does not check the authority reductions produced by accepted-file pinning. An application therefore cannot rely on that helper alone to stop changed files from being loaded.

Users

The primary audience is Python developers building or maintaining coding assistants with Pydantic AI Harness. It is particularly relevant to repositories with instructions in multiple directories or assets created for several assistant ecosystems.

Beginners receive explanations of the three loading strategies and their defaults. Experienced developers receive details about workspace protocols, filesystem events, symlink resolution, context limits and durable-run upgrades. RepoContext discovers asset locations; it does not make another assistant's skills, agent definitions or hooks executable by itself.

Capabilities

Instruction autoload is enabled by default. Each scanned directory contributes its first matching filename: AGENTS.md before CLAUDE.md unless configured otherwise. Ancestor scanning is optional, loads broader instructions before more specific ones, and deduplicates identical content.

Nested traversal is also enabled by default. It surfaces relevant instruction files when the agent accesses a directory or file. Asset inventory is disabled by default; enabling expose_inventory_tool exposes inventory_agent_context(), which locates skills, agent files and hook settings. Skill discovery searches at most eight directories deep.

Using it

Requirements

A run must have a workspace; otherwise RepoContext fails at startup. The examples use Agent from pydantic_ai, LocalWorkspace from pydantic_ai.capabilities, and RepoContext from pydantic_ai_harness. Minimum Python versions, exact package versions and installation commands are not established on this page.

By default, nested discovery uses filesystem events. A deprecated fallback supports hosts without events through non-default traversal_tool_names or traversal_path_arg settings, which emit HarnessDeprecationWarning. FileSystem emits them directly; hosts using other file tools can emit the documented event types. Authorizing external instruction symlinks requires a workspace backend with native realpath support or command execution. Without either, the default path handling cannot enforce symlink containment.

Mechanism

Autoload reads instruction files once at run start and places them in the agent's system instructions. By default it scans only the working directory. walk_up='repo_root' adds ancestors through the nearest root marker, while walk_up='all' can reach the filesystem root. Nested files instead arrive in the conversation tail as contents or a path pointer.

The default nested contents budget is 32,000 characters across notes still visible in the conversation, including earlier runs. Files exceeding the remaining budget become pointers. Notes are not repeated while still present; compaction can remove them and allow later traversal to surface them again.

Accepted-file pinning compares recorded SHA-256 digests with current files when pin_accepted_files is called. It lowers reported workspace authority for changed files, but only capabilities that consult that authority respond to the reduction. The page explicitly says RepoContext, Skills and SubAgents do not yet do so.

Setup

Add LocalWorkspace('./repo') and RepoContext(walk_up='repo_root') to an Agent's capabilities to use the documented repository-root scanning pattern. Set the working directory on the workspace; workspace_dir is deprecated and ignored. Relative configuration paths resolve from that working directory, and ~ is not expanded.

Choose filenames=('CLAUDE.md', 'AGENTS.md') to reverse filename preference, expose_inventory_tool=True to enable inventory, and nested_inject='pointer' to surface paths instead of file bodies. home_dir can bound ancestor scanning but cannot be combined with walk_up='repo_root'.

For shared instruction symlinks, autoload_symlink_roots authorizes external target directories for autoload only. It does not extend scanning, inventory or nested traversal. Authorize a narrowly scoped directory containing trusted instructions.

Example

Consider a hypothetical repository with .git and AGENTS.md at its root, plus packages/api/AGENTS.md. An agent configured with LocalWorkspace('./repo'), FileSystem() and RepoContext(walk_up='repo_root') would, according to the guide, load the root instructions at run start. Reading packages/api/app.py would then surface the nested instruction file before the next model request.

With default settings, the nested file's contents would be included if the conversation's character budget permits; otherwise the model would receive a pointer. This illustrates the documented behavior. Nothing was executed, and actual model compliance was not assessed.

Assessment & evidence

Limitations

RepoContext locates and loads context; it does not parse skill or sub-agent frontmatter, interpret hook bodies, or modify assets. It loads only one instruction file per directory, and autoload does not reload mid-run edits.

Walk-up files receive instruction authority, whereas nested files are delivered as workspace data with authorship and source information. Framing escapes and symlink restrictions constrain particular mechanisms, but the page does not establish comprehensive protection against malicious instructions.

The inventory tool is omitted on steps with a file-reading tool when all asset roots lie inside the working directory, even if file access rules prevent reading those roots. Nested traversal excludes node_modules, .venv, venv and site-packages by default; vendor and third_party require explicit exclusions if appropriate.

Reasoning

The documented benefit follows from when context is delivered: broad instructions arrive before work starts, while directory-specific instructions arrive as the assistant reaches relevant files. This supports using RepoContext to reduce missed repository guidance, but does not establish that every instruction will be followed.

The page reports a nine-model benchmark in which a nested rule was followed in 99% of runs with contents injection, 95% with pointers and 39% with nested traversal disabled. These are documentation claims about that task. The linked benchmark discussion is outside this page, so its detailed methodology and broader applicability were not assessed.

Alternatives

Within the documented configuration, pointer injection offers paths instead of automatically including nested file bodies. Disabling nested traversal removes that discovery behavior. For assets inside the working directory, FileSystem inspection is the documented alternative to the inventory tool.

These options change how much context is delivered automatically and how the assistant obtains it. The page does not compare competing libraries or frameworks, so relative setup effort, compatibility and performance are unknown.

Evidence

The findings are supported by the complete Repo Context documentation page, including its configuration reference, trust discussion and upgrade notes. It is primary documentation for the feature's intended behavior.

Linked implementation files, benchmark discussion, version policy and other documentation pages were not examined. No installation, code execution, backend compatibility check, security test or model-compliance test was performed.

Access & freshness

Costs

The page states no software price, subscription charge, model rate or measured operating cost. Monetary cost is unknown.

It does explain prompt-cache effects. Autoload keeps instructions stable within a run; changes between runs are appended, using a diff when shorter. Nested notes enter the conversation tail rather than changing the system prefix. Larger inlined context can increase model input, but the page provides no token totals or savings measurements.

Rights

The page links implementation source at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/repo_context/], but does not state a software licence, documentation licence or redistribution terms. Commercial-use and redistribution permissions are unknown from this page; the source link alone does not establish them.

Freshness

The documentation was captured on 25 November 2026 at 09:53:38 UTC. It does not identify an exact package release or implementation commit. It warns that Pydantic AI Harness APIs may change between minor releases while on 0.x.

Upgrade notes describe changed filename precedence, nested traversal defaults and dependency-directory exclusions. They also warn that changed workspace-call sequences can affect durable-run replay, recommending that older runs finish or deployments be versioned before upgrading. traversal_tool_names and traversal_path_arg are deprecated compatibility options.

Actions

Before adopting RepoContext, identify the trusted instruction files and choose the smallest appropriate ancestor boundary. Check filename precedence, decide between contents and pointers, and add exclusions for dependency directories your project does not control.

Confirm that the workspace backend resolves symlinks and that custom file tools emit the documented events when using the default integration. If accepted-file approval is a requirement, account for RepoContext's current lack of authority checking. For an existing deployment, review the upgrade notes and affected durable runs against the package version being installed.

Evidence for this report

selected-page.txtselected · checked 2026-11-25