The best way to control Claude Code, Codex and more from any computer or phone
fix(server): Claude text generation sends attached images (#38619)
Julius Marminge committed
Nov 18, 2026 at 06:03 UTC
9415a2e52d0e3ec8103d8e0c6a7e5383c1e54f7c
2 files changed
+97
-4
apps/server/src/textGeneration/ClaudeTextGeneration.test.ts
+39
@@ -229,6 +229,45 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
229
),
230
);
231
232
+ it.effect("sends image attachments to Claude, not only their metadata", () =>
233
+ withFakeClaudeEnv(
234
+ {
235
+ output: JSON.stringify({ structured_output: { branch: "fix/login-button" } }),
236
+ stdinMustContain: Buffer.from("hello").toString("base64"),
237
+ },
238
+ (textGeneration) =>
239
+ Effect.gen(function* () {
240
+ const fs = yield* FileSystem.FileSystem;
241
+ const path = yield* Path.Path;
242
+ const { attachmentsDir } = yield* ServerConfig.ServerConfig;
243
+ const attachmentId = "thread-1-claude-attachment";
244
+ const imagePath = path.join(attachmentsDir, `${attachmentId}.png`);
245
+ yield* fs.makeDirectory(attachmentsDir, { recursive: true });
246
+ yield* fs.writeFile(imagePath, Buffer.from("hello"));
247
+
248
+ yield* textGeneration
249
+ .generateBranchName({
250
+ cwd: process.cwd(),
251
+ message: "fix this",
252
+ attachments: [
253
+ {
254
+ type: "image",
255
+ id: attachmentId,
256
+ name: "screen.png",
257
+ mimeType: "image/png",
258
+ sizeBytes: 5,
259
+ },
260
+ ],
261
+ modelSelection: {
262
+ instanceId: ProviderInstanceId.make("claudeAgent"),
263
+ model: SYNTHETIC_CLAUDE_STANDARD_MODEL,
264
+ },
265
+ })
266
+ .pipe(Effect.ensuring(fs.remove(imagePath).pipe(Effect.ignore)));
267
+ }),
268
+ ),
269
+ );
270
+
271
it.effect("runs Claude text generation with the configured CLAUDE_CONFIG_DIR", () =>
272
Effect.gen(function* () {
273
const path = yield* Path.Path;
apps/server/src/textGeneration/ClaudeTextGeneration.ts
+58
-4
@@ -35,6 +35,8 @@ import {
35
makeClaudeEnvironment,
36
} from "../provider/Drivers/ClaudeHome.ts";
37
import { readClaudeLaunchArgSettings } from "../orchestration-v2/Adapters/ClaudeAdapterV2.ts";
38
+import { resolveAttachmentPath } from "../attachmentStore.ts";
39
+import * as ServerConfig from "../config.ts";
40
41
const CLAUDE_TIMEOUT_MS = 180_000;
42
/** `--tools` takes bare names; patterns go in the allow list. */
@@ -108,6 +110,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
110
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
111
const fileSystem = yield* FileSystem.FileSystem;
112
const path = yield* Path.Path;
113
+ const serverConfig = yield* ServerConfig.ServerConfig;
114
const claudeEnvironment = yield* makeClaudeEnvironment(claudeSettings, environment);
115
const scopedModelCatalog = modelCatalog.pipe(
116
Effect.map((catalog) => scopeClaudeModelCatalog(catalog, claudeSettings.customModels)),
@@ -144,6 +147,36 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
147
),
148
);
149
150
+ const readImageBlocks = Effect.fn("readImageBlocks")(function* (
151
+ attachments: TextGenerationOperations.Request<Schema.Top>["attachments"],
152
+ ) {
153
+ const blocks: Array<{
154
+ type: "image";
155
+ source: { type: "base64"; media_type: string; data: string };
156
+ }> = [];
157
+ for (const attachment of attachments ?? []) {
158
+ if (attachment.type !== "image") continue;
159
+ const attachmentPath = resolveAttachmentPath({
160
+ attachmentsDir: serverConfig.attachmentsDir,
161
+ attachment,
162
+ });
163
+ if (!attachmentPath) continue;
164
+ const bytes = yield* fileSystem
165
+ .readFile(attachmentPath)
166
+ .pipe(Effect.orElseSucceed(() => null));
167
+ if (!bytes) continue;
168
+ blocks.push({
169
+ type: "image",
170
+ source: {
171
+ type: "base64",
172
+ media_type: attachment.mimeType,
173
+ data: Buffer.from(bytes).toString("base64"),
174
+ },
175
+ });
176
+ }
177
+ return blocks;
178
+ });
179
+
180
const runClaudeJson = Effect.fn("runClaudeJson")(function* <S extends Schema.Top>({
181
operation,
182
cwd,
@@ -151,6 +184,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
184
outputSchema: outputSchemaJson,
185
modelSelection,
186
investigate,
187
+ attachments,
188
}: TextGenerationOperations.Request<S>): Effect.fn.Return<
189
S["Type"],
190
TextGenerationError,
@@ -226,6 +260,20 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
260
"Failed to encode Claude CLI settings.",
261
);
262
263
+ // `claude -p` accepts images only as content blocks of a stream-json user message.
264
+ const imageBlocks = yield* readImageBlocks(attachments);
265
+ const streamJson = imageBlocks.length > 0;
266
+ const stdin = streamJson
267
+ ? `${yield* encodeJsonForOperation(
268
+ operation,
269
+ {
270
+ type: "user",
271
+ message: { role: "user", content: [{ type: "text", text: prompt }, ...imageBlocks] },
272
+ },
273
+ "Failed to encode Claude CLI input.",
274
+ )}\n`
275
+ : prompt;
276
+
277
const runClaudeCommand = Effect.fn("runClaudeJson.runClaudeCommand")(function* (
278
noSessionPersistence: boolean,
279
) {
@@ -234,8 +282,9 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
282
claudeSettings.binaryPath || "claude",
283
[
284
"-p",
237
- "--output-format",
238
- "json",
285
+ ...(streamJson
286
+ ? ["--input-format", "stream-json", "--output-format", "stream-json", "--verbose"]
287
+ : ["--output-format", "json"]),
288
"--json-schema",
289
jsonSchemaStr,
290
"--model",
@@ -268,7 +317,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
317
cwd: workingDirectory,
318
shell: spawnCommand.shell,
319
stdin: {
271
- stream: Stream.encodeText(Stream.make(prompt)),
320
+ stream: Stream.encodeText(Stream.make(stdin)),
321
},
322
forceKillAfter: "1 second",
323
});
@@ -294,7 +343,12 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
343
{ concurrency: "unbounded" },
344
);
345
297
- return { stdout, stderr, exitCode };
346
+ // stream-json prints one message per line and ends with the result message.
347
+ return {
348
+ stdout: streamJson ? (stdout.trim().split("\n").at(-1) ?? "") : stdout,
349
+ stderr,
350
+ exitCode,
351
+ };
352
});
353
354
const rawStdout = yield* runClaudeCommand(true).pipe(