How do you preserve project context across Codex sessions in a large codebase?

I’m a backend engineer working on a mature SaaS product with multiple services, shared dependencies, and years of accumulated architectural decisions.

My biggest issue with Codex is not code generation, but context loss. Every new session spends time rediscovering the architecture, important files, dependencies, and previous technical decisions.

I currently use AGENTS.md to document project conventions and important instructions. It helps, but it does not capture everything Codex learns while completing previous tasks, and it can become outdated as the project changes.

For developers using Codex on large production codebases:

  • What information do you keep in AGENTS.md?
  • How do you preserve knowledge learned during previous tasks?
  • Do you use session summaries, Skills, MCP, RAG, code graphs, or another approach?
  • How do you prevent outdated context from misleading Codex?

I’m especially interested in workflows that have been used for several months on mature projects.

What does your actual setup look like, and what approaches did not work for you?

What I found is that splitting up the application into an immutable core with modules and a shared db works pretty well.

This way the model doesn’t need to see all the modules .. just the small core + db + maybe ui core and the module you work on and maybe also connected modules .. but it reduces the effective code for the context it needs by alot.

on the other hand what you can do is using an AST parser like treesitter and write an AST into for example neo4j and then use a vectordb to find the community in the graph .. then use a script that cuts the flesh from the code skeleton because interface or doc blocks with params and return values are often enough to understand most of the code…

I mean there are tools out there for that. I think context7 is one .. but I don’t use them.. I build stuff by myself and for the immutable core + modules way you don’t really need it (it could save token I suppose)

That makes sense. In our case, we already use microservices with separate databases, so the code and data boundaries are relatively clear. The harder part is cross-service changes, where the model needs to understand API contracts, events, data flow, and the dependencies between several services.

I like your distinction between reducing context through architecture and dynamically selecting context through AST or graph-based retrieval. For changes that span multiple services, do you think service boundaries and interface definitions are usually enough, or is that where a code graph becomes genuinely useful?

What is your stack if I may ask?

Sure. We mainly use .NET in a microservices architecture. Each service has its own database, and the services communicate primarily through gRPC.

That’s why cross-service context is more difficult for us than understanding a single service.

I’ve been working through this while rolling out agentic coding workflows across a fairly large engineering organization. The rule that has held up best is: don’t try to preserve everything Codex learned. Preserve only what should still be true for the next engineer.

Raw session summaries feel useful at first, but after a few weeks they become a second, less reliable codebase. They retain dead ends, assumptions, and details whose source has moved. More memory can make the next run worse.

For a mature multi-service system, I use four layers:

  1. Root AGENTS.md: only stable cross-repo rules. Build and test commands, architectural invariants, safety boundaries, and the definition of done.
  2. Service-local AGENTS.md files: ownership, public interfaces, schema and migration rules, local commands, and the few non-obvious constraints that repeatedly matter.
  3. Canonical engineering artifacts: protobuf schemas, ADRs, API contracts, and integration tests. These remain the source of truth.
  4. A task packet: the issue, acceptance criteria, expected affected services, and required evidence. This is intentionally disposable.

For .NET and gRPC specifically, I would make the protobuf definitions first-class and keep a small producer/consumer map beside them. Before allowing edits, I ask Codex to produce an “impact manifest” containing:

  • affected services
  • contracts or events that may change
  • persistence and migration implications
  • tests that prove compatibility
  • known facts versus inferences, with a source path for each

A human approves that scope before implementation. In practice, this catches more mistakes than simply giving the model more context.

My usual first instruction is close to this:

Before editing, list the affected services, contracts, persistence layers, and tests. Cite the file path supporting each item. Separate known facts from inferences. Stop if a public contract or migration policy is unclear.

I use a similarly strict closeout. Instead of asking for a general session summary, I ask:

Which verified facts from this task would help any future maintainer? Cite the source for each one. Propose the smallest update to the nearest AGENTS.md or ADR. Do not preserve task-specific history.

The proposed update still gets human review.

Things that have not worked well for me:

  • a giant root AGENTS.md
  • storing raw chat logs as memory
  • broad RAG before the system boundaries are clear
  • generated architecture maps with no freshness check
  • asking every new session to rediscover the whole system

I would not start with a graph database. For dozens of services and indirect dependencies, a graph can become a useful derived index, but it should always point back to source files and commits. It should not become another source of truth.

The metric I care about is not “did Codex remember the codebase?” It is “can Codex produce a correct, evidence-backed impact plan before it edits anything?” If it can, the context system is working. If it cannot, the repository is not agent-readable yet.

Are your protobuf definitions and consumer compatibility rules centralized anywhere today? For the stack you described, that might be the highest-leverage place to start.

For a large .NET/gRPC codebase, I would keep the source of truth separate from the context-selection layer:

  • Root AGENTS.md: a short routing map and stable rules.
  • Protobufs, ADRs, and compatibility tests: canonical.
  • Each cross-service change: one project and a small task packet linking only the affected services, contracts, and decisions.
  • At closeout: keep verified facts, not raw session summaries.

That gives each new session a simple path: project map → current project → task packet → source files.

Disclosure: I built Dokito around this pattern. It connects multiple repositories to a local, Git-versioned Markdown Area with Context, Resources, Projects, and Tasks:

It is early and does not infer service dependencies. A useful first test would be one real cross-service change: can the next session produce the right impact plan without rescanning every repository?

I’ve been handling this by separating durable instructions from a deterministic snapshot of the repo’s current state. AGENTS.md carries stable guidance, while the snapshot captures Git state, README, entry files, recent commits, and directory structure in Markdown/JSON.

I ended up open-sourcing the small CLI I use for this: