Skip to content

System environment prompt causes cache invalidation #5224

Closed

Description

@heimoshuiyu

Question

In https://github.com/sst/opencode/blob/v1.0.134/packages/opencode/src/session/system.ts#L49

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:

  1. Completely remove the section of the prompt. In my testing, most models are smart enough to use the list tool to view directory files.

  2. 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.

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 8, 2025
  2. github-actions commented on Dec 8, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  3. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Dec 8, 2025
  4. bhagirathsinh-vaghela commented on Feb 23, 2026

    @bhagirathsinh-vaghela

    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.

  5. heimoshuiyu commented on Feb 23, 2026

    @heimoshuiyu
    ContributorAuthor

    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" && false
    Was 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.

  6. bhagirathsinh-vaghela commented on Feb 23, 2026

    @bhagirathsinh-vaghela

    Just noticed in latest dev branch @thdxr change this block to project.vcs === "git" && false Was this intentional or a typo? This leaves an empty <directory></directory> block in the system prompt. https://github.com/anomalyco/opencode/blame/dev/packages/opencode/src/session/system.ts#L49

    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.

  7. TomLucidor commented on Feb 24, 2026

    @TomLucidor

    Ideally full cache support is what coding agent should support, I am surprised a lot of these stuff are not covered for harness/scaffolds

  8. heimoshuiyu commented on Apr 15, 2026

    @heimoshuiyu
    ContributorAuthor

    close as fixed in latest version v1.4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions