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:2461–2483  ·  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

2459 * of custom paths to cmd.exe and disables delayed expansion, so user path bytes
2460 * never become source text in either outer shell. */
2461static int cbm_build_claude_hook_command(const char *script_name, const char *config_dir,
2462 bool windows, char *out, size_t out_sz) {
2463 if (!cbm_hook_script_name_safe(script_name) || !out || out_sz == 0U) {
2464 return CLI_ERR;
2465 }
2466 out[0] = '\0';
2467 if (windows) {
2468 const char *base =
2469 config_dir && config_dir[0] ? "%CLAUDE_CONFIG_DIR%" : "%USERPROFILE%\\.claude";
2470 int written = snprintf(out, out_sz, "cmd.exe /d /v:off /s /c '\"\"%s\\hooks\\%s\"\"'", base,
2471 script_name);
2472 return written > 0 && (size_t)written < out_sz ? CLI_OK : CLI_ERR;
2473 }
2474 if (config_dir && config_dir[0]) {
2475 char path[CLI_BUF_1K];
2476 int written = snprintf(path, sizeof(path), "%s/hooks/%s", config_dir, script_name);
2477 return written > 0 && (size_t)written < sizeof(path)
2478 ? cbm_shell_quote_word(path, out, out_sz)
2479 : CLI_ERR;
2480 }
2481 int written = snprintf(out, out_sz, "\"$HOME/.claude/hooks/%s\"", script_name);
2482 return written > 0 && (size_t)written < out_sz ? CLI_OK : CLI_ERR;
2483}
2484
2485static int cbm_resolve_hook_command(const char *script_name, char *out, size_t out_sz) {
2486 char env_buf[CLI_BUF_1K];

Calls 2

cbm_shell_quote_wordFunction · 0.85

Tested by

no test coverage detected