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
When a project has a large AGENTS.md (or CLAUDE.md/CONTEXT.md) file, OpenCode injects the entire file contents into the system prompt on every loop() iteration with no size guard. This makes OpenCode unusable for projects with large instruction files.
Example: A 331KB AGENTS.md (~83K tokens) consumes 81% of a 128K context window. The first turn starts at ~101K input tokens before the agent does anything, immediately triggering compaction. The session enters a compaction loop and never makes progress.
The root cause is in InstructionPrompt.system() — it reads files via Filesystem.readText() and injects the full content with zero truncation. Meanwhile, the read tool already has a 50KB cap (MAX_BYTES), so the agent can safely read large files on demand.
Related but different from #16960 (which is about losing instructions after compaction — this is about instructions causing compaction in the first place).
Steps to reproduce
Create an AGENTS.md larger than ~100KB in a project
Open the project with OpenCode using a model with 128K context
Send any message — observe compaction triggers on the first turn
The session never stabilizes because the instruction file is re-injected fresh on each iteration
Proposed fix
Add a configurable projectInstructionMaxSize field to opencode.json. When an instruction file exceeds this threshold, skip inline injection and insert a short note telling the agent to read the file on demand via the read tool (which already caps at 50KB per call).
Activity
github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.