OPEN-SOURCE CONTEXT ENGINEERING PROTOCOL · PERSISTENT AGENT MEMORYMIT LICENSE

ContextOS

Persistent project intelligence for AI coding agents.

ContextOS is an open-source context engineering system and Agent Skill that turns software repositories into durable memory for AI coding agents. Conversations are temporary; the repository is durable memory. By maintaining a structured, human-readable .context/ directory (INDEX, STATUS, CONSTRAINTS, PRD, ARCHITECTURE, PLAN, DECISIONS, HANDOFF), ContextOS preserves project truth across conversation restarts, context compaction, token limits, and model switches between Claude Code, Codex, and Cursor.

npx init · zero dependencies

# 1. Scaffold .context/ directory in your repo:

npx github:pokhrelboss/context-os init .

# 2. Install ContextOS agent skill:

npx skills add pokhrelboss/context-os
✓ Zero dependencies (Node.js ESM built-ins only)
✓ Zero network calls · Zero telemetry · Built-in secret scanner
✓ Model-independent: Claude Code, Codex, Cursor & AGENTS.md
01/ Core Philosophy

Conversations Are Temporary. The Repository Is Durable Memory.

When AI coding agents build software, their memory is tethered to ephemeral chat transcripts. When you hit a token limit, conversation quota, or context compaction event, the agent suffers from context amnesia—forgetting which features were completed, reversing architectural choices, and breaking past test assumptions.

ContextOS turns the repository itself into the single source of truth. By persisting requirements, status, ADR decisions, and handoff notes inside a portable .context/ directory committed to Git, your project intelligence survives context compaction, session resets, and cross-model handoffs between Claude Code and OpenAI Codex.

02/ System Architecture

The Three Architecture Layers

ContextOS decouples the persistent memory specification from agent behaviors and entrypoints:

┌─────────────────────────────────────────────────────────────────────────────┐
│                            YOUR REPOSITORY ROOT                            │
└──────────────────────────────────────┬──────────────────────────────────────┘
                                      ▼
LAYER 1: THE PROTOCOL (.context/) ← Durable memory files committed to Git
├── INDEX.md · STATUS.md · CONSTRAINTS.md · PRD.md · ARCHITECTURE.md · PLAN.md · DECISIONS.md · HANDOFF.md
                                      ▲
LAYER 2: THE AGENT SKILL ← Router & decision rules (skills/context-os/)
├── SKILL.md router dispatches to on-demand references (prompt-compiler, prd-engine, status, handoff)
                                      ▲
LAYER 3: THIN ADAPTERS ← Point each tool to .context/ without duplication
├── CLAUDE.md (Claude Code) · AGENTS.md (OpenAI Codex / Cursor / Gemini CLI / OpenCode)
1. The Protocol

Plain Markdown in .context/. Readable by any human, agent, or CI test. Versioned directly in Git.

2. The Skill

Teaches the agent when to compile prompts, update status, record decisions, or hand off without human babysitting.

3. Thin Adapters

CLAUDE.md and AGENTS.md remain lightweight entrypoints that point agents at .context/.

03/ Protocol Specification

The .context/ Protocol Directory

Each file serves a single high-signal role with clear lifecycle and context budgeting rules:

INDEX.md
L0 — Map

Tiny index map: explains what context files exist and when to read them so agents never load unnecessary context.

Budget Level:Always (tiny)
STATUS.md
L0 — Heartbeat

Objective, completed, in-progress, blocked, next exact action, honest validation results (unit/e2e/build), and git status.

Budget Level:Always loaded
CONSTRAINTS.md
L0 — Rules

Hard MUST and MUST NOT guardrails (e.g. backward compatibility, security rules, environment isolation).

Budget Level:Always loaded
PRD.md
L2 — Requirements

Structured product requirements with stable IDs (AUTH-001, API-004) and testable acceptance criteria.

Budget Level:On-demand
ARCHITECTURE.md
L2 — Structure

System component map, data flow pipelines, external dependencies, and runtime topology.

Budget Level:On-demand
PLAN.md
L1 / L2 — Roadmap

Phased implementation plan with strict exit criteria, validation gates, and requirement-traceability tables.

Budget Level:Task-scoped
DECISIONS.md
L2 — ADR Memory

Durable Architectural Decision Records with explicit 'Do Not' guardrails to prevent subsequent agents from reversing choices.

Budget Level:On-demand
HANDOFF.md
L0 — Cold Takeover

Everything a new agent or model needs to resume cold: Next Exact Action, Do Not Redo, and known problems.

Budget Level:On resume/switch
prompts/
Directory

Substantial original user prompts (verbatim) alongside engineering-grade compiled execution specifications.

Budget Level:Reference
archive/
L3 — Cold Storage

Superseded session notes, historical investigations, and large debug traces that should never clutter active context.

Budget Level:Rarely loaded
04/ Token Efficiency

4-Level Context Budgeting

More context is not better context. Dumping entire project histories into LLM context windows causes attention dilution and hallucinations. ContextOS enforces strict token tiering:

L0 — ALWAYS LOADED
Objective · STATUS · CONSTRAINTS

Under 250 total lines. The immediate heartbeat read on every turn.

L1 — TASK CONTEXT
Target Files · Tests · Active Plan Phase

Only the code, test suite, and plan phase required for the active unit.

L2 — ON-DEMAND REF
Relevant PRD · Schema · Architecture

Loaded only when making architectural choices or checking schema rules.

L3 — COLD STORAGE
archive/ · Old Sessions · Debug Logs

Never loaded into active context unless explicitly requested by the user.

05/ Prompt Engineering

The Prompt Compiler

Converts vague user requests into verifiable engineering execution specs before touching code:

OBJECTIVE
  Fix reported auth session drop, enhance dashboard state rhythms, reduce p95 latency.
CURRENT SYSTEM
  Next.js App Router + Supabase Auth; session JWT cookie; PostgreSQL. (from repo inspection)
REQUIREMENTS
  1. Auth: Reproduce failure, write failing regression test, fix refresh token cycle. Keep provider (D-002).
  2. Dashboard: Implement 4 application states (Loading, Empty, Populated, Error) on /dashboard.
  3. Performance: Measure main-thread blocking time; eliminate layout shifts on font load.
CONSTRAINTS
  Keep auth endpoints backward-compatible. Zero mock data in production. Tests before "done".
VALIDATION & DEFINITION OF DONE
  Unit: Vitest token refresh passes · E2E: Playwright login passes · Build: 0 errors · Verified 0 CLS.
06/ Model Portability

Cross-Model Continuity: Claude Code ↔ OpenAI Codex

Switching models mid-project is just save here, rehydrate there. Nothing depends on a model "remembering" anything:

Claude Code → Codex
  1. Claude Code checkpoints active task in STATUS.md.
  2. Writes HANDOFF.md with Next Exact Action and Do Not Redo.
  3. Commits memory changes to Git: git commit.
  4. OpenAI Codex opens the project, reads AGENTS.md natively, inspects STATUS.md, verifies tests, and continues without missing a beat.
Codex → Claude Code
  1. Codex updates STATUS.md and HANDOFF.md upon completing tasks.
  2. Records architectural choices in DECISIONS.md.
  3. Commits progress to Git repository.
  4. Claude Code starts session, runs SessionStart hook to read CLAUDE.md.context/INDEX.md, and resumes with full context.
07/ Deterministic Verification

Deterministic Context Health Auditing

Run contextos health . anytime to get an unweighted, deterministic audit of your project memory. It flags memory decay before it harms agent performance:

Freshness100/100

Measures how recently STATUS.md was updated relative to active git commits.

Consistency100/100

Detects contradictory states, missing Next Actions, or stale blocker tags.

Completeness100/100

Verifies all required protocol files exist and contain non-placeholder content.

Token Efficiency100/100

Guarantees always-loaded L0 files remain compact (< 250 lines) to avoid context bloat.

Handoff Readiness100/100

Ensures HANDOFF.md contains clear Next Action and Do Not Redo instructions.

08/ Ecosystem Verification

Verified Compatibility Matrix

Coding Tool / AgentIntegration MechanismSupport TierNotes
Claude CodeAgent Skill (skills/context-os/) + CLAUDE.md + HooksFull (Native)Native router skill, SessionStart / PreCompact / PostCompact lifecycle hooks.
OpenAI CodexAGENTS.md adapter (native open standard)Full (Native)Reads AGENTS.md at repo root pointing directly to .context/INDEX.md.
CursorAGENTS.md / .cursor/rules integrationSupportedNative AGENTS.md support or project rules importing .context/.
Gemini CLI / OpenCodeAGENTS.md / GEMINI.md adapterSupportedFollows open AGENTS.md convention.
GitHub Copilot / Zed / WarpAGENTS.md root instructionsSupportedStandard workspace agent instructions file.
Google AntigravityGeneric AGENTS.md adapterBest-effortCompatible with project prompt configuration.
Any Other AI ToolManual pointer to .context/INDEX.mdManualAll protocol files are human-readable standard Markdown.

Security, Privacy & Zero Telemetry

ContextOS is built on strict engineering restraint:

🔒 Plain Local Files

All memory lives as human-readable Markdown inside your repository. No proprietary database binaries or lock-in.

🚫 Zero Network & Telemetry

The CLI makes zero network calls and collects zero analytics or crash reporting.

🛡️ Built-in Secret Scanning

contextos validate scans memory files for high-confidence API keys, JWTs, and passwords before commits.

Engineering Logs on ContextOS