claude-code: added 'commandsDir' option to specify commands from filesystem

This commit is contained in:
Sewer56
2025-08-22 22:13:07 +01:00
committed by Austin Horstman
parent a641bbbb9b
commit be37a3492d
5 changed files with 47 additions and 0 deletions

View File

@@ -196,6 +196,16 @@ in
example = lib.literalExpression "./agents";
};
commandsDir = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Path to a directory containing command files for Claude Code.
Command files from this directory will be symlinked to .claude/commands/.
'';
example = lib.literalExpression "./commands";
};
mcpServers = lib.mkOption {
type = lib.types.attrsOf jsonFormat.type;
default = { };
@@ -251,6 +261,10 @@ in
assertion = !(cfg.agents != { } && cfg.agentsDir != null);
message = "Cannot specify both `programs.claude-code.agents` and `programs.claude-code.agentsDir`";
}
{
assertion = !(cfg.commands != { } && cfg.commandsDir != null);
message = "Cannot specify both `programs.claude-code.commands` and `programs.claude-code.commandsDir`";
}
];
programs.claude-code.finalPackage =
@@ -300,6 +314,11 @@ in
source = cfg.agentsDir;
recursive = true;
};
".claude/commands" = lib.mkIf (cfg.commandsDir != null) {
source = cfg.commandsDir;
recursive = true;
};
}
// lib.mapAttrs' (
name: content:

View File

@@ -26,11 +26,18 @@
test-agent = "test content";
};
agentsDir = ./agents;
# assert fail: cannot set commands and commandsDir at the same time.
commands = {
test-command = "test content";
};
commandsDir = ./commands;
};
test.asserts.assertions.expected = [
"`programs.claude-code.package` cannot be null when `mcpServers` is configured"
"Cannot specify both `programs.claude-code.memory.text` and `programs.claude-code.memory.source`"
"Cannot specify both `programs.claude-code.agents` and `programs.claude-code.agentsDir`"
"Cannot specify both `programs.claude-code.commands` and `programs.claude-code.commandsDir`"
];
}

View File

@@ -0,0 +1,14 @@
{
programs.claude-code = {
enable = true;
commandsDir = ./commands;
};
nmt.script = ''
assertFileExists home-files/.claude/commands/test-command.md
assertLinkExists home-files/.claude/commands/test-command.md
assertFileContent \
home-files/.claude/commands/test-command.md \
${./commands/test-command.md}
'';
}

View File

@@ -0,0 +1,6 @@
---
allowed-tools: Bash(echo:*)
description: Test command for commandsDir functionality
---
This is a test command to verify that commandsDir works correctly.

View File

@@ -6,4 +6,5 @@
claude-code-memory-management = ./memory-management.nix;
claude-code-memory-from-source = ./memory-from-source.nix;
claude-code-agents-dir = ./agents-dir.nix;
claude-code-commands-dir = ./commands-dir.nix;
}