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

Function getCommands

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

Source from the content-addressed store, hash-verified

476 * auth changes (e.g. /login) take effect immediately.
477 */
478export async function getCommands(cwd: string): Promise<Command[]> {
479 const allCommands = await loadAllCommands(cwd)
480
481 // Get dynamic skills discovered during file operations
482 const dynamicSkills = getDynamicSkills()
483
484 // Build base commands without dynamic skills
485 const baseCommands = allCommands.filter(
486 _ => meetsAvailabilityRequirement(_) && isCommandEnabled(_),
487 )
488
489 if (dynamicSkills.length === 0) {
490 return baseCommands
491 }
492
493 // Dedupe dynamic skills - only add if not already present
494 const baseCommandNames = new Set(baseCommands.map(c => c.name))
495 const uniqueDynamicSkills = dynamicSkills.filter(
496 s =>
497 !baseCommandNames.has(s.name) &&
498 meetsAvailabilityRequirement(s) &&
499 isCommandEnabled(s),
500 )
501
502 if (uniqueDynamicSkills.length === 0) {
503 return baseCommands
504 }
505
506 // Insert dynamic skills after plugin skills but before built-in commands
507 const builtInNames = new Set(COMMANDS().map(c => c.name))
508 const insertIndex = baseCommands.findIndex(c => builtInNames.has(c.name))
509
510 if (insertIndex === -1) {
511 return [...baseCommands, ...uniqueDynamicSkills]
512 }
513
514 return [
515 ...baseCommands.slice(0, insertIndex),
516 ...uniqueDynamicSkills,
517 ...baseCommands.slice(insertIndex),
518 ]
519}
520
521/**
522 * Clears only the memoization caches for commands, WITHOUT clearing skill caches.

Callers 8

commands.tsFile · 0.85
runFunction · 0.85
setupFunction · 0.85
getAllCommandsFunction · 0.85
refreshPluginStateFunction · 0.85
runHeadlessStreamingFunction · 0.85
useSkillsChangeFunction · 0.85
mainFunction · 0.85

Calls 4

getDynamicSkillsFunction · 0.85
isCommandEnabledFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected