| 2180 | #define CMM_SUBAGENT_REMINDER_SCRIPT "cbm-subagent-reminder" |
| 2181 | |
| 2182 | static void cbm_install_subagent_reminder_script(const char *home) { |
| 2183 | if (!home) { |
| 2184 | return; |
| 2185 | } |
| 2186 | char config_dir[CLI_BUF_1K]; |
| 2187 | cbm_claude_config_dir(home, config_dir, sizeof(config_dir)); |
| 2188 | if (!config_dir[0]) { |
| 2189 | return; |
| 2190 | } |
| 2191 | char hooks_dir[CLI_BUF_1K]; |
| 2192 | snprintf(hooks_dir, sizeof(hooks_dir), "%s/hooks", config_dir); |
| 2193 | cbm_mkdir_p(hooks_dir, CLI_OCTAL_PERM); |
| 2194 | |
| 2195 | char script_path[CLI_BUF_1K]; |
| 2196 | snprintf(script_path, sizeof(script_path), "%s/" CMM_SUBAGENT_REMINDER_SCRIPT, hooks_dir); |
| 2197 | |
| 2198 | FILE *f = fopen(script_path, "w"); |
| 2199 | if (!f) { |
| 2200 | return; |
| 2201 | } |
| 2202 | /* The additionalContext value is a single line with no embedded quotes, |
| 2203 | * backslashes, or newlines, so the JSON below is valid as written — no |
| 2204 | * runtime escaping (and no python3/jq dependency) is required. */ |
| 2205 | (void)fprintf(f, |
| 2206 | "#!/usr/bin/env bash\n" |
| 2207 | "# SubagentStart hook: tell subagents to use codebase-memory-mcp tools.\n" |
| 2208 | "# Installed by codebase-memory-mcp. Fires when any subagent is spawned.\n" |
| 2209 | "# SubagentStart injects context via JSON additionalContext, not plain stdout.\n" |
| 2210 | "cat << 'REMINDER'\n" |
| 2211 | "{\"hookSpecificOutput\":{\"hookEventName\":\"SubagentStart\"," |
| 2212 | "\"additionalContext\":\"Code discovery: prefer codebase-memory-mcp tools " |
| 2213 | "(search_graph, trace_path, get_code_snippet, query_graph, get_architecture, " |
| 2214 | "search_code) over grep/file-read for navigating code. Use Grep/Glob/Read for " |
| 2215 | "text, configs, and non-code files.\"}}\n" |
| 2216 | "REMINDER\n"); |
| 2217 | #ifndef _WIN32 |
| 2218 | fchmod(fileno(f), CLI_OCTAL_PERM); |
| 2219 | #endif |
| 2220 | (void)fclose(f); |
| 2221 | #ifdef _WIN32 |
| 2222 | chmod(script_path, CLI_OCTAL_PERM); |
| 2223 | #endif |
| 2224 | } |
| 2225 | |
| 2226 | int cbm_upsert_claude_subagent_hooks(const char *settings_path) { |
| 2227 | char command[CLI_BUF_1K]; |
no test coverage detected