mikeaorlando.com Michael Orlando
  • Home
  • Start Here
  • About
  • Work & Ventures
  • Ideas & Writing
  • Collaborate
  • Search

◉Managing AI Agent Context Files

Managing AI Agent Context Files

How I keep the instruction files that AI coding agents read short, current, and split by purpose, so each session starts with the rules it needs instead of a history it has to wade through.

Routing Notes

  • Parent Projects for Fun
  • Signal Working Systems

Overview

AI coding agents start every session by reading instruction files: a root file in the repository, a user-level file with personal preferences, and whatever those files point to. Those files are the agent’s working knowledge of the project. If they are long, stale, or contradictory, every session pays for it. This page describes how I manage them: a short root file, reference files loaded only when a task needs them, a freshness contract on each file, and periodic review of the files as a set.

Context

The repository for my homelab infrastructure had a root instructions file that grew with every change. Each new Ansible role and playbook added a row to a reference table, and each change to a role added a note to that row. The file was loaded in full into every session and every subagent, so the growth cost a large share of each session’s context before any work started.

Size was the visible problem. The less visible ones were worse. The tables mixed current facts with history, in the form “this ticket added that.” Hand-maintained rows had drifted from what was on disk: some playbooks and roles had no row, and some statements contradicted each other. The rules that change the agent’s behavior, such as how to handle cloud writes and secrets, came after the long tables, which is the opposite of the order in which they matter.

The System

A short root file. The root file now holds only what every session needs: an overview, the hard rules, the main checklists, the git workflow, quick references for the MCP servers, and a list of further reading. Everything specific to one part of the repository moved out of it.

Reference files loaded on demand. Detail moved to the file closest to what it describes. Each Ansible role has its own README. The Ansible directory has its own instructions file with a one-line index of every playbook and role, and the line “before editing a role, read its README.” The agent reads a role’s README when it is about to change that role, and not otherwise. A pre-commit check fails when a playbook or role has no index row, so the index cannot drift silently the way the old tables did.

This website’s repository follows the same shape at a smaller size: a root file that points to separate reference files for the voice guide and for where related work lives in Jira, Confluence, Slack, and Google Drive.

A freshness contract. Each guidance file says what it covers, what it is distilled from, and when it has to be updated. Facts that change without a code change, such as versions, IDs, and live status, are not written into the files. The file points to the tool call that returns the current value instead.

Current state in files, history in version control. Guidance files and code comments describe what is true now. The reasons for a change, its order, and what it replaced go in the commit message, the pull request, and the ticket. My user-level instructions apply the same rule to code comments: a comment describes only the code next to it and can be checked from that file alone.

Durable memory as an index of small files. The agent’s memory across sessions follows the same structure. One short index file lists one line per memory, and each line points to a small file that holds one fact or rule. The index is loaded every session; the detail is read when it applies.

Review as a set. Splitting the root file was a mechanical move; the text was not judged. A separate review followed. It walked typical tasks from the root file to the files they need and checked whether the path worked, looked for duplication and contradictions across files, and reviewed the largest files. I reviewed the list of findings before any edit was made. The edits then fixed wrong pointers and wrong facts, reduced the largest files, and rewrote the largest role READMEs from a changelog into current-state text on one outline.

The trade-off is that guidance is now spread over many files. That only works if the pointers are correct, which is why the index check and the set review exist.

Components and Why I Chose Them

If terms such as context file, subagent or memory are new to you, How my AI stack fits together explains how the pieces connect.

The components here are files and practices, not products.

Piece What it holds Why it is separate
Root instructions file (CLAUDE.md for Claude Code) Overview, hard rules, main checklists, git workflow, MCP quick references, further reading Every session and every subagent loads it in full, so it holds only what every session needs, with the rules that change behavior near the top
Directory instructions file A one-line index of every playbook and role in the Ansible directory It gives the agent a map of that directory without the detail, and a pre-commit check keeps it in step with what is on disk
Per-role READMEs Current-state design notes for one Ansible role They are needed only when that role is about to change, so the agent reads one when it needs it
Reference files (for example a voice guide, or a registry of where related work lives) Rules or identifiers distilled from a source of truth kept elsewhere Only some tasks need them, and each one names its source and when it must be updated
User-level instructions file Personal preferences that apply in every repository They apply across all projects, so they are written once instead of copied into each repository
Memory index and memory files One line per memory in the index; one fact or rule per file The index is loaded every session; a memory’s detail is read only when it applies
Commit messages, pull requests and tickets Why a change was made, its order and what it replaced History already has a home in version control and the ticket system, so guidance files can state only what is true now

Outcomes

Sessions start with the rules that change behavior near the top, and they read role-level detail only when they work on that role. Statements about what exists on disk are checked by the pre-commit hook instead of by memory. The review turned up guidance that was missing, pointers that were broken, and facts that were wrong, and fixed them in one pass instead of leaving them to be found during unrelated work.

Example Configuration

This is a simplified, generic layout. The names are placeholders, not the contents of a real repository.

repo/
├── CLAUDE.md                     # short: overview, hard rules, checklists, pointers
├── docs/
│   └── ai-context/               # reference files, each with a freshness contract
│       ├── README.md
│       └── change-guidelines.md
└── ansible/
    ├── CLAUDE.md                 # one-line index of every playbook and role
    └── roles/
        └── example_role/
            └── README.md         # current-state notes for this role only

A freshness contract is a short header at the top of each reference file:

Covers: how changes to the example service are made.
Distilled from: the example service page in Confluence.
Update when: the deploy process or the service's owner changes.
Live values (versions, IDs, status): ask the example MCP server; do not copy them here.

A memory index holds one line per memory, each pointing to a small file:

- [Deploy path](deploy-path.md) — staging deploys on push; production only through an approved pull request

Patterns Worth Reusing

Treat the root context file as a budget. Everything in it is read by every session. Put only what every session needs there, and point to the rest.

Point to live sources instead of copying them. Any fact that changes without a commit will go stale in a guidance file. Name the command or tool that returns it.

Keep history out of guidance. Version control and the ticket system already hold history. Guidance files should read as current truth.

Review the files as a set after a restructure. Moving text keeps its errors. A review that follows real tasks through the files finds the gaps a file-by-file reading misses.

Explore

  • ✎Posts
  • ○Categories
  • ◉Projects for Fun
  • ▶Projects for Work
  • ◎Systems Across Domains
  • ▪Technical Tools
  • ◆Transferable Skills
  • ✕Value Multipliers
  • ◇Ventures

Michael Orlando

Systems, ventures, writing, and public proof arranged so the right people can find the right next step.

© 2026 Michael Orlando

Privacy & Data Handling

about.me Substack Credly Polywork