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
System environment prompt causes cache invalidation #5224
I've noticed that the environment() function in system.ts fetches 200 files from the current git working directory. This means that when files are added or removed in the directory, this portion of the system environment prompt is likely to change, resulting in context invalidation and increased API costs.
Here are some optimization ideas I have:
Optional solutions:
Completely remove the section of the prompt. In my testing, most models are smart enough to use the list tool to view directory files.
Retrieve the file list from git committed files, which ensures this part of the prompt remains unchanged until the user commits to the git repository.
PR #14743 fixes this — the environment block is now in a separate system block (block 2) from the stable provider prompt and global AGENTS.md (block 1). Block 1 caches independently across repos and sessions. Optionally, OPENCODE_EXPERIMENTAL_CACHE_STABILIZATION=1 also freezes the date and instruction reads for the process lifetime, giving you full hits past S1 until you restart OpenCode.
Yeah. Good find. Things are stable for now since this is disabled but I think we should just remove it. It is a trivial tool call for the LLM to get the lay of the land when needed. We shouldn't add this listing in the system block since directory contents changing is somewhat frequent in a repo/folder and that alone shouldn't invalidate any instance's prefix cache. We don't get much by having this info preloaded but lose a lot if the listing changes in the instance dir while we have an active session.
Activity
github-actions commentedon Dec 8, 2025
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
bhagirathsinh-vaghela commentedon Feb 23, 2026
PR #14743 fixes this — the environment block is now in a separate system block (block 2) from the stable provider prompt and global AGENTS.md (block 1). Block 1 caches independently across repos and sessions. Optionally,
OPENCODE_EXPERIMENTAL_CACHE_STABILIZATION=1also freezes the date and instruction reads for the process lifetime, giving you full hits past S1 until you restart OpenCode.heimoshuiyu commentedon Feb 23, 2026
Just noticed in latest dev branch https://github.com/anomalyco/opencode/blame/v1.2.10/packages/opencode/src/session/system.ts#L43 @thdxr changed this block to
project.vcs === "git" && falseWas this intentional or a typo? This always leaves an empty
<directories></directories>block in the system prompt.recent PR #11731 assume this is not empty.
bhagirathsinh-vaghela commentedon Feb 23, 2026
Yeah. Good find. Things are stable for now since this is disabled but I think we should just remove it. It is a trivial tool call for the LLM to get the lay of the land when needed. We shouldn't add this listing in the system block since directory contents changing is somewhat frequent in a repo/folder and that alone shouldn't invalidate any instance's prefix cache. We don't get much by having this info preloaded but lose a lot if the listing changes in the instance dir while we have an active session.
TomLucidor commentedon Feb 24, 2026
Ideally full cache support is what coding agent should support, I am surprised a lot of these stuff are not covered for harness/scaffolds
heimoshuiyu commentedon Apr 15, 2026
close as fixed in latest version v1.4.6