The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
fix(claude): every repeated --plugin-dir launch argument loads its plugin (#38634)
Co-authored-by: asssslay <avramova.ruslana.a.r.r@gmail.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Ibrahim Elkamali committed
Nov 19, 2026 at 22:13 UTC
5478e44cc900577de62e271a43c4c341a1268977
2 files changed
+48
-3
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+17
-2
@@ -380,7 +380,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
380
assert.isUndefined(options.extraArgs?.["dangerously-skip-permissions"]);
381
});
382
383
- it("passes every --add-dir launch directory to Claude", () => {
383
+ it("passes every --add-dir and --plugin-dir launch directory to Claude", () => {
384
const options = ClaudeAdapterV2.makeClaudeQueryOptions({
385
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
386
nativeThreadId: "native-add-dir",
@@ -389,7 +389,8 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
389
attachmentsDir: "/attachments",
390
settings: {
391
...AUTO_COMPACT_CLAUDE_SETTINGS,
392
- launchArgs: "--add-dir ../apps ../lib --verbose --add-dir=/shared",
392
+ launchArgs:
393
+ '--add-dir ../apps ../lib --verbose --add-dir=/shared --plugin-dir ./a --plugin-dir=./b.zip --append-system-prompt "--plugin-dir=./prompt"',
394
},
395
});
396
assert.deepEqual(options.additionalDirectories, [
@@ -400,6 +401,20 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
401
"/shared",
402
]);
403
assert.isUndefined(options.extraArgs?.["add-dir"]);
404
+ assert.deepEqual(options.plugins, [
405
+ { type: "local", path: "./a" },
406
+ { type: "local", path: "./b.zip" },
407
+ ]);
408
+ assert.isUndefined(options.extraArgs?.["plugin-dir"]);
409
+ const bare = ClaudeAdapterV2.makeClaudeQueryOptions({
410
+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
411
+ nativeThreadId: "native-bare-plugin-dir",
412
+ resume: false,
413
+ cwd: "/workspace",
414
+ settings: { ...AUTO_COMPACT_CLAUDE_SETTINGS, launchArgs: "--plugin-dir --verbose" },
415
+ });
416
+ assert.isUndefined(bare.plugins);
417
+ assert.isNull(bare.extraArgs?.["plugin-dir"]);
418
});
419
420
it("gives delegated children Claude's subagent prompt cache TTL", () => {
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+31
-1
@@ -72,7 +72,7 @@ import type {
72
// @effect-diagnostics-next-line nodeBuiltinImport:off -- the SDK takes a Node ChildProcess for the CLI.
73
import * as NodeChildProcess from "node:child_process";
74
import * as NodeUtil from "node:util";
75
-import { parseCliArgs } from "@t3tools/shared/cliArgs";
75
+import { parseCliArgs, tokenizeCliArgs } from "@t3tools/shared/cliArgs";
76
import { fromLenientJson } from "@t3tools/shared/schemaJson";
77
import {
78
claudeMcpToolName,
@@ -358,6 +358,27 @@ export const CLAUDE_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(CLAUDE_PROV
358
// The Claude CLI takes the next token as this flag's value even when it starts with `--`.
359
const claudeLaunchArgParseOptions = { valueFlags: ["append-system-prompt"] };
360
361
+// Claude's --plugin-dir is repeatable; parseCliArgs keeps only the last one.
362
+function claudeLaunchArgPluginDirectories(launchArgs: string): ReadonlyArray<string> {
363
+ const tokens = tokenizeCliArgs(launchArgs);
364
+ const directories: string[] = [];
365
+ for (let index = 0; index < tokens.length && tokens[index] !== "--"; index++) {
366
+ const token = tokens[index]!;
367
+ if (!token.startsWith("--") || token.includes("=")) {
368
+ if (token.startsWith("--plugin-dir=")) directories.push(token.slice("--plugin-dir=".length));
369
+ continue;
370
+ }
371
+ const next = tokens[index + 1];
372
+ const takesNext =
373
+ next !== undefined &&
374
+ (!next.startsWith("--") || claudeLaunchArgParseOptions.valueFlags.includes(token.slice(2)));
375
+ if (!takesNext) continue;
376
+ if (token === "--plugin-dir") directories.push(next);
377
+ index++;
378
+ }
379
+ return directories;
380
+}
381
+
382
const CLAUDE_SCRIPT_EXTENSIONS = [".js", ".mjs", ".tsx", ".ts", ".jsx"];
383
// The SDK has no control-request deadline; the CLI waits up to 30 s per MCP server.
384
const CLAUDE_MCP_REGISTRATION_TIMEOUT = "90 seconds";
@@ -2225,6 +2246,8 @@ export function makeClaudeQueryOptions(input: {
2246
const {
2247
// claudeLaunchArgDirectories reads every --add-dir into additionalDirectories.
2248
"add-dir": _launchArgAddDir,
2249
+ // claudeLaunchArgPluginDirectories reads every --plugin-dir into plugins.
2250
+ "plugin-dir": launchArgPluginDir,
2251
"permission-mode": launchArgPermissionMode,
2252
"dangerously-skip-permissions": launchArgSkipPermissions,
2253
"append-system-prompt": launchArgAppendSystemPrompt,
@@ -2248,6 +2271,10 @@ export function makeClaudeQueryOptions(input: {
2271
if (requestThinkingSummaries && extraArgs["thinking-display"] === undefined) {
2272
extraArgs["thinking-display"] = "summarized";
2273
}
2274
+ const pluginDirectories =
2275
+ input.settings === undefined ? [] : claudeLaunchArgPluginDirectories(input.settings.launchArgs);
2276
+ // A bare --plugin-dir still reaches Claude, which reports the missing path.
2277
+ if (launchArgPluginDir === null) extraArgs["plugin-dir"] = null;
2278
const threadIdentity: ClaudeAgentSdkThreadIdentity = input.resume
2279
? { resume: input.nativeThreadId }
2280
: { sessionId: input.nativeThreadId };
@@ -2379,6 +2406,9 @@ export function makeClaudeQueryOptions(input: {
2406
},
2407
}
2408
: {}),
2409
+ ...(pluginDirectories.length === 0
2410
+ ? {}
2411
+ : { plugins: pluginDirectories.map((path) => ({ type: "local" as const, path })) }),
2412
...(Object.keys(extraArgs).length === 0 ? {} : { extraArgs }),
2413
};
2414
const additionalDirectories = [