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, 03:37 UTC
fix(server): skills from Claude --plugin-dir launch args show in the composer (#39896)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Manav committed
Nov 21, 2026 at 08:43 UTC
a1b9e1cc8709d50190bf8e1f50e94257ce206525
3 files changed
+98
-32
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+3
-25
@@ -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, tokenizeCliArgs } from "@t3tools/shared/cliArgs";
75
+import { parseCliArgs } from "@t3tools/shared/cliArgs";
76
import { fromLenientJson } from "@t3tools/shared/schemaJson";
77
import {
78
claudeMcpToolName,
@@ -172,6 +172,8 @@ import {
172
} from "../../provider/Drivers/ClaudeSkillDispatch.ts";
173
import {
174
claudeLaunchArgDirectories,
175
+ claudeLaunchArgParseOptions,
176
+ claudeLaunchArgPluginDirectories,
177
customClaudeApiEndpointHost,
178
discoverClaudeSkills,
179
readClaudeSettingsEnv,
@@ -356,30 +358,6 @@ function mergeClaudeStreamUsage(
358
};
359
}
360
export const CLAUDE_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(CLAUDE_PROVIDER);
359
-// The Claude CLI takes the next token as this flag's value even when it starts with `--`.
360
-const claudeLaunchArgParseOptions = { valueFlags: ["append-system-prompt"] };
361
-
362
-// Claude's --plugin-dir is repeatable; parseCliArgs keeps only the last one.
363
-function claudeLaunchArgPluginDirectories(launchArgs: string): ReadonlyArray<string> {
364
- const tokens = tokenizeCliArgs(launchArgs);
365
- const directories: string[] = [];
366
- for (let index = 0; index < tokens.length && tokens[index] !== "--"; index++) {
367
- const token = tokens[index]!;
368
- if (!token.startsWith("--") || token.includes("=")) {
369
- if (token.startsWith("--plugin-dir=")) directories.push(token.slice("--plugin-dir=".length));
370
- continue;
371
- }
372
- const next = tokens[index + 1];
373
- const takesNext =
374
- next !== undefined &&
375
- (!next.startsWith("--") || claudeLaunchArgParseOptions.valueFlags.includes(token.slice(2)));
376
- if (!takesNext) continue;
377
- if (token === "--plugin-dir") directories.push(next);
378
- index++;
379
- }
380
- return directories;
381
-}
382
-
361
const CLAUDE_SCRIPT_EXTENSIONS = [".js", ".mjs", ".tsx", ".ts", ".jsx"];
362
// The SDK has no control-request deadline; the CLI waits up to 30 s per MCP server.
363
const CLAUDE_MCP_REGISTRATION_TIMEOUT = "90 seconds";
apps/server/src/provider/Drivers/ClaudeSkills.test.ts
+48
@@ -677,6 +677,54 @@ it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
677
}),
678
);
679
680
+ it.effect("discovers inline plugins from --plugin-dir launch args", () =>
681
+ Effect.gen(function* () {
682
+ const fs = yield* FileSystem.FileSystem;
683
+ const path = yield* Path.Path;
684
+ const workspace = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
685
+ const configDir = path.join(workspace, "config");
686
+ const named = path.join(workspace, "named");
687
+ yield* fs.makeDirectory(path.join(named, ".claude-plugin"), { recursive: true });
688
+ yield* fs.writeFileString(
689
+ path.join(named, ".claude-plugin", "plugin.json"),
690
+ '{"name":"acme"}',
691
+ );
692
+ yield* writeSkill(path.join(named, "skills"), "qa", "---\ndescription: QA a ticket\n---\n");
693
+ yield* writeSkill(path.join(workspace, "local", "skills"), "lint", "# Lint");
694
+ const bundle = path.join(workspace, "bundle");
695
+ yield* fs.makeDirectory(path.join(bundle, "tools", ".claude-plugin"), { recursive: true });
696
+ yield* fs.writeFileString(
697
+ path.join(bundle, "tools", ".claude-plugin", "plugin.json"),
698
+ '{"name":"tools"}',
699
+ );
700
+ yield* writeSkill(path.join(bundle, "tools", "skills"), "fmt", "# Fmt");
701
+ yield* writeSkill(path.join(workspace, "muted", "skills"), "hidden", "# Hidden");
702
+ yield* fs.makeDirectory(configDir, { recursive: true });
703
+ yield* fs.writeFileString(
704
+ path.join(configDir, "settings.json"),
705
+ JSON.stringify({ enabledPlugins: { "muted@inline": false } }),
706
+ );
707
+
708
+ const launchArgs = `--plugin-dir ${named} --plugin-dir=local --model sonnet --plugin-dir ${bundle} --plugin-dir muted`;
709
+ const skills = yield* discoverClaudeSkills({ homePath: configDir, launchArgs }, workspace);
710
+ assert.deepEqual(
711
+ skills.map(({ name, scope, description }) => ({ name, scope, description })),
712
+ [
713
+ { name: "acme:qa", scope: "user", description: "QA a ticket" },
714
+ { name: "local:lint", scope: "user", description: undefined },
715
+ { name: "tools:fmt", scope: "user", description: undefined },
716
+ ],
717
+ );
718
+ // Without a cwd, a relative --plugin-dir has nothing to resolve against.
719
+ assert.deepEqual(
720
+ (yield* discoverClaudeSkills({ homePath: configDir, launchArgs })).map(
721
+ (skill) => skill.name,
722
+ ),
723
+ ["acme:qa", "tools:fmt"],
724
+ );
725
+ }),
726
+ );
727
+
728
it.effect("discovers user and project skills with frontmatter metadata", () =>
729
Effect.gen(function* () {
730
const fs = yield* FileSystem.FileSystem;
apps/server/src/provider/Drivers/ClaudeSkills.ts
+47
-7
@@ -485,9 +485,14 @@ const expandInlinePluginDirectory = Effect.fn("expandInlinePluginDirectory")(fun
485
);
486
});
487
488
-/** Plugin folders Claude Code loads inline from CLAUDE_CODE_PLUGIN_DIRS, and their plugin names. */
488
+/**
489
+ * Plugin folders Claude Code loads inline, from --plugin-dir launch arguments and then
490
+ * CLAUDE_CODE_PLUGIN_DIRS, and their plugin names.
491
+ */
492
const discoverInlinePluginSkillRoots = Effect.fn("discoverInlinePluginSkillRoots")(function* (
490
- pluginDirectories: string | undefined,
493
+ launchArgPluginDirectories: ReadonlyArray<string>,
494
+ environmentPluginDirectories: string | undefined,
495
+ cwd: string | undefined,
496
enabledPlugins: ReadonlyMap<string, boolean>,
497
managedPluginNames: ReadonlySet<string>,
498
) {
@@ -497,11 +502,20 @@ const discoverInlinePluginSkillRoots = Effect.fn("discoverInlinePluginSkillRoots
502
const roots: Array<ClaudeSkillRoot> = [];
503
const names = new Set<string>();
504
const seen = new Set<string>();
500
- for (const entry of (pluginDirectories ?? "").split(platform === "win32" ? ";" : ":")) {
501
- const directory = expandHomePath(entry.trim(), home);
502
- // Claude skips relative entries rather than resolving them against its cwd.
503
- if (!directory || !path.isAbsolute(directory)) continue;
504
- for (const installPath of yield* expandInlinePluginDirectory(path.resolve(directory))) {
505
+ const directories = [
506
+ // Claude resolves a relative --plugin-dir against its cwd and expands no `~` in it.
507
+ ...launchArgPluginDirectories
508
+ .filter((directory) => directory && (cwd || path.isAbsolute(directory)))
509
+ .map((directory) => path.resolve(cwd ?? ".", directory)),
510
+ // Claude skips relative CLAUDE_CODE_PLUGIN_DIRS entries rather than resolving them.
511
+ ...(environmentPluginDirectories ?? "")
512
+ .split(platform === "win32" ? ";" : ":")
513
+ .map((entry) => expandHomePath(entry.trim(), home))
514
+ .filter((directory) => directory && path.isAbsolute(directory))
515
+ .map((directory) => path.resolve(directory)),
516
+ ];
517
+ for (const directory of directories) {
518
+ for (const installPath of yield* expandInlinePluginDirectory(directory)) {
519
if (seen.has(installPath)) continue;
520
seen.add(installPath);
521
const manifest = yield* readPluginManifest(installPath);
@@ -717,6 +731,30 @@ export function claudeLaunchArgDirectories(launchArgs?: string): ReadonlyArray<s
731
return directories;
732
}
733
734
+// The Claude CLI takes the next token as this flag's value even when it starts with `--`.
735
+export const claudeLaunchArgParseOptions = { valueFlags: ["append-system-prompt"] };
736
+
737
+// Claude's --plugin-dir is repeatable; parseCliArgs keeps only the last one.
738
+export function claudeLaunchArgPluginDirectories(launchArgs?: string): ReadonlyArray<string> {
739
+ const tokens = tokenizeCliArgs(launchArgs);
740
+ const directories: string[] = [];
741
+ for (let index = 0; index < tokens.length && tokens[index] !== "--"; index++) {
742
+ const token = tokens[index]!;
743
+ if (!token.startsWith("--") || token.includes("=")) {
744
+ if (token.startsWith("--plugin-dir=")) directories.push(token.slice("--plugin-dir=".length));
745
+ continue;
746
+ }
747
+ const next = tokens[index + 1];
748
+ const takesNext =
749
+ next !== undefined &&
750
+ (!next.startsWith("--") || claudeLaunchArgParseOptions.valueFlags.includes(token.slice(2)));
751
+ if (!takesNext) continue;
752
+ if (token === "--plugin-dir") directories.push(next);
753
+ index++;
754
+ }
755
+ return directories;
756
+}
757
+
758
/** First name wins: managed skills, then user skills, then project skills. */
759
export const discoverClaudeSkills = Effect.fn("discoverClaudeSkills")(function* (
760
config: Pick<ClaudeSettings, "homePath"> & Partial<Pick<ClaudeSettings, "launchArgs">>,
@@ -744,7 +782,9 @@ export const discoverClaudeSkills = Effect.fn("discoverClaudeSkills")(function*
782
(yield* readClaudeSettingsEnv(config, cwd, env)).CLAUDE_CODE_PLUGIN_DIRS ??
783
env.CLAUDE_CODE_PLUGIN_DIRS;
784
const inlinePlugins = yield* discoverInlinePluginSkillRoots(
785
+ claudeLaunchArgPluginDirectories(config.launchArgs),
786
inlinePluginDirectories,
787
+ cwd,
788
enabledPlugins,
789
managedPluginNames,
790
);