@@ -55,12 +55,19 @@ function fixFilenameCircularRef(): Plugin {
5555 } ;
5656}
5757
58+ let claudeCliCopied = false ;
59+
5860function copyClaudeExecutable ( ) : Plugin {
5961 return {
6062 name : "copy-claude-executable" ,
6163 writeBundle ( ) {
6264 const destDir = join ( __dirname , ".vite/build/claude-cli" ) ;
6365
66+ // Skip re-copying on subsequent HMR rebuilds
67+ if ( claudeCliCopied && existsSync ( join ( destDir , "cli.js" ) ) ) {
68+ return ;
69+ }
70+
6471 if ( ! existsSync ( destDir ) ) {
6572 mkdirSync ( destDir , { recursive : true } ) ;
6673 }
@@ -96,6 +103,7 @@ function copyClaudeExecutable(): Plugin {
96103 if ( existsSync ( vendorDir ) ) {
97104 cpSync ( vendorDir , join ( destDir , "vendor" ) , { recursive : true } ) ;
98105 }
106+ claudeCliCopied = true ;
99107 return ;
100108 }
101109 }
@@ -121,6 +129,7 @@ function copyClaudeExecutable(): Plugin {
121129 console . log (
122130 "Assembled Claude CLI from workspace sources in claude-cli/ subdirectory" ,
123131 ) ;
132+ claudeCliCopied = true ;
124133 return ;
125134 }
126135
@@ -326,6 +335,8 @@ const PLUGIN_ALLOW_LIST = [
326335 "hooks" ,
327336] ;
328337
338+ let remoteSkillsFetched = false ;
339+
329340function copyPosthogPlugin ( isDev : boolean ) : Plugin {
330341 const sourceDir = join ( __dirname , "../../plugins/posthog" ) ;
331342 const localSkillsDir = join ( sourceDir , "local-skills" ) ;
@@ -366,10 +377,14 @@ function copyPosthogPlugin(isDev: boolean): Plugin {
366377 }
367378
368379 // 2. Download and overlay remote skills (overrides same-named shipped skills)
369- await downloadAndExtractSkills ( destSkillsDir ) ;
380+ // Skip re-downloading on subsequent HMR rebuilds
381+ if ( ! remoteSkillsFetched ) {
382+ await downloadAndExtractSkills ( destSkillsDir ) ;
370383
371- // 2b. Download and overlay context-mill omnibus skills (overrides same-named skills)
372- await downloadAndExtractContextMillSkills ( destSkillsDir ) ;
384+ // 2b. Download and overlay context-mill omnibus skills (overrides same-named skills)
385+ await downloadAndExtractContextMillSkills ( destSkillsDir ) ;
386+ remoteSkillsFetched = true ;
387+ }
373388
374389 // 3. In dev mode: overlay local-skills (overrides both shipped and remote)
375390 if ( isDev && existsSync ( localSkillsDir ) ) {
@@ -409,12 +424,19 @@ function copyDrizzleMigrations(): Plugin {
409424 } ;
410425}
411426
427+ let codexAcpCopied = false ;
428+
412429function copyCodexAcpBinaries ( ) : Plugin {
413430 return {
414431 name : "copy-codex-acp-binaries" ,
415432 writeBundle ( ) {
416433 const destDir = join ( __dirname , ".vite/build/codex-acp" ) ;
417434
435+ // Skip re-copying on subsequent HMR rebuilds
436+ if ( codexAcpCopied && existsSync ( destDir ) ) {
437+ return ;
438+ }
439+
418440 if ( ! existsSync ( destDir ) ) {
419441 mkdirSync ( destDir , { recursive : true } ) ;
420442 }
@@ -452,6 +474,7 @@ function copyCodexAcpBinaries(): Plugin {
452474 ) ;
453475 }
454476 }
477+ codexAcpCopied = true ;
455478 } ,
456479 } ;
457480}
0 commit comments