Context Management

Why it's the bottleneck - and how the protocol keeps you out of it

Context is the bottleneck - not the model

  • The model is usually fine. Your context is the problem.
  • Long sessions accumulate irrelevant noise - old plans, dead branches, raw tool output
  • More tokens is not more smart. It is more confused.
  • Fresh sessions with zero context forget everything useful you already learned
  • Two separate failure modes, one root cause: bad context hygiene
Context rot mid-session and amnesia across sessions are the same problem at two timescales.

The two failure modes

In-session: context rot

Session starts sharp. Hours in, the agent is slower, repeats itself, loses the plot, re-reads files it already knows. The context window is full of stale noise crowding out what matters.
Across sessions: amnesia

Every new chat starts from zero. Hard-won conventions, past decisions, and project quirks die with the last session. You re-explain the same things, forever.

Fighting in-session rot

Subagent delegation
Heavy work (research, reviews, investigations) runs in a sub-thread. Only a structured summary returns to the main context.

Worktree isolation
Workers get their own clean slate. Their reads, failed attempts, and raw tool output never touch your main session.

Focused sessions
One goal = narrow context. The protocol actively resists scope creep because scope creep is context creep.

Risk classification
Small stuff stays direct and cheap. Big stuff is delegated out. Neither bloats the main thread.

Fighting cross-session amnesia

/ds-init-project
One-time per repo. Seeds AGENTS.md, captures conventions, bootstraps memory.
Same project dir
cwd is the project identity. Running claude from the same directory always reads the same persistent memory.
/ds-wrap
End-of-session ritual. Commits learnings into memory so the next session reads richer context than this one.
/ds-init-project -> work -> /ds-wrap -> next session from the same dir is a feedback loop. Each run starts smarter than the last.

The load-bearing habit: run from the project directory

The cwd is the project directory. Every bit of persistence - AGENTS.md, MEMORY.md, session history, /ds-wrap outputs - is keyed to the directory claude was started in. Nothing else matters for memory continuity.

cd ~/code/myproject
claude

Same directory every time = same persistent memory every time. That's the whole mechanism.

Session naming (-n myproject) and resumption (-r) are optional ergonomics - labels and recovery tools, not memory mechanisms. The real load-bearing habit is the cd.

The compounding loop

  1. /ds-init-project seeds baseline context for a repo
  2. You work a focused session - one clear goal
  3. Heavy lifting is delegated so the main thread stays clean
  4. /ds-wrap commits learnings into memory
  5. Same cwd next time - Claude Code reads the same memory and AGENTS.md automatically
  6. Next session starts with richer AGENTS.md, fuller MEMORY.md, sharper defaults
  7. Repeat - each loop is a step up, not a reset
The whole system is designed around one bet: context hygiene beats raw model smarts. Respect the loop and it pays back every session after the first.

Two layers of session capture

Stop hook (automatic)
Fires after every turn. Writes .agentic/context.md with recent user messages, files touched, uncommitted changes, and tools used. Zero ceremony - it just runs.
/ds-wrap (on demand)
Replaces the stop hook's raw snapshot with a structured, enriched version. Captures decisions, conventions, and gotchas into AGENTS.md and memory. Merges across sessions.

If /ds-wrap has already written .agentic/context.md, the stop hook appends a Session Activity block instead of overwriting - so /ds-wrap content is never lost.

The stop hook is the safety net - you always get something. /ds-wrap is the upgrade - you get structured, compounding context.
Close the session cleanly so the Stop hook can finish writing .agentic/context.md. In the terminal CLI, use /exit rather than ctrl+c (ctrl+c can interrupt the hook and lose session state). In the desktop or web app, /exit is not available - just close the window or tab normally rather than force-quitting.

Multiple sessions and the rolling window

You can run multiple sessions in parallel - open separate terminals, each with claude in the same project directory. They share the same persistent memory and AGENTS.md.

When you /ds-wrap each session, they merge into a shared .agentic/context.md using a rolling window of ten slots (Session A through J):

  • First wrap writes Session A. Second wrap labels the existing as A, adds B.
  • At ten sessions, the oldest (A) drops off and everything shifts down.
  • Non-focus sections (next steps, file paths, gotchas) merge across all sessions - duplicates removed.

This means you can work on ten parallel streams in a project and /ds-wrap each one. The next session that starts sees a merged view of all recent work.

The rolling window keeps .agentic/context.md bounded. Ten slots capture even heavily parallel workflows while keeping the file bounded.

Keep context clean. Let it compound.

Focused sessions. Same project dir. /ds-wrap every time.

github.com/Space-Dinosaurs/DinoStack