@@ -5,7 +5,7 @@ import * as Path from "effect/Path";
55import * as Option from "effect/Option" ;
66import * as Schema from "effect/Schema" ;
77import * as HostProcess from "@t3tools/shared/HostProcess" ;
8- import { parseCliArgs } from "@t3tools/shared/cliArgs" ;
8+ import { tokenizeCliArgs } from "@t3tools/shared/cliArgs" ;
99import { fromLenientJson } from "@t3tools/shared/schemaJson" ;
1010import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens" ;
1111import { parse as parseYamlDocument } from "yaml" ;
@@ -427,6 +427,26 @@ const resolveClaudeConfigDirPath = Effect.fn("resolveClaudeConfigDirPath")(funct
427427 return path . join ( home , ".claude" ) ;
428428} ) ;
429429
430+ // Claude's --add-dir is repeatable and variadic; parseCliArgs keeps only one value.
431+ export function claudeLaunchArgDirectories ( launchArgs ?: string ) : ReadonlyArray < string > {
432+ const directories : string [ ] = [ ] ;
433+ let collecting = false ;
434+ for ( const token of tokenizeCliArgs ( launchArgs ) ) {
435+ if ( token === "--" ) break ;
436+ if ( token === "--add-dir" ) {
437+ collecting = true ;
438+ } else if ( token . startsWith ( "--add-dir=" ) ) {
439+ directories . push ( token . slice ( "--add-dir=" . length ) ) ;
440+ collecting = false ;
441+ } else if ( token . startsWith ( "-" ) ) {
442+ collecting = false ;
443+ } else if ( collecting ) {
444+ directories . push ( token ) ;
445+ }
446+ }
447+ return directories ;
448+ }
449+
430450/** First name wins, matching Claude Code's precedence of user skills over project skills. */
431451export const discoverClaudeSkills = Effect . fn ( "discoverClaudeSkills" ) ( function * (
432452 config : Pick < ClaudeSettings , "homePath" > & Partial < Pick < ClaudeSettings , "launchArgs" > > ,
@@ -442,22 +462,15 @@ export const discoverClaudeSkills = Effect.fn("discoverClaudeSkills")(function*
442462 environment ?? process . env ,
443463 ) ;
444464
445- const additionalDirectory = parseCliArgs ( config . launchArgs ?? "" ) . flags [ "add-dir" ] ;
446465 const roots : ReadonlyArray < ClaudeSkillRoot > = [
447466 { directory : path . join ( configDirPath , "skills" ) , scope : "user" } ,
448467 ...( cwd ? [ { directory : path . join ( cwd , ".claude" , "skills" ) , scope : "project" as const } ] : [ ] ) ,
449- ...( additionalDirectory && ( cwd || path . isAbsolute ( additionalDirectory ) )
450- ? [
451- {
452- directory : path . join (
453- path . resolve ( cwd ?? "." , additionalDirectory ) ,
454- ".claude" ,
455- "skills" ,
456- ) ,
457- scope : "project" as const ,
458- } ,
459- ]
460- : [ ] ) ,
468+ ...claudeLaunchArgDirectories ( config . launchArgs )
469+ . filter ( ( directory ) => directory && ( cwd || path . isAbsolute ( directory ) ) )
470+ . map ( ( directory ) => ( {
471+ directory : path . join ( path . resolve ( cwd ?? "." , directory ) , ".claude" , "skills" ) ,
472+ scope : "project" as const ,
473+ } ) ) ,
461474 ...( yield * discoverPluginSkillRoots (
462475 configDirPath ,
463476 cwd ,
0 commit comments