alberto marturelo

Context-First Development · CFD

Your AI agent has amnesia at the start of every session. CFD is the cure.

A methodology for engineers working with AI coding agents (Claude Code, Codex, GitHub Copilot, Gemini CLI, Cursor) on real repositories. It treats context as a first-class artifact: structured, versioned, and reviewed like code.

View on GitHub →
or adopt CFD in 60 seconds ↓

The problem

Models restart every session with no memory of your architectural decisions. The result: you correct more AI-generated code than you would save writing it by hand, because the agent lacks the “why” that code alone can’t express.

The problem isn’t context capacity. It’s context quality.
Session N· decisions made· patterns corrected· work in progresschat history is gone/session-closewritesthe repoversioned · reviewedCLAUDE.mdthe indexCURRENT_STATUS.mdwhere we stoppeddecisions/the whyCONVENTIONS.mdhow we code/session-startreads ~1–3k tokensSession N+1· loads the index· knows where N stoppedsame rules,same whyready in one command
Session N· decisions made· patterns corrected· work in progresschat history is gone/session-closewritesthe repoversioned · reviewedCLAUDE.mdthe indexCURRENT_STATUS.mdwhere we stoppeddecisions/the whyCONVENTIONS.mdhow we code/session-startreads ~1–3k tokensSession N+1· loads the index· knows where N stoppedsame rules,same whyready in one command
The session forgets. The repo remembers.

The real payoff

Adherence, not tokens.

Almost everyone sells token savings. CFD targets something harder to argue with: code that respects your conventions on the first try, decisions that don’t get re-litigated, corrections that never repeat. Token savings are a welcome side effect, not the headline.

Six principles

01

Context Before Code

Resolve context at session start, not while you work.

02

Single Source of Truth

Every fact lives in exactly one file; everything else references it.

03

Hierarchical Context

CLAUDE.md is an index (~100 lines), not an encyclopedia.

04

Decisions as First-Class Citizens

Every significant decision becomes an ADR with alternatives and rationale, before the code.

05

English as Context Language

Tokenizers compress English ~20–40% better. It applies to the context the AI eats, not to what you publish.

06

Automation Through Agent Skills

Maintaining context is a procedure any agent runs, not a chore to remember.

A real issue

The issue body is the spec.

Every unit of work lives in the tracker with five fixed sections. The session starts by reading that, not by reconstructing it from code. This is #116 of sii, a CLI and MCP server for Chile’s tax authority, born with CFD on day 0 and now at 26 ADRs.

sii #116 · auth login --www2## Contextwww2 needs an OAuth session the classic login never mints## Targettasks/auth.ts · auth/www2-login.ts (new)## ADRs to loadADR-026 · ADR-006 · ADR-004## Acceptance criteria7 items: behaviour, tests, docs## Estimated sessions1 — more than that, split it firstdecisionsADR-026the www2 sessionADR-006cookies only, never the passwordtarget filesauth/www2-login.tstasks/auth.tsPR checklistthe criteria, verbatim/issue-start 116 loads exactly this
sii #116 · auth login --www2## Contextwww2 needs an OAuth session theclassic login never mints## Targettasks/auth.ts · auth/www2-login.ts(new)## ADRs to loadADR-026 · ADR-006 · ADR-004## Acceptance criteria7 items: behaviour, tests, docs## Estimated sessions1 — more than that, split it first/issue-start 116 loads exactly thisdecisionsADR-026the www2 sessionADR-006cookies only, never the passwordtarget filesauth/www2-login.tstasks/auth.tsPR checklistthe criteria, verbatim
A real issue (sii #116). Everything the session needs is in the body, not in the chat.

Not docs, mechanism

The discipline enforces itself.

What separates CFD from “just write good docs” is that context is enforced by mechanism, not goodwill:

SessionStart hook

Injects context automatically on start and warns when it’s stale.

Commit guard

Blocks commits that stage code without updating CURRENT_STATUS.md.

CI

Fails the PR when two ADRs share a slug and warns when code changes without touching status. It reaches any agent, including one you never configured.

Measured, not claimed

Reproducible numbers.

~824

tokens to orient a session with CFD

~10,519

tokens scanning the whole repo without CFD

12.8×

less context to get started

≤1 day

freshness of CURRENT_STATUS.md

Measured with scripts/measure-session-cost.sh over the node-express example the repo shipped until July 2026. Run the same script on your own repo.

Automation

The procedures are Agent Skills.

One copy in .agents/skills/, the open format Claude Code, Codex, GitHub Copilot and Gemini CLI all read. The session rituals run only when you invoke them, never on the model’s judgement.

  • /project-initBootstraps the CFD scaffold in an existing repo.
  • /session-startLoads CLAUDE.md + CURRENT_STATUS.md + decisions index.
  • /issue-newCreates an issue with a fixed template and ADRs to preload.
  • /issue-startStarts work with the decision context already loaded.
  • /review-prReviews the diff against the AC, the conventions and the ADRs. Before closing.
  • /session-closeEnsures CURRENT_STATUS.md ships alongside your code.

In Codex they are invoked as $session-start. Install them into every agent with npx skills add albertomarturelo/context-first-development.

CFD in your setup

The files and the loop are the same. What changes is where state lives and who decides.

Find your case. They stack: a team running Codex and Claude in worktrees reads all four.

Case 1

One developer, one repo

1/session-startreads STATUS +decisions index2/issue-start Nloads the AC+ its ADRs3implementone AC itemat a time4/review-prself-review;fix now5/session-closeSTATUS + docsship with code6mergeclosesthe issuethe habit that makes it workYou correct a pattern→ rule in CONVENTIONS.mdA decision surfaces→ /new-decision, ADR firstnext session starts where this one stopped
1/session-startreads STATUS + decisions index2/issue-start Nloads the AC + its ADRs3implementone AC item at a time4/review-prself-review; fix now5/session-closeSTATUS + docs ship with code6mergecloses the issuethe habit that makes it workYou correct a pattern→ rule in CONVENTIONS.mdA decision surfaces→ /new-decision, ADR firstnext session starts where this one stopped
One loop. One issue per session. Review before close.
  • →One issue per session. /issue-new forces decomposition until an issue fits one.
  • →What you correct goes to CONVENTIONS.md; what you decide becomes an ADR before the code. The agent never hears the same correction twice.
  • →Review your own diff before you close, while the context is still loaded. Reviewing after the close means paying a new session to rebuild it.

ADR short-sessions-over-long

Case 2

A team on one repo

ON EACH LAPTOPSHAREDDev A + agentCURRENT_STATUS.mdgitignored: personal memoryDev B + agentCURRENT_STATUS.mdgitignored: personal memoryclaim issuesopen PRscode + docsTrackerissues with AC · assigneeswho does what, right nowCI on every PR· ADR slugs unique (blocks)· + the checks you addmergemainCLAUDE.mdindexdecisions/ADRsCONVENTIONS.mdrules.agents/skills/ritualschanges only througha reviewed PR
ON EACH LAPTOPDev A + agentCURRENT_STATUS.mdgitignored: personalmemoryDev B + agentCURRENT_STATUS.mdgitignored: personalmemoryclaim issuesopen PRscode + docsSHAREDTrackerissues with AC ·assigneeswho does what, rightnowCI on every PR· ADR slugs unique(blocks)· + the checks you addmergemainCLAUDE.mdindexdecisions/ADRsCONVENTIONS.mdrules.agents/skills/ritualschanges only through a reviewed PR
Personal state stays local. Shared truth goes through review.
  • →Status goes personal: CURRENT_STATUS.md leaves git. Shared, it conflicts on every PR and injects everyone’s work-in-progress into your session.
  • →The tracker is the shared picture: assignees and issue state answer “who is doing what”.
  • →When a teammate reviews, the order flips: you close, and their findings open your next session.

ADR current-status-per-developer

Case 3

Parallel loops in git worktrees

mainADRs for the batchdecided firstwt-1 · Claude Code · #41 · src/auth/rebasemerge #411stwt-2 · Codex · #42 · src/billing/!merge #422ndwt-3 · Copilot · #43 · docs/api/rebasemerge #433rdmid-loop ADRlands as its own PRnew ADR needed: stop, land it firstYou orchestrate: disjoint paths · every merge reviewed against main · as many loops as you can review
wt-1 · Claude Code · #41 · src/auth/wt-2 · Codex · #42 · src/billing/wt-3 · Copilot · #43 · docs/api/mainADRs for the batchdecided firstwt-1rebasemerge #411stwt-2!merge #422ndwt-3rebasemerge #433rdmid-loop ADRlands as its own PRnew ADR needed: stop,land it firstYou orchestrate: disjoint paths · every mergereviewed against main · as many loops as youcan review
A worktree isolates files, not decisions. Decide on main first; merge one at a time.
  • →A worktree isolates files, not decisions. Everything on main when you branch is shared; anything decided inside one worktree is invisible to the others until it merges.
  • →So decide first, and stop when a new decision appears. Disjoint target paths; a mid-loop ADR lands on main as its own PR and the other loops rebase.
  • →You are the bottleneck on purpose: each merge is reviewed against the current main. Run as many loops as you can actually review, usually two or three.

ADR parallel-loops-in-worktrees

Case 4

Several agents, one source

AGENTS.mdsymlinkCLAUDE.mdthe index · only copy.claude/skills/symlink.agents/skills/the rituals · only copyread by allClaude CodeCLAUDE.md · .claude/skills · /nameCodexAGENTS.md · .agents/skills · $nameGitHub CopilotAGENTS.md · .agents/skills · /nameGemini CLIAGENTS.md* · .agents/skills* one config lineCI runs the same checks on every PR, whichever agent wrote it.
AGENTS.mdsymlinkCLAUDE.mdthe index · onlycopy.claude/skills/symlink.agents/skills/the rituals · onlycopyread by allClaude CodeCLAUDE.md · .claude/skills · /nameCodexAGENTS.md · .agents/skills · $nameGitHub CopilotAGENTS.md · .agents/skills · /nameGemini CLIAGENTS.md* · .agents/skills* one config lineCI runs the same checks on every PR, whicheveragent wrote it.
One copy of the context. Every agent finds it where it looks.
  • →Nothing to translate. The index and the procedures exist once; symlinks give each agent the path it looks for.
  • →CI is the guarantee: hooks help inside Claude Code, but the CI checks hold any agent’s PR to the same rules.

ADR agent-skills-as-procedures

What it costs, honestly

It is a discipline, not a tool that works while you look away.

  • →A few minutes per session for the start and close rituals, and about 30 minutes to bootstrap an existing repo.
  • →Decisions get written before code. The first week feels slower; the payoff is the week after, when nothing gets re-explained.
  • →It only works if the docs stay true. A stale ADR misleads the agent with full confidence. The hooks and CI exist to prevent that, but someone still has to run the ritual.

Get started

Adopt CFD in 60 seconds.

Clone the templates over your repo, edit CLAUDE.md with your project description, and start your first session.

git clone https://github.com/albertomarturelo/context-first-development.git /tmp/cfd
cp -R /tmp/cfd/templates/. .
# Edit CLAUDE.md with your project, then:
> /session-start

# or install just the skills into every agent:
npx skills add albertomarturelo/context-first-development
View on GitHub →

Don’t feel like cloning? The repo ships a zero-install bootstrap prompt: paste it into your agent, it generates the scaffold and embeds the rules into CLAUDE.md so future sessions inherit the full workflow.

Fit

Who is it for?

  • →Solo developers on non-trivial repos (100+ files).
  • →Teams of 2–20 adopting agents in production.
  • →Tech leads evaluating AI-assisted development at scale.

Not for: quick scripts, throwaway code, or “vibe coding” workflows.

Context first. Code second.

Open source, multi-model, and vendor-neutral. It’s plain Markdown: it works the same with Claude Code, Codex, GitHub Copilot, Gemini CLI, or Cursor.

Code MIT · Prose CC-BY-SA 4.0

I use Google Analytics to see what gets read. No advertising cookies, and no third parties beyond that measurement. More detail