1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-09 18:41:06 +01:00

claude-code: fix wrapper to inject --mcp-config after subcommands

Manually wrap program to maintain options called from cli.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-12-04 12:13:20 -06:00
parent 9379fbf4f5
commit 05a56dbf24
2 changed files with 14 additions and 14 deletions

View file

@ -345,24 +345,23 @@ in
programs.claude-code.finalPackage =
let
makeWrapperArgs = lib.flatten (
lib.filter (x: x != [ ]) [
(lib.optional (cfg.mcpServers != { }) [
"--add-flags"
"--mcp-config ${jsonFormat.generate "claude-code-mcp-config.json" { inherit (cfg) mcpServers; }}"
])
]
);
mcpConfigFile = jsonFormat.generate "claude-code-mcp-config.json" {
inherit (cfg) mcpServers;
};
hasWrapperArgs = makeWrapperArgs != [ ];
needsWrapper = cfg.mcpServers != { };
wrapperScript = pkgs.writeShellScriptBin "claude" ''
exec "${lib.getExe cfg.package}" "$@" --mcp-config "${mcpConfigFile}"
'';
in
if hasWrapperArgs then
if needsWrapper then
pkgs.symlinkJoin {
name = "claude-code";
paths = [ cfg.package ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/claude ${lib.escapeShellArgs makeWrapperArgs}
rm $out/bin/claude
ln -s ${wrapperScript}/bin/claude $out/bin/claude
'';
inherit (cfg.package) meta;
}

View file

@ -1,2 +1,3 @@
#! /nix/store/00000000000000000000000000000000-bash/bin/bash -e
exec -a "$0" "/nix/store/00000000000000000000000000000000-claude-code/bin/.claude-wrapped" --mcp-config /nix/store/00000000000000000000000000000000-claude-code-mcp-config.json "$@"
#!/nix/store/00000000000000000000000000000000-bash/bin/bash
exec "/nix/store/00000000000000000000000000000000-claude-code/bin/claude-code" "$@" --mcp-config "/nix/store/00000000000000000000000000000000-claude-code-mcp-config.json"