Context Architecture (Technical Reference)
How the agent system loads, layers, and refreshes context to give Claude the right information at the right time.
Why Context Matters
Claude Code agents are only as effective as the context they receive. Without structured context loading, agents:
- Lack awareness of user preferences, values, and constraints
- Cannot route tasks to the right tools or workflows
- Miss domain-specific knowledge needed for quality output
- Repeat questions that should already have answers
The context architecture solves this with layered, on-demand context loading — from broad system rules down to domain-specific knowledge.
Context Layers at a Glance
┌─────────────────────────────────────────────┐
│ Layer 1: Global CLAUDE.md │
│ (agent behavior, safety, git rules) │
└──────────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Layer 2: Project CLAUDE.md │
│ (repo-specific rules) │
└──────────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Layer 3: InnerOS Self_Context │
│ (identity, values, health, domains) │
└──────────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Layer 4: Operating System │
│ (AGENT_GUIDE, conventions, LLM instr.) │
└──────────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Layer 5: Goals & Workflows │
│ (structured goals, workflow definitions) │
└──────────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Layer 6: Coaching Layer │
│ (playbook, session logs) │
└─────────────────────────────────────────────┘| Layer | Scope | Loaded When |
|---|---|---|
| Global CLAUDE.md | All projects, all sessions | Always (automatic) |
| Project CLAUDE.md | Per-repo rules | When working in that repo |
| InnerOS Self_Context | Identity, values, preferences | On /contxt command |
| Operating System | Routing, conventions | On /contxt command |
| Goals & Workflows | Domain-specific plans | On /contxt [domain] |
| Coaching | Growth, reflection | On /contxt coaching |
Layer Details
Layer 1: Global CLAUDE.md
Scope: All projects, all sessions
Location: ~/.claude/CLAUDE.md
Loads: Automatically on every Claude Code session
This is the foundation. It defines:
- Agent behavior rules — iteration bounds, completion promises, validation requirements
- Safety guardrails — what agents can and cannot do autonomously
- Git sync rules — when to commit, when to push, branch conventions
- Task management protocol — how to use todo.md, how to mark tasks complete
- Human handoff protocol — what to include when handing off to a human
- Skills vs agents decision framework — when to use deterministic scripts vs LLM reasoning
Every agent in every project inherits these rules. This is where you put universal constraints.
Layer 2: Project CLAUDE.md
Scope: Single repository
Location: <repo-root>/CLAUDE.md
Loads: Automatically when working in that repo
Project-specific rules that override or extend global behavior:
- What this repo is and how it’s structured
- Repo-specific conventions (naming, testing, deployment)
- Files to read first, directories to ignore
- Build and validation commands for this project
Example: A documentation repo’s CLAUDE.md might say “never auto-commit” and “always run npm run build before marking done,” while a Python project’s might specify “run pytest and mypy.”
Layer 3: InnerOS Self_Context
Scope: Personal identity and preferences
Location: Obs_Vault/0_InnerContext/Self_Context/
Loads: On /contxt command
┌────────────────────────────┐
│ master_context.md │
│ (hub file ~67KB) │
└─────────────┬──────────────┘
│
┌──────────┬──────────┼──────────┬──────────┐
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌──────────┐┌──────────┐┌──────────┐┌──────────┐┌──────────────┐
│identity ││values ││health ││domains ││communication │
│.md ││.md ││.md ││.md ││.md │
└──────────┘└──────────┘└──────────┘└──────────┘└──────────────┘
┌──────────┬──────────┬──────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌──────────┐┌──────────┐┌──────────┐┌──────────────┐
│relation- ││constr- ││prefer- ││... (15 files │
│ships.md ││aints.md ││ences.md ││ total) │
│ ││(e.g.ADHD)││ ││ │
└──────────┘└──────────┘└──────────┘└──────────────┘This is the “who you are” layer:
| File | Contains |
|---|---|
master_context.md | Hub file linking all others, auto-refreshed nightly |
identity.md | Core identity, roles, how you see yourself |
values.md | What matters, decision-making principles |
health.md | Health context relevant to scheduling and energy |
domains.md | Life domains (work, creative, financial, etc.) |
communication.md | How you prefer to be communicated with |
constraints.md | Constraints like ADHD that affect workflow design |
Agents use this to tailor their output — a coach agent reads health.md, a planner reads constraints.md, a writer reads communication.md.
Layer 4: Operating System
Scope: Agent routing and conventions
Location: Obs_Vault/0_InnerContext/
Loads: On /contxt command (Step 1: essentials)
| File | Purpose |
|---|---|
AGENT_GUIDE.md | Master routing index — tells agents where to find every file, workflow, and convention |
CONVENTIONS.md | Naming, structure, formatting rules |
llm_instructions.md | Base instructions injected into every LLM interaction |
AGENT_GUIDE.md is the most critical file in the system. It’s the “table of contents” that lets any agent navigate the vault and find what it needs.
Layer 5: Goals & Workflows
Scope: Domain-specific plans and processes
Location: Obs_Vault/1_Projects/ and Obs_Vault/2_Areas/
Loads: On /contxt [domain] command
Each life domain has:
- Goals file — structured goals with status, metrics, and next actions
- Workflows file —
_workflows.mddefining repeatable processes - Active projects — current work in progress
Domains follow the PARA structure:
| PARA Level | Contains |
|---|---|
1_Projects/ | Active projects with clear outcomes |
2_Areas/ | Ongoing responsibilities (health, finance, career) |
3_Resources/ | Reference material, blueprints, guides |
4_Archive/ | Completed or paused items |
Layer 6: Coaching
Scope: Personal growth and reflection
Location: Obs_Vault/2_Areas/Coaching/
Loads: On /contxt coaching or coaching-related commands
- Coaching playbook — frameworks, exercises, prompts
- Session logs — past coaching session notes and insights
- Growth tracking — patterns identified over time
Layer Interaction
┌─ Always Loaded ───────────────┐ ┌─ On-Demand ─────────────────────┐
│ │ │ │
│ Global CLAUDE.md │ │ Self_Context │
│ │ │ │ │ │
│ ▼ │ │ ▼ │
│ Project CLAUDE.md │──▶ │ Operating System │
│ │ │ │ │
└───────────────────────────────┘ │ ┌────┴─────┐ │
│ ▼ ▼ │
│ Goals & Coaching │
│ Workflows │
└─────────────────────────────────┘Key principle: Lower layers constrain upper layers. If Global CLAUDE.md says “never force-push to main,” no amount of domain context can override that. This creates a safe, predictable system where adding context adds capability without removing guardrails.
Loading & Routing
How the /contxt command fetches the right context for any session.
The Loading Mechanism
Context loading follows a 2-step bundle pattern: first load the essentials that every session needs, then load domain-specific context based on what you’re working on.
User ──▶ /contxt [domain] ──▶ Step 1: Essentials ──▶ Step 2: Domain Bundle ──▶ Agent
│ │
Load llm_instructions.md │
Load AGENT_GUIDE.md (if domain specified)
│ Route to domain bundle
Essentials ready Domain context loaded
│ │
└───────────────────────┘
│
Full context injected
│
▼
Agent ──▶ Ready with contextStep 1: Load Essentials
Every /contxt invocation loads two critical files:
| File | Size | Purpose |
|---|---|---|
llm_instructions.md | ~5KB | Base behavior rules for all LLM interactions |
AGENT_GUIDE.md | ~15KB | Master routing index — where everything lives |
These files give the agent enough orientation to navigate the vault and understand system conventions, regardless of what domain you’re working in.
Step 2: Domain-Specific Bundle
When you specify a domain, the command loads additional context:
| Command | Bundle Loaded |
|---|---|
/contxt | Essentials only (Step 1) |
/contxt coding | + coding workflows, active projects, tech stack prefs |
/contxt music | + music projects, production notes, release pipeline |
/contxt crypto | + portfolio, DeFi positions, investment thesis |
/contxt health | + health context, fitness goals, energy patterns |
/contxt coaching | + coaching playbook, session history, growth patterns |
Each bundle is a curated set of files from the vault that gives the agent domain expertise.
The Routing Index: AGENT_GUIDE.md
AGENT_GUIDE.md is the single most important file in the context system. It acts as a table of contents for the entire vault, telling agents:
- Where to find files for each domain
- Which workflows apply to which tasks
- What conventions to follow
- Where to store outputs
┌──────────────────────────────┐
│ AGENT_GUIDE.md │
│ (master routing index) │
└──────────────┬───────────────┘
│
┌──────────┬──────────┼──────────┬──────────┬──────────┐
│ │ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼
┌──────────┐┌──────────┐┌──────────┐┌──────────┐┌──────────┐┌──────────┐
│ Coding ││ Music ││ Finance ││ Health ││ Admin ││ Content │
│ projects ││ sessions ││ portfolio││ metrics ││ house ││ writing │
│ stack ││ releases ││ DeFi ││ goals ││ suppliers││ publish │
│ convent. ││ gear ││ tax ││ constr. ││ calendar ││ social │
└──────────┘└──────────┘└──────────┘└──────────┘└──────────┘└──────────┘Without this file, agents would need to search the vault blindly. With it, they can jump directly to the relevant files.
Building Your Own Routing
To set up context loading for your system:
1. Create your AGENT_GUIDE.md
List every important file and directory, organized by domain:
# Agent Guide
## Coding
- Projects: `1_Projects/Coding/`
- Stack preferences: `2_Areas/Coding/stack.md`
- Conventions: `_System/Conventions/coding.md`
## Finance
- Portfolio: `2_Areas/Finance/portfolio.md`
- Tax docs: `2_Areas/Finance/tax/`2. Create your /contxt command
A slash command that reads the routing index and loads the right files:
# Context Loader
Load system context for the current session.
## Usage
/contxt [domain]
## Steps
1. Read `llm_instructions.md` for base instructions
2. Read `AGENT_GUIDE.md` for routing
3. If domain specified, load domain-specific files listed in AGENT_GUIDE
4. Confirm what was loaded3. Define domain bundles
For each domain, decide which files the agent needs. Keep bundles focused — loading too much context wastes tokens and dilutes attention.
Good bundle: 3-5 focused files totaling under 30KB Bad bundle: 20 files totaling 200KB (agent will lose focus)
Context Budget
Every token of context loaded is a token not available for reasoning. Be strategic:
| Context Size | Guideline |
|---|---|
| < 10KB | Always fine to load |
| 10-30KB | Good for focused domain work |
| 30-50KB | Maximum for a single session |
| > 50KB | Split across multiple interactions |
The /contxt command should respect these budgets, loading only what’s needed for the current task rather than everything available.
Refresh Cycle
Context goes stale. Here’s how the system keeps it fresh automatically and manually.
Why Refresh Matters
Context files represent your current state — goals, priorities, active projects, health, preferences. When these files drift from reality, agents make decisions based on outdated information.
Two mechanisms keep context fresh:
- Automated refresh via NightCrew (daily, runs at 3 AM)
- Manual refresh when you make significant changes
NightCrew: Automated Refresh
NightCrew is a LaunchAgent-triggered pipeline that runs every night. It collects data from across your system and updates context files.
┌─ 3:00 AM - NightCrew Pipeline ──────────────────────────────────────────┐
│ │
│ Stage 1-3 Stage 4-6 Stage 7-9 │
│ File triage & ──▶ Messages, voice ──▶ Photos, activity │
│ session extraction memos, calendar summary, morning brief │
│ │ │
│ ▼ │
│ Stage 13-15 Stage 10-12 │
│ Context file ── Conversation analysis │
│ updates & pattern detection │
│ │ │
│ ▼ │
│ Stage 16 │
│ Git push to sync │
│ │ │
└───────┼─────────────────────────────────────────────────────────────────┘
│
▼
┌──────────────────────────────┐
│ master_context.md │
│ Updated with fresh data │
└──────────────────────────────┘What Gets Refreshed
| Stage | Source | Updates |
|---|---|---|
| 1-3 | Downloads, Claude sessions | File organization, session context extraction |
| 4-6 | WhatsApp, iMessage, Calendar | Message digests, upcoming events |
| 7-9 | Photos, Health, Activity | Photo triage, health metrics, activity summary |
| 10-12 | Conversation patterns | Communication insights, topic tracking |
| 13-15 | All of the above | master_context.md regenerated from fresh data |
| 16 | Git | Push updated vault to remote |
The Key Output: master_context.md
The most important output of NightCrew is the updated master_context.md. This file is the hub that links to all other Self_Context files. When agents load context via /contxt, this file tells them what’s current.
NightCrew rewrites master_context.md by:
- Scanning conversation patterns from recent Claude sessions
- Analyzing photo library changes (vision-based classification)
- Pulling reading highlights and notes
- Aggregating health and activity data
- Synthesizing all of the above into updated priorities and status
Manual Refresh
Some changes can’t wait for the nightly pipeline. Update context files manually when:
| Trigger | What to Update |
|---|---|
| New project started | 1_Projects/ + AGENT_GUIDE.md |
| Goal changed | Domain goals file + master_context.md |
| New tool/integration added | AGENT_GUIDE.md + relevant workflows |
| Preferences changed | Relevant Self_Context file |
| Major life event | master_context.md + affected domain files |
Manual Refresh Workflow
┌─── Yes ──▶ Let NightCrew handle it
│
Change happens ──▶ Can it wait? ───┤
for NightCrew │
└─── No ───▶ Update file ──▶ Update ──▶ Git commit
directly AGENT_GUIDE & push
(if routing
changed)Setting Up Your Own Refresh
Minimal Setup (No Automation)
Just update files manually. This works if you have a small vault and few context files.
Recommended Setup (Hybrid)
- Create a nightly script that collects data from your key sources
- Set up a LaunchAgent to run it at a fixed time
- Include a
master_context.mdregeneration step — even a simple concatenation of key files helps - Git push at the end to sync changes
Advanced Setup (Full NightCrew)
Build a multi-stage pipeline:
- Data collection scripts for each source (Python recommended)
- Aggregation step that merges data into summaries
- Context generation step that updates vault files
- Analysis step (optional) that uses Claude to find patterns
- Sync step that commits and pushes
The staged approach means each step can fail independently without breaking the whole pipeline.
Freshness Indicators
How to tell if your context is stale:
| Signal | Meaning |
|---|---|
master_context.md last modified > 7 days ago | NightCrew may not be running |
| Agent asks questions you’ve already answered | Context not loading properly |
| Agent references old projects/goals | Files haven’t been updated |
/contxt loads successfully but output is generic | Bundle may be loading wrong files |
Tip: Add a last_updated: field to your key context files. NightCrew can write this automatically, and you can grep for stale files with a simple script.