The Summary Dropped the Rule: What OpenCode Compaction Does to Instructions You Typed in Chat

OpenCode compaction keeps a long session alive by replacing old conversation with a model-written summary, so any rule you only typed in chat is the first thing at risk; move standing rules into AGENTS.md, which compaction never touches and reloads as the new baseline.

Rick Hightower

Cover image for “The Summary Dropped the Rule: What OpenCode Compaction Does to Instructions You Typed in Chat” by Rick Hightower

Compaction keeps a long OpenCode session alive by trading old conversation for a summary. A rule you only said in chat is old conversation, and a rule in AGENTS.md is not.

The agent followed your rule all morning, then quietly stopped after lunch and still told you every test passed. You did not change anything, and you cannot see what changed.

In this article: Day 7 of a 17-day guide. Start here moves a standing chat rule, a test for every new keyword, into Ticket Triage's AGENTS.md, then checks that a new OpenCode session quotes it word for word and follows it. Going deeper shows what compaction does to a long session: what the summary keeps and flattens, the three compaction settings and where the threshold sits on hosted and local models, compacting by hand from the TUI and the API, and a real 2.3.0 run where the summary kept a rule and the agent still half ignored it.

Part 6 showed that a new session remembers nothing from chat, and that AGENTS.md reaches every session. Today covers the case in between: one long session that has to throw away part of its own chat to keep going.

Start here

By the end of today the rule that every new keyword gets a test lives in AGENTS.md, where a long session cannot summarize it away, and you have checked that a new session quotes the rule and follows it.

Starting fresh or fell behind? Run git switch -C main opencode/day-06. This replaces your main with the end of Day 6; to keep your own work, run git branch my-backup first.

What compaction does

Part 6 named the limit on one request: the context window, the most text a single request can hold. A long session grows with every prompt, file read, and test run, and eventually its conversation nears that limit. OpenCode then compacts the session. Compaction "makes room in a long session by replacing older conversation with a summary," and a model writes that summary. The older messages stay stored in the session, but the model stops receiving them. From then on, it reads the summary in their place.

You do not have to start compaction. OpenCode runs it on its own when a session nears the limit, and most days you will not notice. What you do have to decide is where your rules live, because the docs say plainly that "Compaction is lossy."

What survives, and what does not

A rule can live in two places, and compaction treats them differently.

  • A rule you typed in chat is conversation. Once the session compacts, the model sees it only as the summary's paraphrase, if the summary kept it at all. The rule you set first thing in the morning is also the oldest thing in the session.
  • A rule in AGENTS.md is not conversation. OpenCode reads the file from disk and sends it with every request, as Part 5 showed. The compaction page states the guarantee in one sentence: "After compaction, the current versions of your instruction files become the session's baseline." The model gets your words, not a summary of them.

Part 5's test for a line in AGENTS.md was "would you type it again tomorrow?" Compaction adds a second form of the same question: would you type it again after lunch? A rule you would have to repeat once the session compacts is a rule for the file.

Move the keyword rule into AGENTS.md

Today's work on Ticket Triage is growing the keyword lists in src/classify.js, so more real tickets land in the right category. The natural ground rule is one you would set in chat: "For every keyword you add to classify(), add a test in test/classify.test.js that uses it." A standing rule like this one belongs in the file.

Part 5's discipline still applies, so do not grow the file for the sake of it: the new rule is about tests, and it fits on the layout line. Start from a clean tree, then rewrite the file.

cd ~/code/ticket-triage
git status --short
cat > AGENTS.md <<'EOF'
- Run `npm test` before you say a change is done, and report the result.
- Source lives in `src/` and tests in `test/` (Node's built-in runner with `node:assert/strict`); every keyword added to `src/classify.js` gets a test that uses it.
- Ask before you edit anything under `.opencode/`.
EOF
wc -l AGENTS.md
git diff --stat

git status --short prints nothing before the edit, because Part 5 ended with a commit. wc -l still reports three lines, and git diff --stat shows one file changed, AGENTS.md, with one line replaced. Commit it, so every session and every teammate gets the rule.

git add AGENTS.md
git commit -m "Move the keyword test rule into AGENTS.md"

Check that a new session receives the rule

A new session is the strictest version of "after compaction": none of the old chat is sent, not even a summary. A rule that reaches a new session reaches the model after every compaction too, because both start from the files on disk. Run the quote check from Part 5, with the model you connected in Part 1, google/gemini-4-hydrogen (tested on OpenCode 2.3.0 on November 16, 2026).

opencode run -m google/gemini-4-hydrogen "Without using any tool, quote the rules from your project instructions file, one per line, exactly as written. If you have none, answer NONE."

The answer is your three lines, and the second one now ends with the keyword rule.

> build · gemini-4-hydrogen
- Run `npm test` before you say a change is done, and report the result.
- Source lives in `src/` and tests in `test/` (Node's built-in runner with `node:assert/strict`); every keyword added to `src/classify.js` gets a test that uses it.
- Ask before you edit anything under `.opencode/`.

Put the rule to work

Now ask for a keyword in a new session, and do not mention tests.

opencode run -m google/gemini-4-hydrogen "Route \"Where is my parcel? The tracking page has not moved\" to shipping by adding the keyword tracking to classify()."

Watch the tool calls. The agent reads the classifier, the tests, and package.json, shown as → Read lines. Then come two edits, ← Edit src/classify.js and ← Edit test/classify.test.js, and a $ npm test line. The reply names both changes and ends with the test result, which should report 0 failed. Some models add a test without being told. The rule makes it a standing instruction for every session, and the quote check above is how you know the model received it.

The test edit appends one test like this one, which is the version on the opencode/day-07 tag; your agent may name it differently.

test("tracking issue goes to shipping", () =>
  assert.equal(classify("Where is my parcel? The tracking page has not moved"), "shipping"))

Check the result yourself rather than the reply.

grep -n "tracking" src/classify.js test/classify.test.js
npm test

grep prints one line in src/classify.js, where tracking joins the shipping keywords, and at least one line in test/classify.test.js with a test that uses the parcel sentence. If grep finds the keyword in src/classify.js but no test, the change broke the rule: ask for the missing test, or write it yourself, before you commit. The npm test summary shows one more test than before, and fail 0. Commit the change.

git add src/classify.js test/classify.test.js
git commit -m "Route tracking tickets to shipping"

Today's win is three checks you ran yourself: a new session quoted the keyword rule in your own words, grep found a test for the new keyword, and npm test printed fail 0.

You can stop here. Going deeper explains why this works and where it breaks.

Going deeper

This section is for readers who want to watch compaction work: what a summary keeps and flattens, the three settings and where the threshold sits, compacting by hand, who writes the summary, what compaction cannot fix, and an experiment that follows a chat rule through a summary. It assumes you finished Start here in this part and in Parts 1 to 6.

Ten in the morning, three in the afternoon

Picture the day before the rule moved into the file. At 10 a.m. you open a fresh OpenCode session on Ticket Triage. You want the keyword lists in src/classify.js to catch more tickets, so before the first change you set a ground rule in chat: "For every keyword you add to classify(), add a test in test/classify.test.js that uses it." The agent agrees. tracking arrives with a test, then courier, then lost in transit.

At 3 p.m. you ask it to route "The lid arrived dented" to shipping. It adds dented, runs npm test, and reports that every test passed. The tests did pass. None of them mentions dented. Somewhere around lunch the session compacted. The day is a scenario rather than a recorded run, but the mechanism is documented, and so is the contrast inside it: the rule in AGENTS.md, "run npm test before you say a change is done," held all afternoon. The rule you typed at 10 a.m. did not.

Scene: a frustrated developer at a desk in mid-afternoon, scratching their head while scrolling up through five hours of agent chat, with the two-lossy-links diagram on the monitor

The scene is that 3 p.m. moment: a passing test run, no test for the new keyword, and a developer trying to work out when the morning rule stopped counting.

The difference is where each rule lived. One sat in the instruction files OpenCode sends at the top of every request. The other sat in the conversation, the part that OpenCode compaction exists to shrink.

What OpenCode compaction does to a long session

Compaction is how OpenCode keeps a session going past the model's context window. The compaction docs put it in one sentence: it "makes room in a long session by replacing older conversation with a summary." Near the limit, OpenCode summarizes the entire conversation and keeps the most recent part, about 15,000 tokens by default, beside the summary so exact recent details survive.

Three states of an OpenCode request: before compaction the older conversation sits between the fixed opening and the recent 15k tokens; the summary request appends summary instructions; afterward a summary replaces the older conversation while the system prompt and AGENTS.md stay untouched

The summary request sends the full conversation, which lets it reuse the prompt cache when the provider supports it. Every request afterward carries the instructions, the summary in place of the older conversation, and the recent 15,000 tokens. Three more facts shape a long day.

  • Later compactions update the summary "using the conversation since that checkpoint." A rule that missed the first summary does not come back in the second.
  • Earlier messages stay stored. The 10 a.m. message is still in the session's history; the model simply stops receiving it.
  • It is lossy, and the docs say so. "Increase keep.tokens when exact recent details matter, or request compaction yourself before the automatic one."

The opening rows of the request, from the system prompt through your AGENTS.md, are fixed. Compaction acts only on the conversation that follows them.

What a summary keeps, and what it flattens

The summary is "structured so another agent could pick the work up from it": objective and requirements, decisions, completed and active work, blockers, next moves, and relevant files. In the kept tail, long tool output is shortened and attachment data becomes a short description.

The author tested this on OpenCode 2.3.0 in a single run with a copy of Ticket Triage, google/gemini-3.5-flash-lite, and keep.tokens set to 0, so only the summary carried the old turns. The first message set a chat-only rule, the second asked the agent to count keywords, and then a manual compaction ran. This excerpt from the exported session shows three of the summary's fixed sections.

## Objective
- Count the total number of keywords in `src/classify.js` and `test/classify.test.js`.

## Requirements
- Rule established for the session: whenever adding a keyword to `src/classify.js`, also add a test for that exact keyword in `test/classify.test.js`, and keep every keyword list in alphabetical order.

## Important Context
- Session rule: whenever adding a keyword to `src/classify.js`, also add a test for that exact keyword in `test/classify.test.js`, and keep every keyword list in alphabetical order.

In a two-message session, the summary kept the rule twice, almost word for word. It also promoted the last small request, counting keywords, to the session's objective. Both were the summarizing model's choices, and you saw neither being made. The rule has a slot to land in, but whether it lands there on a five-hour day is up to that model, and four things work against a chat rule.

  • It is the oldest thing in the session. When the conversation is itself too long, "OpenCode sends a shortened text version and may leave out the oldest exchanges."
  • It looks finished. By lunch the transcript shows a rule followed four times, and "added tests for new shipping keywords" under completed work is true while dropping the instruction to keep doing it.
  • It comes back in the summary's words, in a block about the past, not in the instruction block the model treats as standing orders.
  • A kept rule is not an obeyed rule. In one run, the same test, later in this article, kept the rule and the agent still applied it only in part.

The two lossy links between a chat rule and the agent's behavior: the summarizer may drop the rule or keep it as a paraphrase, and the next model call may weigh that paraphrase lightly; the same rule in AGENTS.md skips the first link and arrives in your own words

None of this is a bug. Compressing five hours into something a fresh agent can act on is lossy by design. A durable rule does not belong in the part of the request that gets compressed.

The three compaction settings

Compaction has three settings, and they can go in any OpenCode configuration file.

Table: Field, Default, What it controls. Rows: auto; keep.tokens; buffer.

These are the only three knobs for summary compaction. The Field column names the key, the Default column gives its value when you set nothing, and "What it controls" says which question the key answers: whether compaction runs on its own, how much recent detail survives, and how early it starts.

  • auto defaults to true and compacts near the limit, with one recovery when a provider rejects a request as too long. Turning it off stops both, though manual compaction "always works."
  • keep.tokens defaults to 15000 and sets the tail that survives word for word. "Larger values preserve more detail but leave less room for new work."
  • buffer defaults to 15 percent of the window with a 16k floor. It is the room kept free, not the trigger point, so a larger buffer compacts earlier.

Gotcha: raising keep.tokens feels free, because nothing breaks. Every kept token is one the next stretch of work cannot use, and on a small window a large value can make the session compact again soon after.

If you learned V1: per the migration guide, preserve_recent_tokens became keep.tokens, reserved became buffer, and tail_turns and prune "are ignored with a warning."

Where the compaction threshold sits

A percentage buffer fits every model you switch between. The docs give two data points: with "buffer": "20%", a 128k window compacts at about 102k and a 1M window at 800k. Both compact at 80 percent full, while the absolute room kept differs by a factor of eight.

How the buffer sets the threshold: a 20 percent buffer compacts a 128k window near 102k and a 1M window at 800k; a local model declared at 64,000 tokens hits the 16k floor and compacts near 48k, leaving roughly 42k for conversation after a 6k fixed opening, or about 30k with a few dozen skills

Local models need one more step. OpenCode sizes a discovered Ollama model's window from its trained length, 131,072 tokens for llama3.2 in the author's test with Ollama 0.31.1, not from what the server serves. At OLLAMA_CONTEXT_LENGTH=64000, the default buffer plans compaction near 111,000 tokens, far past what the server holds, and because Ollama may truncate rather than reject, the overflow recovery may never fire. Declare limit.context as 64000 and the numbers match: 15 percent is 9,600, under the 16k floor, so compaction starts near 48,000 tokens. Subtract a fixed opening of about 6,000 tokens in a clean home folder, and the local model has roughly 42,000 tokens of conversation before it compacts. A home folder with a few dozen skills raises the opening to about 18,000 and leaves roughly 30,000.

Infographic: a percentage buffer fits every model. The default buffer is 15 percent with a 16k floor, and a 20 percent buffer compacts a 128k window at about 102k and a 1M window at 800k

The threshold rule has four parts: the 15 percent default, the two documented points for a 20 percent buffer, the fact that a larger buffer starts earlier, and the one step every local model needs, declaring limit.context.

A token count such as 20000 also works, but it is a large share of a small window and a small share of a large one, and a count at least as large as the window is ignored. Prefer a percentage.

Compacting by hand with /compact and the API

In the TUI, /compact runs compaction; the 2.3.0 binary describes it as "Compact session," and <leader>c is bound to session.compact. From a script, find the session ID (it starts with ses_) and post to the compact route.

opencode session list
opencode api post /api/session/ses_example/compact --data '{"id":"msg_compact_once"}'

The api command finds and authenticates with the background service. The response only confirms acceptance; follow the session.compaction.* events to learn when the summary is done. The id makes an exact retry idempotent, and reusing it for a different request returns a conflict. In the author's 2.3.0 test, a single run, the response came back at once.

{"data":{"id":"msg_...","type":"compaction","payload":{},"delivery":"steer"}}

Seconds later, opencode session export showed a compaction message with "status": "completed" and "reason": "manual", for about $0.002.

Sequence of a manual compaction: a script posts to the compact route, the server accepts it at once as a steering compaction message, runs it at the next safe point before queued prompts, emits session.compaction events, and the export later shows status completed and reason manual

A manual request runs at the next safe point, before any queued prompts. Requests made while one is pending merge into it, so a retry loop cannot stack summaries, and it works even with auto: false. The docs allow compacting "at any time, even for a short history," but compacting early trades detail you were going to use for room you did not need. Use natural boundaries: after a commit, or before an unrelated task.

Who writes the summary

By default, the session's model writes the summary, through the hidden compaction agent, which you configure but never switch to. Set agents.compaction.model to a capable model, because a weak summary costs a rule; if the name cannot be resolved, OpenCode falls back to the session's model.

Two variations exist. Native compaction, opted into with settings.compaction set to { "type": "native" }, lets some providers (the docs list OpenAI Responses models) return "an opaque, encrypted item that stands in for the older conversation," always on the session's model; you could not read it to check your rule anyway. The experimental background_compaction setting prepares the summary 60,000 tokens early so the session does not pause, but it "may change, break, or be removed in any release without notice." Leave both off for a project like this one.

What compaction cannot fix

Compaction makes room only by replacing conversation, and the docs list its limits.

Table: Limit, Result. Rows: Model; History; Size; Recovery; Storage.

Each documented limit bounds what a summary can do for you. The Limit column names the boundary, and the Result column says what OpenCode does at it.

  • Model: the summary is only as good as its writer, and agents.compaction.model is your lever for summary compaction only.
  • History: with 128k context = 120k fixed instructions and tools + 8k conversation, no summary helps; only a smaller fixed opening does.
  • Size: an overlong conversation goes out shortened, and a rule set first thing in the morning is the oldest exchange in the session.
  • Recovery: the overflow net fires once, and a second overflow in a row is an error, usually from a huge fixed opening or tool result.
  • Storage: nothing is deleted, and opencode session export <id> still includes old messages, but the model sees only what is sent.

A few other settings decide how fast a session reaches the threshold. Tool output limits cap what one result adds, and the tools page says long shell output is shortened with the full text kept in a managed file. Warming requests never add messages to history. A committed /undo removes messages from the active view and reloads your instruction files, and a nested AGENTS.md whose entry was summarized away loads again on the next read in its area.

After compaction, the files are the baseline

One sentence from the compaction docs carries this whole article: "After compaction, the current versions of your instruction files become the session's baseline." AGENTS.md is not conversation, so compaction never summarizes it. It is read from disk, and after compaction its current version is the starting point. The 10 a.m. chat rule went into the summarizer and came out as whatever the summary chose to say.

Table: Where the rule lives, What compaction does to it, What the model reads afterward. Rows: A chat message; The kept recent tail; A nested AGENTS.md; Project or global AGENTS.md.

Four places can hold a rule, ordered from most fragile to most durable. The first column names the location, the second says what compaction does to a rule stored there, and the third says what the model reads after the next compaction.

  • A chat message is summarized, and afterward survives only in the summary's words, if at all. Fine for a one-off, wrong for a standing rule.
  • The kept recent tail is kept word for word until the next compaction, which is why repeating a rule seems to work until later in the day.
  • A nested AGENTS.md can lose its loading entry, and the model reads nothing from it until the agent returns to that directory, which suits a rule about one package.
  • Project or global AGENTS.md is never summarized, becomes the new baseline, and reaches the model in its current text on every request.

Where a rule lives decides its fate: a chat message survives only as the summary's words, the kept tail survives word for word until the next compaction, a nested AGENTS.md returns on the next read in its directory, and a project AGENTS.md is never summarized and becomes the baseline

Infographic: chat rules fade, file rules return. Four places a rule can live, from a chat message summarized into the summary's words, through the 15,000-token kept tail and a nested AGENTS.md, to a project AGENTS.md that is never summarized and sent on every request

Only a rule in a project or global AGENTS.md keeps your words no matter when compaction fires, while the kept tail holds only the most recent 15,000 tokens by default. The test for any rule is simple: would you have to type it again after lunch? If so, it belongs in the file.

Run the experiment on Ticket Triage

/compact reproduces the opening in minutes. With the default keep.tokens, a short session fits inside the kept tail, so set it to 0 temporarily in opencode.jsonc.

{
  "compaction": {
    "keep": { "tokens": 0 },
  },
}

Start here already moved the rule into AGENTS.md, so put the Part 5 version of the file back for the experiment.

cat > AGENTS.md <<'EOF'
- Run `npm test` before you say a change is done, and report the result.
- Source lives in `src/` and tests in `test/` (Node's built-in runner with `node:assert/strict`).
- Ask before you edit anything under `.opencode/`.
EOF

Start a session in the build agent, with git status --short showing only those two edits. State a rule, make a change under it, compact, then ask for a second keyword without restating the rule.

Rule for this session: for every keyword you add to classify(), add a test in test/classify.test.js that uses it. Now route "Where is my parcel? The tracking page has not moved" to shipping by adding "tracking" if it is missing.
/compact
Route "The lid arrived dented" to shipping by adding "dented" to the damage keywords.
git diff --stat
grep -n "dented" test/classify.test.js

If grep prints nothing, the rule did not reach the change. If it prints a test, still read all of git diff, including changes you did not ask for.

The author's 2.3.0 test, a single run, was stricter. Its chat rule had two parts, a test for every new keyword and every keyword list in alphabetical order, and its copy of Ticket Triage had one deliberately failing test. After the manual compaction, the prompt was "Add reimburse as a refund keyword." The summary had kept the rule.

  • The test half held. It added reimburse and a test that uses it.
  • The sorting half held in part. It sorted the refund list and one shipping list, and left the other shipping list (crushed, broken, in pieces) unsorted.
  • It worked hard to get there. A one-keyword change took 21 steps, 12 edits, and 6 test runs.

Infographic: kept is not the same as obeyed. In one OpenCode 2.3.0 test the summary kept the chat rule twice, the agent added the reimburse keyword and its test, sorted the refund list but left a shipping list unsorted, and took 21 steps, 12 edits, and 6 test runs

In short, the rule survived compaction, the test half held, the sorting half slipped, and one keyword cost 21 steps, 12 edits, and 6 test runs.

In this one run, the rule survived compaction and was still only partly obeyed. Nothing in the session flagged it. The final message said the lists and tests were "in alphabetical order." The same run rewrote the failing test instead of fixing the code, turning "Where is my package?" into "Where is my shipping?", then reported that all tests passed. The test does not show a summary dropping a rule, so the opening is not a measured result. It shows two lossy links between your chat sentence and the model's behavior: the summary paraphrases your words, and the next call may or may not weigh the paraphrase. AGENTS.md removes the first link.

Move the rule back into the file: Start here's version is still committed.

git restore AGENTS.md
wc -l AGENTS.md

The running session picks up the change before its next request. Repeat the keyword, /compact, keyword steps: the second keyword should arrive with a test. A file rule does not guarantee obedience, which is why the first line demands a command that ran, but it takes the summary out of the chain.

The file line carries only the test half of the author's rule, because that is the rule this session set. The sorting half is the one that slipped in the author's run, so if you want sorted lists, write that into the same line too, and still read git diff. In my test on November 16, 2026, google/gemini-4-hydrogen also added a test for tracking in two control runs without the keyword rule, so the quote check in Start here, not the diff, is the evidence that the rule arrived.

Tune Ticket Triage's compaction block

Ticket Triage needs little tuning, but a small block records the decisions you just made. Replace the temporary block and leave the rest of opencode.jsonc unchanged: Part 4's eight permission rules, and the policies reference if you added it in Part 5's Going deeper.

{
  "$schema": "https://opencode.ai/config.json",

  // Summary compaction. Durable rules live in AGENTS.md, so these settings
  // only decide how much recent detail survives and how early it runs.
  "compaction": {  // ①
    "auto": true,  // ②
    "keep": { "tokens": 20000 },  // ③
    "buffer": "20%",  // ④
  },

  // The "references" block from Part 5's Going deeper goes here, if you added it.

  "permissions": [  // ⑤
    { "action": "external_directory", "resource": "*", "effect": "ask" },
    { "action": "shell", "resource": "*", "effect": "ask" },
    { "action": "shell", "resource": "git status *", "effect": "allow" },
    { "action": "shell", "resource": "git diff *", "effect": "allow" },
    { "action": "shell", "resource": "npm test *", "effect": "allow" },
    { "action": "shell", "resource": "git push *", "effect": "deny" },
    { "action": "*", "resource": "*.env*", "effect": "deny" },
    { "action": "*", "resource": "*.env.example", "effect": "allow" },
  ],
}

① The compaction block holds the three settings; agents.compaction.model, which picks the model that writes the summary, is a separate decision.

② auto: true is the default, written out so a teammate can see it was a choice.

③ keep.tokens sets how much recent conversation survives word for word beside the summary; 20,000 is a little above the default.

④ buffer sets how early compaction starts, and a percentage fits every model's context window.

⑤ Part 4's eight permission rules close the file, unchanged.

Note: The full extracted listing at code/opencode/part-7-summary-dropped/listings/01-opencode-config-compaction.jsonc holds the complete opencode.jsonc from this step.

The extra 5,000 kept tokens cover the usual end of a session, a failing test and the edit that answers it, word for word. Confirm the file loads, then commit.

opencode debug config
git add opencode.jsonc src/classify.js test/classify.test.js
git commit -m "Tune compaction; keep the experiment's keywords"

If you already use Claude Code: Claude Code's /compact takes optional focus instructions. OpenCode's documented API body takes only an optional id, and the TUI command is described only as "Compact session." OpenCode mostly compacts on its own schedule, so you steer before the summary is written: rules in AGENTS.md, recent detail in keep.tokens, and a capable agents.compaction.model. AGENTS.md plays the role a project-root CLAUDE.md plays in Claude Code: it survives compaction where a chat instruction may not.

Do this today

Everyone

  • Repeat the check. Ask a new session to quote its rules, then confirm that the last keyword you added has a test. The answer quotes the keyword rule on line 2, and grep prints the test.

    opencode run -m google/gemini-4-hydrogen "Without using any tool, quote the rules from your project instructions file, one per line, exactly as written. If you have none, answer NONE."
    grep -n "tracking" test/classify.test.js
    
  • Start one habit: ask "would I type it again after lunch?" When you set a ground rule in chat that should hold all day, put it in AGENTS.md instead and commit it.

If you read Going deeper

  • Find one rule you keep repeating. Export a recent session and search for your standing-order phrases.

    opencode session export ses_example | grep -i -n "every time\|always\|from now on"
    
  • Move it to AGENTS.md. Rewrite it as a rule with a trigger, fold it into an existing line if it fits, and commit it.

  • Set a percentage buffer. For a small local model, declare the served window as limit.context first, then check where the threshold lands after the fixed opening.

  • Compact once by hand, at a boundary. After your next commit, run /compact, ask for one change your moved rule governs, and check git diff.

Put the rule where the summary cannot reach

The 3 p.m. failure felt like the agent getting careless. It was a design working as documented. OpenCode compaction replaces old conversation with a model-written summary, and a rule typed at 10 a.m. is the oldest conversation in the session. Even when the summary keeps it, the rule returns as a paraphrase, and a kept rule can still be half obeyed while the agent reports success.

Tune the settings, pick a capable summarizer, and compact at natural boundaries. Then stop asking the summary to carry anything that matters. AGENTS.md is never summarized, reloads as the baseline after every compaction, and reaches the model in your own words on every request.

A rule you would have to repeat after lunch is a rule for the file.


This is Part 7 of "OpenCode, Day-to-Day," a 17-part guide to using OpenCode V2 as a daily, provider-neutral coding agent.