Your Coding Agent Forgets on Purpose
Your coding agent did not get worse in the afternoon; OpenCode rebuilds a budgeted context window on every request, and once you can see that budget you can decide what survives it.

The OpenCode context window is a budget rebuilt on every request, not a memory. Learn what fills it, what it costs, and why the rule you agreed on at three o'clock is gone by four.
The agent quietly undid a decision you made an hour ago, and you started to wonder whether the model got worse. It did not; the decision fell out of a budget you can learn to control.
In this article: Day 6 of a 17-day guide. Start here runs a four-command experiment on Ticket Triage that shows a new OpenCode session remembers nothing from an earlier one, a continued session remembers only because its conversation is sent again, and
AGENTS.mdreaches every new session. Going deeper explains the mental model behind it: a context window rebuilt on every request, the measured fixed cost of one request (18,247 tokens before any work), one afternoon walked through the window, what compaction keeps and what it flattens, the model as a setting, and the V1 habits that load silently and mislead you.
Part 5 gave Ticket Triage a three-line AGENTS.md whose rules load on every request. Today shows why that file matters more than anything you say in chat.
Start here
By the end of today you can show, with four short commands, that a new OpenCode session remembers nothing from an earlier one, that a continued session remembers only because its conversation is sent again, and that AGENTS.md reaches every new session.
Starting fresh or fell behind? Run git switch -C main opencode/day-05. This replaces your main with the end of Day 5; to keep your own work, run git branch my-backup first.
What the model actually reads
The model does not remember anything between requests. On every request, OpenCode sends it a block of text, and the model reads that text and nothing else. The block has a limit, called the context window, which is the most text one request can hold. On every request, the block holds four kinds of text:
- The agent's standing instructions, which OpenCode writes.
build, the default agent from Part 1, has its own. - Your
AGENTS.mdfiles, the rules you wrote in Part 5. - The list of tools the agent may call, such as
read,edit, andshell. - The conversation so far in this session: your prompts, the files the agent read, the command output, and its replies.
A session is one conversation, with its own history. In the TUI from Part 2, the /new command starts one. The first three items are the same in every session of the project, and you change them only by changing configuration or files. They are not small. In a test on OpenCode 2.3.0 on November 16, 2026, the first request of a Ticket Triage session on google/gemini-4-hydrogen sent 5,904 input tokens before the agent did any work. The fourth belongs to one session only. When you start a new session, its conversation is empty, so anything you said in an older session is not in the block.
The experiment
Run four commands in Ticket Triage. Each one is a separate opencode run, which starts a new session unless you add --continue, the flag that sends the next prompt into the most recent session instead. The model is the one you connected in Part 1, google/gemini-4-hydrogen (tested on OpenCode 2.3.0 on November 16, 2026). If opencode models | grep '^google/' no longer lists it, use the newest Gemini model it shows.
Run the four commands in this order, with no other OpenCode prompt in between, because --continue picks the most recent session, whichever one that is. Start from a clean tree, so the last step can prove that nothing stayed behind. If git status --short lists files, commit them before you start; the last step restores AGENTS.md and would discard an uncommitted edit to it.
cd ~/code/ticket-triage
git status --short
First, tell a session a fact.
opencode run -m google/gemini-4-hydrogen "Remember this for later: the release codename is BLUE-HERON-7. Reply OK."
The answer is OK. Now ask the same session, with --continue, so this prompt joins that conversation.
opencode run --continue -m google/gemini-4-hydrogen "What is the release codename? Answer with the codename only, or UNKNOWN if you do not know it. Do not use any tool."
The answer is BLUE-HERON-7. The session knew it, because OpenCode sent the whole conversation again, the earlier prompt included. Now ask the same question in a new session, without --continue.
opencode run -m google/gemini-4-hydrogen "What is the release codename? Answer with the codename only, or UNKNOWN if you do not know it. Do not use any tool."
The answer is UNKNOWN. Nothing deleted the fact. The new session's conversation was empty, so the fact was never in the text the model read. Last, put the fact in AGENTS.md and ask a new session once more.
printf -- '- The release codename is BLUE-HERON-7.\n' >> AGENTS.md
opencode run -m google/gemini-4-hydrogen "What is the release codename? Answer with the codename only, or UNKNOWN if you do not know it. Do not use any tool."
The answer is BLUE-HERON-7. The session was new, but AGENTS.md is sent with every request, so the fact reached the model. The codename was only a test, so take it out again and check the tree.
git restore AGENTS.md
git status --short
The last command prints nothing. Today's win is the four answers in order: OK, BLUE-HERON-7, UNKNOWN, BLUE-HERON-7, and a clean tree. Your model may word the first reply differently; the codename answers are the check.
Where each kind of fact belongs
The experiment gives you a simple sorting rule for everything you tell the agent.
- A rule for every session goes in
AGENTS.md. Rule order inclassify(), the test command, a folder the agent must not touch: if you would say it again tomorrow, write it in the file and commit it. Every new session reads it. - A fact for this task goes in the prompt. The ticket text, the file to change, the shape of the answer you want. It needs to reach the model once, in this session.
- A file the agent should read goes in as a file. Name it in the prompt, as the Part 1 session did, so the agent reads the current version instead of a summary of it from earlier in the chat.
- A long thread that has drifted gets a new session. When a session is full of old test output and abandoned attempts, start a new one and restate the one or two decisions that still matter, or better, put them in
AGENTS.mdfirst.
The same rule explains a habit from Part 2: a session that is cheap to correct is one where the important decisions do not depend on the chat.
What the four answers mean
Chat is not memory, and files are. A decision you make in a session lasts as long as that session's conversation carries it. A rule in AGENTS.md reaches every session, because OpenCode reads the file again for every request. --continue resumes the most recent session, not the one you have in mind, so a run in between changes what it continues.
A long session has its own version of the same problem. The conversation grows with every file read and every test run, so an early decision becomes a small part of a large block of text, and the model can lose track of it. Going deeper walks through one such afternoon.
You can stop here. Going deeper explains why this works and where it breaks.
Going deeper
This section is for readers who want the full list of what OpenCode sends, the measured cost of that list, how a long session loses a decision, and what changed in V2. It assumes you finished Start here in this part and in Parts 1 to 5.
Four in the afternoon
It is four in the afternoon, and a small support-ticket service has been open in OpenCode since lunch. An hour ago the agent fixed a classifier bug: it added a damage check after the refund check and before the shipping check, and the two of you agreed that order was the whole point. Since then you have run the tests, chased a typo, and pasted a stack trace that no longer matters. Now you ask for one more test. The agent writes it, decides the order looks odd, and rewrites the classifier with the damage check first.
The model did not get worse at four o'clock. The decision you made at three is still a sentence somewhere in the session, buried under test output and file reads. If the session crossed its limit in the meantime, that sentence may now be a line in a summary, or gone. On every request the model reads what OpenCode sends it and nothing else, and what OpenCode sends is a budget, not a memory.
This section is about that budget: the OpenCode context window, what fills it before you type a word, how it grows while you work, and what happens when it runs out. Once you can see it, the four o'clock rewrite stops being a mystery and becomes a configuration problem.
The decision the afternoon needs
Before Part 3's fix, the crushed-mug ticket from Part 1 printed other. The customer said "box," not "package." The fix is a damage rule: crushed, broken, or "in pieces" routes to shipping, and to refund when the customer also asks for money back. It forces a decision about rule order, exactly the kind of decision an agent forgets when the window fills.
OpenCode is a runtime, and the model is a setting
OpenCode is an open-source coding agent from Anomaly, and it is a server with clients rather than one program. By default it discovers or starts one shared background server for your user account, and that server owns sessions, configuration, permissions, and tool execution. The opencode command opens the full-screen terminal interface, the TUI, which is only one client. opencode mini, the web interface reached with opencode pair, and scripts that call opencode run all reach that shared server. Editors that connect through opencode acp start a private server of their own, and the desktop app runs its own server and shows the shared sessions after you pair it. The --standalone flag runs a private server for one command, and --server connects to a URL you name.

The model behind a session is a setting the server applies, not the product you installed. You can connect Anthropic, OpenAI, GitHub Copilot, a cloud platform, OpenCode's own Console models, or a local model, and switch per session, per agent, or per command. The measured run later in this article used google/gemini-3.5-flash, and nothing in the repository depended on that choice. Start here used google/gemini-4-hydrogen, which Google's models page recommends for new projects as of November 16, 2026.
What OpenCode sends on every request
Every request is a fixed front section plus a conversation that grows. The instructions page lists six sources that OpenCode combines in order, and tool definitions and the conversation complete the request.

OpenCode builds each request from eight inputs. The Input column names each piece, "Where it comes from" names who supplies it, and "When it changes" names what must happen before the model sees it differently. The first seven inputs are what you pay before you type a word; the last is what you pay while you work.
- Agent or provider system prompt comes from the selected agent or the provider and changes when you switch either.
buildis the default agent that edits and runs commands;plandenies edits to project files but keeps its shell. - Code Mode tool guidance comes from OpenCode when Code Mode is on, which lets the agent reach MCP tools through one
executetool; MCP servers use it by default. It changes when you add MCP servers or denyexecute. - MCP server, reference, and skill guidance comes from server instructions, configured references, and the skills list. Skills appear as an ID, a name, and a description, so twenty skills cost twenty short entries.
AGENTS.mdfiles, then configured instructions load global first, then upward from the workspace, then theinstructionsarray. Every line rides along on every request; edits to a nested file need a new session.- Date and environment context is built in, rarely changes within a session, and is not something you configure.
- Session-specific instruction entries come from clients and scripts through the API, only when a client supplies them.
- Tool definitions cover built-in tools such as
read,edit,shell, andsubagent. If you denyexecute, every MCP tool it would have reached is listed directly, with its full definition, in every request. - Conversation holds your prompts, attachments, tool calls, results, and replies. It grows every turn until compaction replaces the older part with a summary, and it is the input that buries a three o'clock decision.

Putting a number on the fixed cost
The front section is not small, and you can measure it. The research for this series ran OpenCode 2.3.0 against Ticket Triage on google/gemini-3.5-flash, a model Google's models page no longer lists, with JSON output, which records a step_finish event per step with token counts and cost.
opencode run --standalone -m google/gemini-3.5-flash --format json --archived "Run npm test and tell me how many tests passed."
--standalone runs a private server for the one command (Part 1), --format json prints the run as a stream of JSON events instead of text, and --archived keeps the session out of the session lists.
The first request sent 18,247 input tokens. The project was nearly empty, three small source files and a short AGENTS.md, and the agent had done no work yet. Those tokens were the system prompt, the tool definitions, AGENTS.md, and the descriptions of the 56 personal skills in the author's ~/.claude/skills folder, which OpenCode reads as a compatibility folder. The second request read 16,194 tokens from the provider's prompt cache. The steps cost $0.0285 and $0.0066, about $0.035 for the run.
A rerun on November 16, 2026, separated the two. In a Ticket Triage project at the end of Part 5, with an empty home folder, the same command's first request sent 5,904 input tokens on google/gemini-4-hydrogen and 5,846 on google/gemini-3.5-flash. With the 56 personal skills visible again, the two models sent 18,116 and 18,205. The model barely moved the floor. The skills tripled it. On gemini-4-hydrogen, two more runs in the clean home folder sent the same 5,904 tokens, 3,850 of them read from the prompt cache.

The rerun measured 5,904 input tokens on the first request in a clean home folder, 18,116 with the personal skills in view, and 3,850 tokens read from cache on later runs. What remains after that floor is the room for your code, your test output, and your decisions.
About six thousand tokens is the floor every request stands on in a clean home folder, about eighteen thousand with the author's skills, and an MCP server with forty tools listed directly, a long AGENTS.md, or a dozen wordy skills raises it for the life of the session. Most of the floor is cached, because it did not change between requests, and cached reads cost much less than fresh input. The room left over is what your work gets, and every OpenCode feature either adds to the floor or protects that remainder.
One afternoon, from the window's point of view
A turn is one model response plus the tools it calls, and every tool result stays in the conversation until something removes it. At three o'clock you type a prompt with an @ attachment that puts the file into your message.
Add a damage rule to @src/classify.js: crushed, broken, or "in pieces" goes to shipping, but keep the refund check first.
The agent reads the test file, edits the classifier, and runs npm test. Each call and each result is now part of the conversation.

On screen, that turn is a few lines. In the window it is a prompt, two files, a diff, and the test runner's whole report. Repeat it a dozen times with a typo hunt and a stale stack trace, and "keep the refund check first" is a small fraction of what the model reads. Nothing deleted it; newer, louder material outvoted it. The tools cap single results, with a read returning at most 2,000 lines and 50 KiB per page, but caps do not stop forty reasonable results from crowding out one decision.
What compaction keeps, and what it flattens
When the conversation nears the model's limit, OpenCode compacts it. It summarizes the whole conversation and keeps about the most recent 15,000 tokens beside the summary, so exact recent details survive. Automatic compaction is on by default, with keep.tokens set to 15000 and a buffer of 15 percent of the window, at least 16k. The summary records the objective, decisions, completed and active work, blockers, the next move, and relevant files. Earlier messages stay stored, but they stop going to the model.

The docs say plainly that compaction is lossy. A three o'clock decision is exactly the detail a summary can flatten into "added a damage rule," which is how the four o'clock rewrite happens. After compaction, the current instruction files become the session's new baseline: a rule in AGENTS.md comes through untouched, and a rule said only in chat depends on the summary.

The scene is the opening moment of this article: a developer watching the agent undo a decision made an hour earlier, with the compaction flow on the monitor as the reason.

Compaction fires with a buffer of 15 percent of the window, keeps the recent 15,000 tokens, and replaces older history with a summary, so where a rule lives decides whether it survives.
Compaction can only replace older conversation. When a request is mostly fixed instructions and tool schemas, there is nothing to summarize, and the compaction page gives the arithmetic.
128k context = 120k fixed instructions and tools + 8k conversation
No summary rescues that session. The only fix is a smaller fixed cost.
If you already use Claude Code: OpenCode has a /compact command too, as Claude Code does, but you rarely need it. Compaction runs on its own near the limit, and reaching for /compact out of habit throws away detail you may still need.
The V1 habits that load without an error
This article covers OpenCode V2, anchored to release 2.3.0 from November 13, 2026, titled "Background Subagents by Default" in the changelog, where opencode --version prints opencode v2.3.0. The migration guide names three intentional breaks: a new plugin API, new server API contracts, and terminal settings moved from tui.json to one global cli.json. Outside those, V2 reads V1 configuration and normalizes it in memory. The compatibility is kind to your old config and unkind to your learning: a V1 shape copied from a blog post often loads without an error, so the failure shows up as confusion.

Each V1 configuration shape has a V2 replacement. The "V1 shape" column holds what an older tutorial or config still says, and the "V2 shape" column holds what you write from day one.
permissionmap keyed by tool becomes an orderedpermissionslist where the last matching rule wins, withbashrenamedshellandtaskrenamedsubagent.providermap becomesproviders:npmbecomespackagewith anaisdk:prefix,apibecomessettings.baseURL, andoptionssplits intosettings,headers, andbody.small_modelbecomesagents.title.model, because V2 treats session titles as a hiddentitleagent.tui.jsonterminal settings move to one globalcli.jsonthat the background server does not read.CLAUDE.mdfallback is gone; V2 discoversAGENTS.mdand nothing else.- Tail-turn and pruning compaction settings are ignored with a warning, replaced by a token budget beside a summary.
- Language servers and LSP tools do not run in V2; use the project's lint, typecheck, or test command instead, which for Ticket Triage is
npm test.

Five renames cause the most confusion, each a V1 shape with a V2 replacement: permissions, providers, the title model, instruction files, and compaction settings.
If you learned V1: the npm package opencode-ai still installs V1. The V2 command-line package is @opencode/cli.
Four ideas worth holding onto
Strip the commands away, and working with OpenCode rests on four ideas.

The model is a setting. The server runs the session, and you can mix vendors in one project: a stronger model for plan and a cheap one for session titles is ordinary configuration.
Every feature decides what the model sees. AGENTS.md, references, compaction, subagents, skills, commands, and MCP servers each sit at one input of the request, and each either adds to the fixed cost or protects the room left over.
The default is allow, so you write the rules. On a real 2.3.0 install, every built-in agent starts from a base rule that allows every action, plus rules that ask before reading .env files. opencode debug agents shows the base rule, and the agents page documents the .env rule. The build agent edits files and runs shell commands without asking.
Done means a command ran. A model that says "the tests pass" has told you what it believes. A tool_use event for npm test with three passing tests is what happened.
If you already use Claude Code: the habits carry over (keep the window clean, put rules in a file, give the agent a way to verify), but three misfire: CLAUDE.md does not load, OpenCode allows everything by default, while Claude Code decides through permission modes that you can switch, and Shift+Tab cycles agents rather than permission modes. Claude Code is built around Anthropic's Fable, Opus, Sonnet, and Haiku models; OpenCode makes the model a setting.
Do this today
Everyone
- Repeat the experiment. In Ticket Triage, with a clean tree and a committed
AGENTS.md, run the four Start here prompts in order and check the four answers:OK,BLUE-HERON-7,UNKNOWN,BLUE-HERON-7. Then rungit restore AGENTS.mdand confirmgit status --shortprints nothing. - Start one habit: write decisions in a file, not only in chat. When you agree on a rule that must outlast today's session, add one line to
AGENTS.mdand commit it.
If you read Going deeper
-
Write down two decisions your last agent session forgot. Keep the note outside the repository; Part 7 shows what a summary does to the ones that stay in chat.
-
Measure the rules OpenCode will not read. V2 loads only
AGENTS.md, so count what is stranded inCLAUDE.md.wc -l CLAUDE.md AGENTS.md -
Find your fixed cost. Run one headless prompt with
--format jsonand readtokens.inputin the firststep_finishevent.opencode run --standalone -m google/gemini-4-hydrogen --format json --archived "Run npm test and tell me how many tests passed." | grep -m1 step_finish
The model was never forgetful
The four o'clock rewrite felt like the model getting tired. It was arithmetic. Thousands of tokens of instructions, tools, and skill descriptions went out before any work began, a dozen ordinary turns piled file reads and test output on top, and a one-sentence decision lost the vote, or lost its wording in a summary.
Once you see the OpenCode context window as a budget rebuilt on every request, the fixes stop being superstition. Keep the fixed front small. Put the rules that must survive in AGENTS.md, where compaction cannot flatten them. Pick the model per job, because it is only a setting. And believe the test runner, not the reply.
Your coding agent forgets on purpose. Decide what it is allowed to forget.
This is Part 6 of "OpenCode, Day-to-Day," a 17-part guide to using OpenCode V2 as a daily, provider-neutral coding agent.