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:3045–3067  ·  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

3043 * of custom paths to cmd.exe and disables delayed expansion, so user path bytes
3044 * never become source text in either outer shell. */
3045static int cbm_build_claude_hook_command(const char *script_name, const char *config_dir,
3046 bool windows, char *out, size_t out_sz) {
3047 if (!cbm_hook_script_name_safe(script_name) || !out || out_sz == 0U) {
3048 return CLI_ERR;
3049 }
3050 out[0] = '\0';
3051 if (windows) {
3052 const char *base =
3053 config_dir && config_dir[0] ? "%CLAUDE_CONFIG_DIR%" : "%USERPROFILE%\\.claude";
3054 int written = snprintf(out, out_sz, "cmd.exe /d /v:off /s /c '\"\"%s\\hooks\\%s\"\"'", base,
3055 script_name);
3056 return written > 0 && (size_t)written < out_sz ? CLI_OK : CLI_ERR;
3057 }
3058 if (config_dir && config_dir[0]) {
3059 char path[CLI_BUF_1K];
3060 int written = snprintf(path, sizeof(path), "%s/hooks/%s", config_dir, script_name);
3061 return written > 0 && (size_t)written < sizeof(path)
3062 ? cbm_shell_quote_word(path, out, out_sz)
3063 : CLI_ERR;
3064 }
3065 int written = snprintf(out, out_sz, "\"$HOME/.claude/hooks/%s\"", script_name);
3066 return written > 0 && (size_t)written < out_sz ? CLI_OK : CLI_ERR;
3067}
3068
3069static int cbm_resolve_hook_command(const char *script_name, char *out, size_t out_sz) {
3070 char env_buf[CLI_BUF_1K];

Calls 2

cbm_shell_quote_wordFunction · 0.85

Tested by

no test coverage detected