MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_build_claude_hook_command

Function cbm_build_claude_hook_command

src/cli/cli.c:2531–2553  ·  view source on GitHub ↗

Build the hook command string written into Claude Code's settings.json. * POSIX embeds a safely quoted absolute custom config path or a portable $HOME * path. Windows explicitly invokes cmd.exe so the hook also works when Claude * falls back from Git Bash to PowerShell. The Windows command defers expansion * of custom paths to cmd.exe and disables delayed expansion, so user path bytes * never

Source from the content-addressed store, hash-verified

2529 * of custom paths to cmd.exe and disables delayed expansion, so user path bytes
2530 * never become source text in either outer shell. */
2531static int cbm_build_claude_hook_command(const char *script_name, const char *config_dir,
2532 bool windows, char *out, size_t out_sz) {
2533 if (!cbm_hook_script_name_safe(script_name) || !out || out_sz == 0U) {
2534 return CLI_ERR;
2535 }
2536 out[0] = '\0';
2537 if (windows) {
2538 const char *base =
2539 config_dir && config_dir[0] ? "%CLAUDE_CONFIG_DIR%" : "%USERPROFILE%\\.claude";
2540 int written = snprintf(out, out_sz, "cmd.exe /d /v:off /s /c '\"\"%s\\hooks\\%s\"\"'", base,
2541 script_name);
2542 return written > 0 && (size_t)written < out_sz ? CLI_OK : CLI_ERR;
2543 }
2544 if (config_dir && config_dir[0]) {
2545 char path[CLI_BUF_1K];
2546 int written = snprintf(path, sizeof(path), "%s/hooks/%s", config_dir, script_name);
2547 return written > 0 && (size_t)written < sizeof(path)
2548 ? cbm_shell_quote_word(path, out, out_sz)
2549 : CLI_ERR;
2550 }
2551 int written = snprintf(out, out_sz, "\"$HOME/.claude/hooks/%s\"", script_name);
2552 return written > 0 && (size_t)written < out_sz ? CLI_OK : CLI_ERR;
2553}
2554
2555static int cbm_resolve_hook_command(const char *script_name, char *out, size_t out_sz) {
2556 char env_buf[CLI_BUF_1K];

Calls 2

cbm_shell_quote_wordFunction · 0.85

Tested by

no test coverage detected