Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(claude): preserve thinking text in run transcripts (#10517)

pseudoyue8f389d92bb4
diff --git a/server/pkg/agent/claude.go b/server/pkg/agent/claude.go
index 358f94d59c..1232489226 100644
--- a/server/pkg/agent/claude.go
+++ b/server/pkg/agent/claude.go
@@ -576,8 +576,8 @@ func (b *claudeBackend) handleAssistant(msg claudeSDKMessage, ch chan<- Message,
trySend(ch, Message{Type: MessageText, Content: block.Text})
}
case "thinking":
- if block.Text != "" {
- trySend(ch, Message{Type: MessageThinking, Content: block.Text})
+ if block.Thinking != "" {
+ trySend(ch, Message{Type: MessageThinking, Content: block.Thinking})
}
case "tool_use":
toolUseCount++
@@ -1114,6 +1114,7 @@ func claudeUsageHasTokens(input, output, cacheRead, cacheWrite int64) bool {
type claudeContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
+ Thinking string `json:"thinking,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
diff --git a/server/pkg/agent/claude_test.go b/server/pkg/agent/claude_test.go
index cb794797a5..6fddf39ac5 100644
--- a/server/pkg/agent/claude_test.go
+++ b/server/pkg/agent/claude_test.go
@@ -7,6 +7,7 @@ import (
"log/slog"
"os"
"path/filepath"
+ "reflect"
"runtime"
"slices"
"strings"
@@ -49,6 +50,76 @@ func TestClaudeHandleAssistantText(t *testing.T) {
}
}
+func TestClaudeExecuteThinking(t *testing.T) {
+ t.Parallel()
+
+ for _, tt := range []struct {
+ name string
+ content string
+ want []Message
+ }{
+ {
+ name: "thinking stays in order with text and tools",
+ content: `[
+ {"type":"text","text":"Checking the fixture."},
+ {"type":"thinking","thinking":"Compare the fixture with the expected value.","signature":"fixture-signature"},
+ {"type":"tool_use","id":"tool_read","name":"Read","input":{"file_path":"fixture.txt"}},
+ {"type":"text","text":"The fixture matches."}
+ ]`,
+ want: []Message{
+ {Type: MessageText, Content: "Checking the fixture."},
+ {Type: MessageThinking, Content: "Compare the fixture with the expected value."},
+ {Type: MessageToolUse, CallID: "tool_read", Tool: "Read", Input: map[string]any{"file_path": "fixture.txt"}},
+ {Type: MessageText, Content: "The fixture matches."},
+ },
+ },
+ {
+ name: "empty and signature-only thinking stay silent",
+ content: `[
+ {"type":"thinking","thinking":"","signature":"fixture-signature"},
+ {"type":"thinking","signature":"fixture-signature"},
+ {"type":"text","text":"The fixture matches."}
+ ]`,
+ want: []Message{{Type: MessageText, Content: "The fixture matches."}},
+ },
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Parallel()
+ event := mustMarshal(t, map[string]any{
+ "type": "assistant",
+ "message": map[string]any{
+ "id": "msg_thinking", "role": "assistant", "content": json.RawMessage(tt.content),
+ },
+ })
+ terminal := json.RawMessage(`{"type":"result","subtype":"success","result":"The fixture matches.","modelUsage":{"claude-sonnet-4-6":{"inputTokens":3,"outputTokens":5}}}`)
+ backend := claudeUsageFixtureBackend(t, []json.RawMessage{event}, terminal, false)
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+ session, err := backend.Execute(ctx, "fixture", ExecOptions{Timeout: 5 * time.Second})
+ if err != nil {
+ t.Fatal(err)
+ }
+ var got []Message
+ for message := range session.Messages {
+ switch message.Type {
+ case MessageText, MessageThinking, MessageToolUse:
+ got = append(got, message)
+ }
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("transcript = %#v, want %#v", got, tt.want)
+ }
+ result, ok := <-session.Result
+ if !ok || result.Status != "completed" || result.Output != "The fixture matches." {
+ t.Fatalf("result = %+v (present=%v), want completed with only the final answer", result, ok)
+ }
+ if got := result.Usage["claude-sonnet-4-6"]; got != (TokenUsage{InputTokens: 3, OutputTokens: 5}) {
+ t.Errorf("usage = %+v, want 3 input / 5 output", got)
+ }
+ })
+ }
+}
+
func TestClaudeHandleAssistantToolUse(t *testing.T) {
t.Parallel()