Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Automatically reduces token usage in OpenCode by removing obsolete tool outputs from conversation history.

![DCP in action](dcp-demo.png)
![DCP in action](dcp-demo3.png)

## Installation

Expand Down
7 changes: 6 additions & 1 deletion lib/fetch-wrapper/formats/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export const anthropicFormat: FormatDescriptor = {
if (msg.role === 'assistant') {
// Append to existing content array
if (Array.isArray(msg.content)) {
msg.content.push({ type: 'text', text: injection })
const firstToolUseIndex = msg.content.findIndex((block: any) => block.type === 'tool_use')
if (firstToolUseIndex !== -1) {
msg.content.splice(firstToolUseIndex, 0, { type: 'text', text: injection })
} else {
msg.content.push({ type: 'text', text: injection })
}
} else if (typeof msg.content === 'string') {
// Convert string content to array format
msg.content = [
Expand Down