Skip to content

Anthropic prompt caching misses when dynamic user.system is merged into the static prefix #20110

@parappally

Description

@parappally

Summary

Anthropic prompt caching misses when OpenCode merges the session-static system prompt with per-turn user.system content before the request is built.

Problem

packages/opencode/src/session/llm.ts currently joins the static OpenCode system prefix with dynamic caller-provided user.system text into one system message. For Anthropic-style caching, that makes the cached system prefix change on every follow-up turn.

Expected behavior

The static OpenCode prefix should stay in its own system message so it can remain cache-stable across turns, while dynamic user.system content can vary independently.

Scope

A minimal fix would keep the static prefix as the first system message, move dynamic user.system content into a second system message, and keep plugin-added system fragments collapsed back into the trailing slot.

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

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