[PR #10380] fix: add prompt caching to session compaction - Issue #10342 #13425

Open
opened 2026-02-16 18:18:17 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10380

State: open
Merged: No


Problem

Session compaction sent an empty system: [] array, missing the ~90% cost savings from prompt caching.

Solution

Added system prompts to compaction processor:

import { SystemPrompt } from "./system"

// Changed from:
system: [],

// To:
system: [...(await SystemPrompt.environment()), ...(await SystemPrompt.custom())],

Impact

  • Cost Savings: Enables ~90% reduction in compaction API costs through cached system prompts
  • Consistency: Compaction now uses the same system prompts as regular loops

Technical Details

The SystemPrompt.environment() and SystemPrompt.custom() methods return prompts that support Claude's prompt caching feature:

  • Environment prompts (project context, tool definitions, etc.)
  • Custom prompts (user-defined instructions)

Testing

  • Verified with existing test suite (752/759 tests passing)
  • Confirmed system prompts are now included in compaction requests

Fixes #10342 - Major cost optimization for long sessions

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10380 **State:** open **Merged:** No --- ## Problem Session compaction sent an empty `system: []` array, missing the ~90% cost savings from prompt caching. ## Solution Added system prompts to compaction processor: ```typescript import { SystemPrompt } from "./system" // Changed from: system: [], // To: system: [...(await SystemPrompt.environment()), ...(await SystemPrompt.custom())], ``` ## Impact - **Cost Savings**: Enables ~90% reduction in compaction API costs through cached system prompts - **Consistency**: Compaction now uses the same system prompts as regular loops ## Technical Details The `SystemPrompt.environment()` and `SystemPrompt.custom()` methods return prompts that support Claude's prompt caching feature: - Environment prompts (project context, tool definitions, etc.) - Custom prompts (user-defined instructions) ## Testing - Verified with existing test suite (752/759 tests passing) - Confirmed system prompts are now included in compaction requests Fixes #10342 - Major cost optimization for long sessions
yindo added the pull-request label 2026-02-16 18:18:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13425