You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Title OpenCode session can explode into thousands of assistant messages and massive token usage without effective context/loop limits #43028
Title OpenCode session can explode into thousands of assistant messages and massive token usage without effective context/loop limits
Body
Summary
I found a severe session growth issue in OpenCode: a single session can continue generating assistant messages in a loop, reaching thousands of messages and hundreds of millions of tokens, even though the user only sent a few prompts.
Evidence
From local OpenCode DB inspection:
Session ID: ses_0008cf681ffe5kvHzVbP1ngPxZ
Title: 询问模型身份
Directory: /home/server/xkw-logger
Tokens:
input=187,625,605
cache_read=278,806,144
output=92,342
reasoning=44,571
total 466,568,662
Message counts:
user=26
assistant=2253
total 2279
Parts: 7216
Events: 21504
The last part of the session shows repeated assistant messages every ~10-20 seconds, with each message reading roughly 251k cached tokens.
Observed behavior
A single session keeps growing for days.
Assistant messages accumulate far beyond user messages.
The same user node can end up with thousands of assistant children.
There is no obvious hard stop on steps / turns / tool calls / compaction.
Expected behavior
OpenCode should enforce stronger bounds on runaway sessions.
Long sessions should compact or stop before reaching extreme message/token counts.
There should be a safeguard against repeated assistant loops in one session.
If an agent is stuck in a loop, it should be aborted or surfaced clearly.
Actual behavior
The session continues producing assistant messages repeatedly.
Token usage and event count grow massively.
The session becomes extremely expensive and hard to recover.
Config check
I also checked /root/.config/opencode/opencode.jsonc, and there were no obvious limits configured such as:
maxSteps
maxTurns
maxToolCalls
autoCompact
compact
history
context
maxTokens
maxOutputTokens
Additional notes
This looks like either:
missing built-in safety limits for long-running sessions, or
a bug in loop/compaction handling that allows one session to keep spawning assistant steps indefinitely.
If helpful, I can also provide:
a shorter bug report version
an English version
a reproduction-focused version
The issue title appears to include the word "Title" at the start — please remove it so the title reads: "OpenCode session can explode into thousands of assistant messages and massive token usage without effective context/loop limits"
OpenCode version is missing (_No response_) — please provide the exact version you were using
Steps to reproduce is empty — even a general description like "run a long session with tool-calling enabled" helps narrow down the root cause
Operating System and Terminal fields are empty — these help rule out environment-specific factors
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
Activity
github-actions commentedon Aug 17, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
_No response_) — please provide the exact version you were usingPlease edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
If you believe this was flagged incorrectly, please let a maintainer know.
github-actions commentedon Aug 17, 2026
This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.
Feel free to open a new issue that follows our issue templates.