MCPcopy
hub / github.com/claude-code-best/claude-code / getCommands

Function getCommands

src/commands.ts:563–604  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

561 * auth changes (e.g. /login) take effect immediately.
562 */
563export async function getCommands(cwd: string): Promise<Command[]> {
564 const allCommands = await loadAllCommands(cwd)
565
566 // Get dynamic skills discovered during file operations
567 const dynamicSkills = getDynamicSkills()
568
569 // Build base commands without dynamic skills
570 const baseCommands = allCommands.filter(
571 _ => meetsAvailabilityRequirement(_) && isCommandEnabled(_),
572 )
573
574 if (dynamicSkills.length === 0) {
575 return baseCommands
576 }
577
578 // Dedupe dynamic skills - only add if not already present
579 const baseCommandNames = new Set(baseCommands.map(c => c.name))
580 const uniqueDynamicSkills = dynamicSkills.filter(
581 s =>
582 !baseCommandNames.has(s.name) &&
583 meetsAvailabilityRequirement(s) &&
584 isCommandEnabled(s),
585 )
586
587 if (uniqueDynamicSkills.length === 0) {
588 return baseCommands
589 }
590
591 // Insert dynamic skills after plugin skills but before built-in commands
592 const builtInNames = new Set(COMMANDS().map(c => c.name))
593 const insertIndex = baseCommands.findIndex(c => builtInNames.has(c.name))
594
595 if (insertIndex === -1) {
596 return [...baseCommands, ...uniqueDynamicSkills]
597 }
598
599 return [
600 ...baseCommands.slice(0, insertIndex),
601 ...uniqueDynamicSkills,
602 ...baseCommands.slice(insertIndex),
603 ]
604}
605
606/**
607 * Clears only the memoization caches for commands, WITHOUT clearing skill caches.

Callers 9

getAllCommandsFunction · 0.85
commands.tsFile · 0.85
runFunction · 0.85
setupFunction · 0.85
refreshPluginStateFunction · 0.85
runHeadlessStreamingFunction · 0.85
getSkillIndexFunction · 0.85
createSessionFunction · 0.85
useSkillsChangeFunction · 0.85

Calls 4

getDynamicSkillsFunction · 0.85
isCommandEnabledFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected