System environment prompt causes cache invalidation #3391

Open
opened 2026-02-16 17:39:55 -05:00 by yindo · 1 comment
Owner

Originally created by @heimoshuiyu on GitHub (Dec 8, 2025).

Originally assigned to: @thdxr on GitHub.

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.

Originally created by @heimoshuiyu on GitHub (Dec 8, 2025). Originally assigned to: @thdxr on GitHub. ### 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 <files></files> 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.
Author
Owner

@github-actions[bot] commented on GitHub (Dec 8, 2025):

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

  • #2541: Make the directory listing limit configurable in the system prompt (addresses the same concern about the file listing in the system prompt)
  • #5005: unexpected system prompt parts despite disabling default agent(s) (related to system prompt optimization and control)
  • #3182: Very slow session due to 98GB of git snapshots (related to context invalidation and increased API costs from changing environment data)
  • #3176: Why is OpenCode massively abusing git? (related to git file handling and performance impact)

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

@github-actions[bot] commented on GitHub (Dec 8, 2025): This issue might be a duplicate of existing issues. Please check: - #2541: Make the directory listing limit configurable in the system prompt (addresses the same concern about the file listing in the system prompt) - #5005: unexpected system prompt parts despite disabling default agent(s) (related to system prompt optimization and control) - #3182: Very slow session due to 98GB of git snapshots (related to context invalidation and increased API costs from changing environment data) - #3176: Why is OpenCode massively abusing git? (related to git file handling and performance impact) Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3391