Skip to content
TypeScript

fix(claude): preview images read from the workspace (#9119)

Theo Browned0b19b32e01d
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts
index 136b01190e3..5f9a65dd675 100644
--- a/apps/mobile/src/lib/threadActivity.test.ts
+++ b/apps/mobile/src/lib/threadActivity.test.ts
@@ -504,6 +504,61 @@ describe("buildThreadFeed", () => {
);
});
+ it("keeps viewed image metadata while collapsing a streamed Claude Read", () => {
+ const turnId = TurnId.make("turn-image-read");
+ const imagePath = `/workspace/${"nested folder/".repeat(16)}reference image.webp`;
+ const thread = makeThread({
+ id: ThreadId.make("thread-image-read"),
+ projectId: ProjectId.make("project-1"),
+ title: "Image read",
+ activities: [
+ makeActivity({
+ id: EventId.make("image-read-update"),
+ kind: "tool.updated",
+ tone: "tool",
+ summary: "Image view",
+ createdAt: "2026-04-01T00:00:01.000Z",
+ turnId,
+ payload: {
+ toolCallId: "tool-read-image",
+ itemType: "image_view",
+ status: "inProgress",
+ detail: `${imagePath.slice(0, 177)}...`,
+ data: { imagePath },
+ },
+ }),
+ makeActivity({
+ id: EventId.make("image-read-completed"),
+ kind: "tool.completed",
+ tone: "tool",
+ summary: "Image view",
+ createdAt: "2026-04-01T00:00:02.000Z",
+ turnId,
+ payload: {
+ toolCallId: "tool-read-image",
+ itemType: "image_view",
+ status: "completed",
+ detail: `${imagePath.slice(0, 177)}...`,
+ data: {},
+ },
+ }),
+ ],
+ });
+
+ const group = buildThreadFeed(thread)[0];
+ expect(group).toMatchObject({
+ type: "activity-group",
+ activities: [
+ {
+ workEntry: {
+ itemType: "image_view",
+ viewedImagePath: imagePath,
+ },
+ },
+ ],
+ });
+ });
+
it("keeps MCP inputs available to expanded mobile work rows", () => {
const turnId = TurnId.make("turn-mcp");
const thread = makeThread({
diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts
index 367042448da..3047e2f5bb4 100644
--- a/apps/mobile/src/lib/threadActivity.ts
+++ b/apps/mobile/src/lib/threadActivity.ts
@@ -88,6 +88,7 @@ export interface WorkLogEntry {
turnId: TurnId | null;
label: string;
detail?: string;
+ viewedImagePath?: string;
command?: string;
rawCommand?: string;
changedFiles?: ReadonlyArray<string>;
@@ -438,6 +439,7 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
}
const itemType = extractWorkLogItemType(payload);
const requestKind = extractWorkLogRequestKind(payload);
+ const viewedImagePath = asTrimmedString(asRecord(payload?.data)?.imagePath);
if (
!taskDetailAsLabel &&
payload &&
@@ -449,6 +451,9 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
entry.detail = detail;
}
}
+ if (viewedImagePath) {
+ entry.viewedImagePath = viewedImagePath;
+ }
if (commandPreview.command) {
entry.command = commandPreview.command;
}
@@ -591,6 +596,7 @@ function mergeDerivedWorkLogEntries(
): DerivedWorkLogEntry {
const changedFiles = mergeChangedFiles(previous.changedFiles, next.changedFiles);
const detail = next.detail ?? previous.detail;
+ const viewedImagePath = next.viewedImagePath ?? previous.viewedImagePath;
const command = next.command ?? previous.command;
const rawCommand = next.rawCommand ?? previous.rawCommand;
const toolTitle = next.toolTitle ?? previous.toolTitle;
@@ -606,6 +612,7 @@ function mergeDerivedWorkLogEntries(
id: previous.id,
createdAt: previous.createdAt,
...(detail ? { detail } : {}),
+ ...(viewedImagePath ? { viewedImagePath } : {}),
...(command ? { command } : {}),
...(rawCommand ? { rawCommand } : {}),
...(changedFiles.length > 0 ? { changedFiles } : {}),
diff --git a/apps/server/src/orchestration/ActivityPayloadProjection.test.ts b/apps/server/src/orchestration/ActivityPayloadProjection.test.ts
index 18732fa4ea3..237a6f83d28 100644
--- a/apps/server/src/orchestration/ActivityPayloadProjection.test.ts
+++ b/apps/server/src/orchestration/ActivityPayloadProjection.test.ts
@@ -158,6 +158,33 @@ describe("projectActivityPayload", () => {
expect(JSON.stringify(openCode.payload).length).toBeLessThan(200);
});
+ it("keeps full Claude Read image paths through repeated projection", () => {
+ const imagePath = `/workspace/${"nested folder/".repeat(16)}reference image.webp`;
+ const projected = projectActivityPayload(
+ activity({
+ itemType: "dynamic_tool_call",
+ detail: 'Read: {"file_path":"truncated..."}',
+ data: {
+ toolName: "Read",
+ input: { file_path: imagePath },
+ result: { content: "Image Size: 1280x720." },
+ },
+ }),
+ );
+ const projectedAgain = projectActivityPayload(projected);
+
+ expect(projected.payload).toMatchObject({ data: { imagePath } });
+ expect(projectedAgain.payload).toMatchObject({ data: { imagePath } });
+
+ const textRead = projectActivityPayload(
+ activity({
+ itemType: "dynamic_tool_call",
+ data: { toolName: "Read", input: { file_path: "/workspace/src/index.ts" } },
+ }),
+ );
+ expect(textRead.payload).not.toMatchObject({ data: { imagePath: expect.anything() } });
+ });
+
it("slims Codex-shaped mcp_tool_call items to rendered fields plus a result summary", () => {
const projected = projectActivityPayload(
activity({
diff --git a/apps/server/src/orchestration/ActivityPayloadProjection.ts b/apps/server/src/orchestration/ActivityPayloadProjection.ts
index 0b1cb15d3db..5a4a3d9a275 100644
--- a/apps/server/src/orchestration/ActivityPayloadProjection.ts
+++ b/apps/server/src/orchestration/ActivityPayloadProjection.ts
@@ -3,6 +3,7 @@ import type {
OrchestrationThreadActivity,
OrchestrationThreadDetailSnapshot,
} from "@t3tools/contracts";
+import { isWorkspaceImagePreviewPath } from "@t3tools/shared/filePreview";
function asRecord(value: unknown): Record<string, unknown> | null {
return value !== null && typeof value === "object" && !Array.isArray(value)
@@ -143,6 +144,21 @@ function projectCommandValue(data: Record<string, unknown>): unknown {
return undefined;
}
+function projectViewedImagePath(data: Record<string, unknown>): string | undefined {
+ const directPath = asTrimmedString(data.imagePath);
+ if (directPath && isWorkspaceImagePreviewPath(directPath)) {
+ return directPath;
+ }
+
+ const toolName = asTrimmedString(data.toolName)?.toLowerCase();
+ if (toolName !== "read" && toolName !== "read file") {
+ return undefined;
+ }
+ const input = asRecord(data.input);
+ const inputPath = asTrimmedString(input?.file_path) ?? asTrimmedString(input?.path);
+ return inputPath && isWorkspaceImagePreviewPath(inputPath) ? inputPath : undefined;
+}
+
function summarizeToolTextOutput(value: string): string | null {
let meaningfulLineCount = 0;
let offset = 0;
@@ -374,6 +390,10 @@ export function projectActivityPayload(
if (command !== undefined) {
projectedData.command = command;
}
+ const imagePath = projectViewedImagePath(data);
+ if (imagePath) {
+ projectedData.imagePath = imagePath;
+ }
const changedFiles: string[] = [];
collectChangedFiles(data, changedFiles, new Set<string>(), 0);
diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts b/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
index d629394acad..759a1641093 100644
--- a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
+++ b/apps/server/src/provider/Layers/ClaudeAdapter.test.ts
@@ -46,6 +46,7 @@ import { ProviderAdapterProcessError, ProviderAdapterValidationError } from "../
import type { ClaudeAdapterShape } from "../Services/ClaudeAdapter.ts";
import { makeClaudeAdapter, type ClaudeAdapterLiveOptions } from "./ClaudeAdapter.ts";
const decodeClaudeSettings = Schema.decodeSync(ClaudeSettings);
+const encodeUnknownJsonString = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
// Test-local service tag so the rest of the file can keep using `yield* ClaudeAdapter`.
class ClaudeAdapter extends Context.Service<ClaudeAdapter, ClaudeAdapterShape>()(
@@ -1434,6 +1435,167 @@ describe("ClaudeAdapterLive", () => {
);
});
+ it.effect("classifies only streamed Read image inputs as image views", () => {
+ const harness = makeHarness();
+ return Effect.gen(function* () {
+ const adapter = yield* ClaudeAdapter;
+ const runtimeEventsFiber = yield* Stream.takeUntil(
+ adapter.streamEvents,
+ (event) => event.type === "turn.completed",
+ ).pipe(Stream.runCollect, Effect.forkChild);
+
+ const session = yield* adapter.startSession({
+ threadId: THREAD_ID,
+ provider: ProviderDriverKind.make("claudeAgent"),
+ runtimeMode: "full-access",
+ });
+ yield* adapter.sendTurn({
+ threadId: session.threadId,
+ input: "inspect both files",
+ attachments: [],
+ });
+
+ const imagePath = `/workspace/${"nested folder/".repeat(16)}reference image.webp`;
+ harness.query.emit({
+ type: "stream_event",
+ session_id: "sdk-session-read-image",
+ uuid: "read-image-start",
+ parent_tool_use_id: null,
+ event: {
+ type: "content_block_start",
+ index: 0,
+ content_block: {
+ type: "tool_use",
+ id: "tool-read-image",
+ name: "Read",
+ input: {},
+ },
+ },
+ } as unknown as SDKMessage);
+ harness.query.emit({
+ type: "stream_event",
+ session_id: "sdk-session-read-image",
+ uuid: "read-image-input",
+ parent_tool_use_id: null,
+ event: {
+ type: "content_block_delta",
+ index: 0,
+ delta: {
+ type: "input_json_delta",
+ partial_json: encodeUnknownJsonString({ file_path: imagePath }),
+ },
+ },
+ } as unknown as SDKMessage);
+ harness.query.emit({
+ type: "user",
+ session_id: "sdk-session-read-image",
+ uuid: "read-image-result",
+ parent_tool_use_id: null,
+ message: {
+ role: "user",
+ content: [
+ {
+ type: "tool_result",
+ tool_use_id: "tool-read-image",
+ content: "Image Size: 1280x720.",
+ },
+ ],
+ },
+ } as unknown as SDKMessage);
+
+ harness.query.emit({
+ type: "stream_event",
+ session_id: "sdk-session-read-image",
+ uuid: "read-text-start",
+ parent_tool_use_id: null,
+ event: {
+ type: "content_block_start",
+ index: 1,
+ content_block: {
+ type: "tool_use",
+ id: "tool-read-text",
+ name: "Read",
+ input: { file_path: "/workspace/src/index.ts" },
+ },
+ },
+ } as unknown as SDKMessage);
+ harness.query.emit({
+ type: "user",
+ session_id: "sdk-session-read-image",
+ uuid: "read-text-result",
+ parent_tool_use_id: null,
+ message: {
+ role: "user",
+ content: [
+ {
+ type: "tool_result",
+ tool_use_id: "tool-read-text",
+ content: "export {};",
+ },
+ ],
+ },
+ } as unknown as SDKMessage);
+ harness.query.emit({
+ type: "result",
+ subtype: "success",
+ is_error: false,
+ errors: [],
+ session_id: "sdk-session-read-image",
+ uuid: "read-image-turn-result",
+ } as unknown as SDKMessage);
+
+ const runtimeEvents = Array.from(yield* Fiber.join(runtimeEventsFiber));
+ const imageEvents = runtimeEvents.filter(
+ (
+ event,
+ ): event is Extract<
+ ProviderRuntimeEvent,
+ { type: "item.started" | "item.updated" | "item.completed" }
+ > =>
+ (event.type === "item.started" ||
+ event.type === "item.updated" ||
+ event.type === "item.completed") &&
+ String(event.itemId) === "tool-read-image",
+ );
+ assert.deepEqual(
+ imageEvents.map((event) => [event.type, event.payload.itemType]),
+ [
+ ["item.started", "dynamic_tool_call"],
+ ["item.updated", "image_view"],
+ ["item.updated", "image_view"],
+ ["item.completed", "image_view"],
+ ],
+ );
+ for (const event of imageEvents.slice(1)) {
+ assert.equal(event.payload.detail, imagePath);
+ assert.equal(
+ (event.payload.data as { input?: { file_path?: string } } | undefined)?.input?.file_path,
+ imagePath,
+ );
+ }
+
+ const textEvents = runtimeEvents.filter(
+ (
+ event,
+ ): event is Extract<
+ ProviderRuntimeEvent,
+ { type: "item.started" | "item.updated" | "item.completed" }
+ > =>
+ (event.type === "item.started" ||
+ event.type === "item.updated" ||
+ event.type === "item.completed") &&
+ String(event.itemId) === "tool-read-text",
+ );
+ assert.deepEqual(
+ textEvents.map((event) => event.payload.itemType),
+ ["dynamic_tool_call", "dynamic_tool_call", "dynamic_tool_call"],
+ );
+ }).pipe(
+ Effect.provideService(Random.Random, makeDeterministicRandomService()),
+ Effect.provide(harness.layer),
+ );
+ });
+
it.effect("falls back to a default plan step label for blank TodoWrite content", () => {
const harness = makeHarness();
return Effect.gen(function* () {
diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.ts b/apps/server/src/provider/Layers/ClaudeAdapter.ts
index c0e24231643..07739146b07 100644
--- a/apps/server/src/provider/Layers/ClaudeAdapter.ts
+++ b/apps/server/src/provider/Layers/ClaudeAdapter.ts
@@ -20,6 +20,7 @@ import {
type ModelUsage,
} from "@anthropic-ai/claude-agent-sdk";
import { parseCliArgs } from "@t3tools/shared/cliArgs";
+import { isWorkspaceImagePreviewPath } from "@t3tools/shared/filePreview";
import {
ApprovalRequestId,
type CanonicalItemType,
@@ -713,8 +714,27 @@ function readClaudeResumeState(resumeCursor: unknown): ClaudeResumeState | undef
};
}
-function classifyToolItemType(toolName: string): CanonicalItemType {
+function readToolImagePath(toolName: string, input: Record<string, unknown>): string | undefined {
+ const normalized = toolName.trim().toLowerCase();
+ if (normalized !== "read" && normalized !== "read file") {
+ return undefined;
+ }
+ const pathValue = input.file_path ?? input.path;
+ if (typeof pathValue !== "string") {
+ return undefined;
+ }
+ const path = pathValue.trim();
+ return path.length > 0 && isWorkspaceImagePreviewPath(path) ? path : undefined;
+}
+
+function classifyToolItemType(
+ toolName: string,
+ input: Record<string, unknown> = {},
+): CanonicalItemType {
const normalized = toolName.toLowerCase();
+ if (readToolImagePath(toolName, input)) {
+ return "image_view";
+ }
if (normalized.includes("agent")) {
return "collab_agent_tool_call";
}
@@ -1166,6 +1186,11 @@ function workflowAgentStatus(entry: ClaudeWorkflowAgentEntry): RuntimeTaskStatus
}
function summarizeToolRequest(toolName: string, input: Record<string, unknown>): string {
+ const imagePath = readToolImagePath(toolName, input);
+ if (imagePath) {
+ return imagePath;
+ }
+
const commandValue = input.command ?? input.cmd;
const command = typeof commandValue === "string" ? commandValue : undefined;
if (command && command.trim().length > 0) {
@@ -2529,9 +2554,14 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
const partialInputJson = tool.partialInputJson + event.delta.partial_json;
const parsedInput = tryParseJsonRecord(partialInputJson);
+ const itemType = parsedInput
+ ? classifyToolItemType(tool.toolName, parsedInput)
+ : tool.itemType;
const detail = parsedInput ? summarizeToolRequest(tool.toolName, parsedInput) : tool.detail;
let nextTool: ToolInFlight = {
...tool,
+ itemType,
+ title: titleForTool(itemType),
partialInputJson,
...(parsedInput ? { input: parsedInput } : {}),
...(detail ? { detail } : {}),
@@ -2636,11 +2666,11 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
}
const toolName = block.name;
- const itemType = classifyToolItemType(toolName);
const toolInput =
typeof block.input === "object" && block.input !== null
? (block.input as Record<string, unknown>)
: {};
+ const itemType = classifyToolItemType(toolName, toolInput);
const itemId = block.id;
const detail = summarizeToolRequest(toolName, toolInput);
const inputFingerprint =
diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts
index dc32f84b1e5..a0d24d78adf 100644
--- a/apps/web/src/session-logic.test.ts
+++ b/apps/web/src/session-logic.test.ts
@@ -1653,6 +1653,44 @@ describe("deriveWorkLogEntries", () => {
});
});
+ it("keeps viewed image metadata while collapsing a streamed Claude Read", () => {
+ const imagePath = `/workspace/${"nested folder/".repeat(16)}reference image.webp`;
+ const activities: OrchestrationThreadActivity[] = [
+ makeActivity({
+ id: "image-read-update",
+ createdAt: "2026-02-23T00:00:01.000Z",
+ kind: "tool.updated",
+ summary: "Image view",
+ payload: {
+ toolCallId: "tool-read-image",
+ itemType: "image_view",
+ detail: `${imagePath.slice(0, 177)}...`,
+ data: { imagePath },
+ },
+ }),
+ makeActivity({
+ id: "image-read-complete",
+ createdAt: "2026-02-23T00:00:02.000Z",
+ kind: "tool.completed",
+ summary: "Image view",
+ payload: {
+ toolCallId: "tool-read-image",
+ itemType: "image_view",
+ detail: `${imagePath.slice(0, 177)}...`,
+ data: {},
+ },
+ }),
+ ];
+
+ const entries = deriveWorkLogEntries(activities);
+ expect(entries).toHaveLength(1);
+ expect(entries[0]).toMatchObject({
+ id: "image-read-complete",
+ itemType: "image_view",
+ viewedImagePath: imagePath,
+ });
+ });
+
it("does not use command stdout as the detail when Cursor omits the command input", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts
index 6d853dc3ea1..519f888ee52 100644
--- a/apps/web/src/session-logic.ts
+++ b/apps/web/src/session-logic.ts
@@ -73,6 +73,7 @@ export interface WorkLogEntry {
toolCallId?: string;
label: string;
detail?: string;
+ viewedImagePath?: string;
command?: string;
rawCommand?: string;
changedFiles?: ReadonlyArray<string>;
@@ -924,9 +925,13 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
};
const itemType = extractWorkLogItemType(payload);
const requestKind = extractWorkLogRequestKind(payload);
+ const viewedImagePath = asTrimmedString(asRecord(payload?.data)?.imagePath);
if (detail) {
entry.detail = detail;
}
+ if (viewedImagePath) {
+ entry.viewedImagePath = viewedImagePath;
+ }
if (commandPreview.command) {
entry.command = commandPreview.command;
}
@@ -1156,6 +1161,7 @@ function mergeDerivedWorkLogEntries(
): DerivedWorkLogEntry {
const changedFiles = mergeChangedFiles(previous.changedFiles, next.changedFiles);
const detail = next.detail ?? previous.detail;
+ const viewedImagePath = next.viewedImagePath ?? previous.viewedImagePath;
const command = next.command ?? previous.command;
const rawCommand = next.rawCommand ?? previous.rawCommand;
const toolTitle = next.toolTitle ?? previous.toolTitle;
@@ -1169,6 +1175,7 @@ function mergeDerivedWorkLogEntries(
...previous,
...next,
...(detail ? { detail } : {}),
+ ...(viewedImagePath ? { viewedImagePath } : {}),
...(command ? { command } : {}),
...(rawCommand ? { rawCommand } : {}),
...(changedFiles.length > 0 ? { changedFiles } : {}),
diff --git a/packages/client-runtime/src/work-log/presentation.test.ts b/packages/client-runtime/src/work-log/presentation.test.ts
index b4abd4c4019..1d2cedee544 100644
--- a/packages/client-runtime/src/work-log/presentation.test.ts
+++ b/packages/client-runtime/src/work-log/presentation.test.ts
@@ -2,7 +2,11 @@ import { describe, expect, it } from "vite-plus/test";
import { ThreadId } from "@t3tools/contracts";
-import { resolveViewedImageAsset, workEntryViewedImagePath } from "./presentation.js";
+import {
+ resolveViewedImageAsset,
+ toolGroupAction,
+ workEntryViewedImagePath,
+} from "./presentation.js";
describe("workEntryViewedImagePath", () => {
const entry = { label: "Read", tone: "tool" } as const;
@@ -19,6 +23,14 @@ describe("workEntryViewedImagePath", () => {
detail: "C:\\workspace\\a.webp",
}),
).toBe("C:\\workspace\\a.webp");
+ expect(
+ workEntryViewedImagePath({
+ ...entry,
+ itemType: "dynamic_tool_call",
+ detail: 'Read: {"file_path":"truncated..."}',
+ viewedImagePath: " /workspace/reference image.webp ",
+ }),
+ ).toBe("/workspace/reference image.webp");
});
it("rejects non-image, multi-line, and non-read details", () => {
@@ -32,6 +44,19 @@ describe("workEntryViewedImagePath", () => {
});
});
+describe("toolGroupAction", () => {
+ it("groups legacy Claude image reads with other reads", () => {
+ expect(
+ toolGroupAction({
+ label: "Tool call",
+ tone: "tool",
+ itemType: "dynamic_tool_call",
+ viewedImagePath: "/workspace/reference.png",
+ }),
+ ).toBe("read");
+ });
+});
+
describe("resolveViewedImageAsset", () => {
const threadId = ThreadId.make("thread-1");
diff --git a/packages/client-runtime/src/work-log/presentation.ts b/packages/client-runtime/src/work-log/presentation.ts
index 2d5e6ebfc86..f1334754c72 100644
--- a/packages/client-runtime/src/work-log/presentation.ts
+++ b/packages/client-runtime/src/work-log/presentation.ts
@@ -20,6 +20,7 @@ export interface WorkLogPresentationEntry {
readonly tone: "thinking" | "tool" | "info" | "error";
readonly command?: string;
readonly detail?: string;
+ readonly viewedImagePath?: string;
readonly changedFiles?: ReadonlyArray<string>;
readonly itemType?: ToolLifecycleItemType;
readonly requestKind?: string;
@@ -68,6 +69,7 @@ export function toolGroupAction(entry: WorkLogPresentationEntry): ToolGroupActio
if (
entry.requestKind === "file-read" ||
entry.itemType === "image_view" ||
+ entry.viewedImagePath !== undefined ||
(entry.itemType === "dynamic_tool_call" &&
entry.toolTitle?.trim().toLowerCase() === "read file")
) {
@@ -89,6 +91,14 @@ export function toolGroupAction(entry: WorkLogPresentationEntry): ToolGroupActio
}
export function workEntryViewedImagePath(entry: WorkLogPresentationEntry): string | null {
+ const viewedImagePath = entry.viewedImagePath?.trim();
+ if (
+ viewedImagePath !== undefined &&
+ !/[\r\n]/.test(viewedImagePath) &&
+ isWorkspaceImagePreviewPath(viewedImagePath)
+ ) {
+ return viewedImagePath;
+ }
const detail = entry.detail?.trim();
return toolGroupAction(entry) === "read" &&
detail !== undefined &&