r/opencodeCLI • • 15h ago

Why does OpenCode sometimes forget things from the same session?

I've been using OpenCode to work on some testnet tasks. I asked the agent to create a separate wallet specifically for testnet activities.

At first, everything worked fine. It created the wallet, claimed faucet tokens, and even made some transactions.

But at some point, while I was still in the same session, the agent seemed to forget that it had already created the wallet.

I had to ask it to scan the files on my VPS just to find the wallet again.

I'm a bit confused about why this happens. If I'm still using the same session, shouldn't it remember what it did earlier?

Could this be related to context limits, context compaction, or something else?

Has anyone experienced something similar? How do you usually handle this when working on longer tasks?

1 Upvotes

2 comments sorted by

1

u/AdventurousItem4635 14h ago

Yeah that's compaction. When the session gets close to the model's context limit OpenCode summarizes the older part of the conversation and keeps going from the summary, and details like which wallet it made or where it saved the keyfile often don't make it into that summary. Old tool outputs can get cleared too, so the command output that had the address is gone.

On anything long I have it write that kind of state to a file in the project, AGENTS.md or just a notes file with the wallet path and address, and tell it to check there first. Then it doesn't matter what got summarized.

1

u/SirRobinBlibs 2h ago

That's compaction. When the context fills up, OpenCode replaces older history with a summary, and small concrete details like a wallet address or a key path are exactly what summaries drop. What works: keep a short STATE.md with the facts that must survive, and tell the agent in AGENTS.md to read it at the start and update it after any step that creates something. AGENTS.md goes into the initial instructions rather than the chat history, so it isn't summarized away. You can also keep more recent context through compaction with "compaction": { "keep": { "tokens": ... } } in opencode.json. Just the key path in the file, never the key itself.