---
type: workflow-spec
status: draft
created: 2026-07-18
updated: 2026-07-18
source:
  - user-edited-ai
canonical: false
source_of_truth_for: agent-instruction-hierarchy

doc_version: "0.1"
changelog: agent_instruction_hierarchy_changelog.md
---

# Agent Instruction Hierarchy

## Purpose

This document defines how Codex loads and prioritises `AGENTS.md` instructions across the AIOS Vault.

The hierarchy allows shared instructions to be maintained once while individual projects retain their own local rules.

## Instruction Levels

For a task opened inside an AIOS project, Codex can apply instructions from several levels:

| Order | Level | Example location | Intended content |
|---|---|---|---|
| 1 | Global | `~/.codex/AGENTS.md` | Personal preferences that apply wherever Codex is used |
| 2 | Vault | `AIOS-Vault/AGENTS.md` | Rules that apply throughout the AIOS Vault |
| 3 | Area | `AIOS-Vault/40_Clients/AGENTS.md` | Rules shared by a group of projects |
| 4 | Project | `AIOS-Vault/40_Clients/[client]/[project]/AGENTS.md` | Project-specific paths, tools, workflows, and exceptions |

Additional intermediate instruction files can be added when a folder genuinely needs shared rules.

## Loading and Priority

Codex loads applicable instruction files from the broadest level down to the active working directory.

- Parent instructions remain active when a lower-level file does not conflict with them.
- A more specific instruction closer to the working directory takes priority when instructions conflict.
- Project files should add local context or explicit exceptions rather than repeat shared rules.
- Instructions are normally discovered when a task starts. Start a new task after changing the hierarchy to ensure the updated files are loaded.

Codex checks for `AGENTS.override.md` before `AGENTS.md` within the same directory and loads at most one instruction file from that directory. An override at one level does not remove applicable parent-level instructions.

The override file is useful for a temporary or specialised replacement without deleting the normal `AGENTS.md`. The risk is forgetting it exists and wondering why changes to the normal file are being ignored.

## Effect of the Vault Git Repository

Installing Git did not create the hierarchy. Initialising the entire AIOS Vault as one Git repository made the Vault the detected repository root.

When a task is opened inside a nested project, Codex can now discover instruction files from the Vault repository root down to that project's working directory.

This makes Vault-wide and area-wide instruction layers practical without copying the same rules into every project.

## Sandbox Boundary

Instruction discovery and filesystem permissions are separate.

Loading an instruction file from a parent folder does not grant Codex permission to edit that folder or other files within the Vault. Read and write access continue to be controlled by the Codex task's sandbox and approval settings.

## AIOS Instruction Design

Use the narrowest instruction level that covers the intended scope:

- Put personal working preferences in the global Codex instructions.
- Put universal AIOS conventions in the Vault-level instructions.
- Put shared client-project conventions at the `40_Clients` level when needed.
- Keep project-level instructions focused on that project's local requirements.

Do not duplicate a shared rule across every project. Duplication creates drift and makes it unclear which copy is authoritative. It also uses unncessary tokens and space within the context window.

A future instruction-management skill should determine the correct level for a new rule, update the authoritative file, identify redundant lower-level copies, and preserve genuine project-specific differences. It should not blindly synchronise complete `AGENTS.md` files across projects.

## Verification

The hierarchy was verified in the Codex desktop app by placing a unique test instruction in the vaults root folder, `AIOS-Vault/AGENTS.md` and starting a new task inside the more deeply nest `AIOS_Prototype` project folder.

The new task followed both the Vault-level test instruction and the project-level instructions. This confirmed that the parent file remained active and the project file was layered after it.  Two tests were run inside of fresh tasks.  The first test revealed an answer to an instruction that existed only within the Vault-level instructions. The second test had an amendment to the project-level instructions, which contradicted the vault-level instructions. In the second test, the project-level instructions were prioritised as expected, confirming the hierarchy of AGENTS.md instructions.

Codex initially reported only the project-level file when asked to list its loaded instruction sources. It later identified both repository files after the contradiction was pointed out. Therefore, self-reported source lists may be incomplete. Behavioural tests using unique, harmless markers provide stronger verification of whether an instruction level was loaded.

## Reference

- [OpenAI: Custom instructions with AGENTS.md](https://learn.chatgpt.com/docs/agent-configuration/agents-md)
