Skip to content

[FEATURE]: Modify system prompt to improve cache hit rate #29672

@BruceXSK

Description

@BruceXSK

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

I previously submitted an issue mentioning the impact of AGENTS.md on cache hit rates. See: #29584

Additionally, I have found that the environment information and the skills list in the system prompt also affect the cache hit rate.

Currently, the environment information in the system prompt includes: model id & provider, working directory, workspace root folder, git repo flag, platform, today's date.

Below is my analysis of each field's impact on cache hits:

  • model id & provider: It only changes when switching models, and different models have different KV caches, so switching models naturally leads to cache misses. So this field is fine.
  • working directory: Once a session is created, this field does not change dynamically, and it is information the LLM needs to know.
  • platform: This field is stable, would not change during the lifetime of a session, and is also information the LLM needs to know.
  • workspace root folder & git repo flag: In my testing, in a non-git repo directory, workspace root folder is /, and git repo flag is false. While the session remains in the foreground and I run git init in that directory, neither field changes. However, once I exit opencode and resume the session after git init or rm -r .git, workspace root folder becomes the same as the working directory, and git repo flag becomes true, causing all subsequent token caches to miss.
  • today's date: After crossing midnight, this field changes, causing all subsequent token caches to miss. DeepSeek servers may keep caches on disk for several hours or even days; the cache miss caused by the date change is unnecessary.

Therefore, I suggest the following regarding the env section of the system prompt:

  • Remove workspace root folder and git repo flag. The agent can use git commands to check whether the current path is a git repo. I don't think this information needs to be in the system prompt.
  • Remove today's date. The agent can also query this using commands. I don't think this information needs to be in the system prompt either.

In addition to the modifications to the env section of the system prompt, I also suggest placing the skill list before env. Because the skill list is more stable than env (e.g., working directory), this will yield better cache hit rates when using opencode in different working paths.

Related code packages/opencode/src/session/system.ts:42-80

OpenCode version: 1.15.10

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions