Skip to content

Commit c29e6d5

Browse files
author
Martin Vogel
committed
fix(hooks): replace blocking Claude PreToolUse gate with non-blocking augmenter
The previous PreToolUse hook gated Grep/Glob/Read/Search with 'exit 2' on the first call per session, which broke Claude Code's read-before-edit invariant (issue #362) and could deny tool calls under upgrade/missing-binary failure modes. Replace it with a structurally non-blocking augmenter: - New 'codebase-memory-mcp hook-augment' subcommand reads the hook JSON from stdin and, for Grep/Glob, queries search_graph (in-process, no shell) and emits hookSpecificOutput.additionalContext. Every failure path (no project, short token, missing binary, slow query, timeout) exits 0 with no stdout — the hook physically cannot block a tool call. - 300 ms SIGALRM/_exit(0) in-process deadline; 5 s settings.json timeout backstop. Output is written exactly once at the very end, so a mid-work timeout yields a clean no-op (never partial JSON). - Matcher narrowed to 'Grep|Glob' (Read explicitly excluded) for Claude; Gemini matcher narrowed to 'google_search|grep_search' (excludes read_file) for the same reason. - The installed shim is a thin wrapper that delegates to the binary; legacy filename 'cbm-code-discovery-gate' is kept so existing settings.json entries upgrade with zero migration. Installer refuses to embed binary paths containing a double quote (shim injection defense). - Per-agent 'old matchers' lists let upsert/remove clean up historical matcher strings during upgrade. - Smoke tests (8d/8e/8l) updated to assert the new behavior and regress-test against re-introducing Read in the matcher or 'exit 2' in the shim. - Session reminder text updated: 'always Read a file before editing it' replaces the prior 'fall back to Read only for text content'. (cherry picked from commit f72c8e68c4d91e52911a569a967ad782ce5472b2)
1 parent 32bb56e commit c29e6d5

7 files changed

Lines changed: 513 additions & 65 deletions

File tree

‎Makefile.cbm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ TRACES_SRCS = src/traces/traces.c
215215
WATCHER_SRCS = src/watcher/watcher.c
216216

217217
# CLI module (new)
218-
CLI_SRCS = src/cli/cli.c src/cli/progress_sink.c
218+
CLI_SRCS = src/cli/cli.c src/cli/progress_sink.c src/cli/hook_augment.c
219219

220220
# UI module (graph visualization)
221221
UI_SRCS = \

‎README.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ Restart your agent. Verify with `/mcp` — you should see `codebase-memory-mcp`
333333

334334
| Agent | MCP Config | Instructions | Hooks |
335335
|-------|-----------|-------------|-------|
336-
| Claude Code | `.claude/.mcp.json` | 4 Skills | PreToolUse (Grep/Glob/Read reminder) |
336+
| Claude Code | `.claude/.mcp.json` | 4 Skills | PreToolUse (Grep/Glob graph augment, non-blocking) |
337337
| Codex CLI | `.codex/config.toml` | `.codex/AGENTS.md` | — |
338-
| Gemini CLI | `.gemini/settings.json` | `.gemini/GEMINI.md` | BeforeTool (grep/read reminder) |
338+
| Gemini CLI | `.gemini/settings.json` | `.gemini/GEMINI.md` | BeforeTool (grep reminder) |
339339
| Zed | `settings.json` (JSONC) | — | — |
340340
| OpenCode | `opencode.json` | `AGENTS.md` | — |
341341
| Antigravity | `mcp_config.json` | `AGENTS.md` | — |
@@ -345,7 +345,15 @@ Restart your agent. Verify with `/mcp` — you should see `codebase-memory-mcp`
345345
| OpenClaw | `openclaw.json` | — | — |
346346
| Kiro | `.kiro/settings/mcp.json` | — | — |
347347

348-
**Hooks** are advisory (exit code 0) — they remind agents to prefer MCP graph tools when they reach for grep/glob/read, without blocking the tool call.
348+
**Hooks are structurally non-blocking** (exit code 0, every failure path).
349+
For Claude Code, the `PreToolUse` hook intercepts `Grep`/`Glob` (never `Read` —
350+
gating `Read` breaks the read-before-edit invariant) and, when the search
351+
token matches indexed symbols, injects them as `additionalContext` via
352+
`search_graph` so the agent gets structured context alongside its normal
353+
search results. For Gemini CLI, `BeforeTool` prints a short reminder.
354+
The installed Claude shim file is named `cbm-code-discovery-gate` for
355+
backward compatibility with existing installs; despite the legacy name it
356+
never gates and never blocks.
349357

350358
## CLI Mode
351359

‎scripts/smoke-test.sh‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -569,26 +569,38 @@ if ! path_match "$CMD" "$SELF_PATH"; then
569569
fi
570570
echo "OK 8c: Claude Code MCP (.claude/.mcp.json)"
571571

572-
# 8d: Claude Code hooks
572+
# 8d: Claude Code hooks — matcher must be exactly "Grep|Glob" (no Read, no Search).
573+
# Gating Read breaks Claude Code's read-before-edit invariant (issue #362), so
574+
# this assertion locks in the matcher to prevent regressions.
573575
if ! cat "$FAKE_HOME/.claude/settings.json" 2>/dev/null | python3 -c "
574576
import json, sys
575577
d = json.load(sys.stdin)
576578
hooks = d.get('hooks', {}).get('PreToolUse', [])
577-
found = any('Grep' in str(h.get('matcher', '')) for h in hooks)
578-
sys.exit(0 if found else 1)
579+
ok = any(h.get('matcher') == 'Grep|Glob' for h in hooks)
580+
bad = any('Read' in str(h.get('matcher', '')) for h in hooks)
581+
sys.exit(0 if (ok and not bad) else 1)
579582
" 2>/dev/null; then
580-
echo "FAIL 8d: PreToolUse hook not found in settings.json"
583+
echo "FAIL 8d: PreToolUse hook matcher is not exactly 'Grep|Glob' (or still contains Read)"
581584
exit 1
582585
fi
583-
echo "OK 8d: Claude Code PreToolUse hook"
586+
echo "OK 8d: Claude Code PreToolUse hook (matcher=Grep|Glob, Read excluded)"
584587

585-
# 8e: Claude Code gate script
588+
# 8e: Claude Code shim script — must be non-blocking augmenter, not a gate.
586589
if [ "$(uname -s)" != "MINGW64_NT" ] 2>/dev/null; then
587-
if [ ! -x "$FAKE_HOME/.claude/hooks/cbm-code-discovery-gate" ]; then
588-
echo "FAIL 8e: gate script not executable or missing"
590+
GATE_SCRIPT="$FAKE_HOME/.claude/hooks/cbm-code-discovery-gate"
591+
if [ ! -x "$GATE_SCRIPT" ]; then
592+
echo "FAIL 8e: shim script not executable or missing"
589593
exit 1
590594
fi
591-
echo "OK 8e: gate script installed and executable"
595+
if grep -q 'exit 2' "$GATE_SCRIPT"; then
596+
echo "FAIL 8e: shim contains 'exit 2' — must never block"
597+
exit 1
598+
fi
599+
if ! grep -q 'hook-augment' "$GATE_SCRIPT"; then
600+
echo "FAIL 8e: shim missing 'hook-augment' delegation"
601+
exit 1
602+
fi
603+
echo "OK 8e: shim installed, non-blocking, delegates to hook-augment"
592604
fi
593605

594606
# 8f-8h: Codex TOML
@@ -626,12 +638,17 @@ if ! cat "$FAKE_HOME/.gemini/settings.json" 2>/dev/null | python3 -c "
626638
import json, sys
627639
d = json.load(sys.stdin)
628640
hooks = d.get('hooks', {}).get('BeforeTool', [])
629-
sys.exit(0 if len(hooks) > 0 else 1)
641+
# Matcher must be exactly 'google_search|grep_search' (no read_file). The
642+
# old matcher gated the agent's read tool — consistent with the Claude fix
643+
# we remove it here too.
644+
ok = any(h.get('matcher') == 'google_search|grep_search' for h in hooks)
645+
bad = any('read_file' in str(h.get('matcher', '')) for h in hooks)
646+
sys.exit(0 if (ok and not bad) else 1)
630647
" 2>/dev/null; then
631-
echo "FAIL 8l: Gemini BeforeTool hook missing"
648+
echo "FAIL 8l: Gemini BeforeTool hook matcher must be 'google_search|grep_search' (no read_file)"
632649
exit 1
633650
fi
634-
echo "OK 8l: Gemini BeforeTool hook"
651+
echo "OK 8l: Gemini BeforeTool hook (matcher=google_search|grep_search)"
635652

636653
# 8m: Gemini instructions
637654
if [ ! -f "$FAKE_HOME/.gemini/GEMINI.md" ]; then

‎src/cli/cli.c‎

Lines changed: 101 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,18 +1462,31 @@ int cbm_remove_antigravity_mcp(const char *config_path) {
14621462

14631463
/* ── Claude Code pre-tool hooks ───────────────────────────────── */
14641464

1465-
#define CMM_HOOK_MATCHER "Grep|Glob|Read|Search"
1465+
/* Matcher intentionally excludes Read: gating Read breaks Claude Code's
1466+
* read-before-edit invariant (issue #362). The hook is a non-blocking
1467+
* augmenter, never a gate. */
1468+
#define CMM_HOOK_MATCHER "Grep|Glob"
14661469
#define CMM_HOOK_COMMAND "~/.claude/hooks/cbm-code-discovery-gate"
1470+
/* Hard backstop in settings.json; the binary also self-bounds with an
1471+
* in-process deadline well under this. */
1472+
#define CMM_HOOK_TIMEOUT_SEC 5
14671473

14681474
/* Old matcher values from previous versions — recognized during upgrade so
1469-
* upsert_hooks_json can remove them before inserting the current matcher. */
1470-
static const char *cmm_old_matchers[] = {
1475+
* upsert/remove can clean them up before inserting the current matcher.
1476+
* Per-agent lists (no shared global): each caller passes its own. */
1477+
static const char *const cmm_claude_old_matchers[] = {
1478+
"Grep|Glob|Read|Search",
14711479
"Grep|Glob|Read",
14721480
NULL,
14731481
};
1482+
static const char *const cmm_gemini_old_matchers[] = {
1483+
"google_search|read_file|grep_search",
1484+
NULL,
1485+
};
14741486

1475-
/* Check if a PreToolUse array entry matches our hook (current or old matcher). */
1476-
static bool is_cmm_hook_entry(yyjson_mut_val *entry, const char *matcher_str) {
1487+
/* Check if a hook array entry is ours (current matcher or a known old one). */
1488+
static bool is_cmm_hook_entry(yyjson_mut_val *entry, const char *matcher_str,
1489+
const char *const *old_matchers) {
14771490
yyjson_mut_val *matcher = yyjson_mut_obj_get(entry, "matcher");
14781491
if (!matcher || !yyjson_mut_is_str(matcher)) {
14791492
return false;
@@ -1486,8 +1499,8 @@ static bool is_cmm_hook_entry(yyjson_mut_val *entry, const char *matcher_str) {
14861499
return true;
14871500
}
14881501
/* Also match old versions for backwards-compatible upgrade */
1489-
for (int i = 0; cmm_old_matchers[i]; i++) {
1490-
if (strcmp(val, cmm_old_matchers[i]) == 0) {
1502+
for (int i = 0; old_matchers && old_matchers[i]; i++) {
1503+
if (strcmp(val, old_matchers[i]) == 0) {
14911504
return true;
14921505
}
14931506
}
@@ -1501,12 +1514,15 @@ typedef struct {
15011514
const char *hook_event;
15021515
const char *matcher_str;
15031516
const char *command_str;
1517+
const char *const *old_matchers; /* NULL-terminated; may be NULL */
1518+
int timeout_sec; /* >0 adds "timeout" to the hook entry */
15041519
} hooks_upsert_args_t;
15051520
static int upsert_hooks_json(hooks_upsert_args_t args) {
15061521
const char *settings_path = args.settings_path;
15071522
const char *hook_event = args.hook_event;
15081523
const char *matcher_str = args.matcher_str;
15091524
const char *command_str = args.command_str;
1525+
const char *const *old_matchers = args.old_matchers;
15101526
if (!settings_path) {
15111527
return CLI_ERR;
15121528
}
@@ -1549,7 +1565,7 @@ static int upsert_hooks_json(hooks_upsert_args_t args) {
15491565
size_t max;
15501566
yyjson_mut_val *item;
15511567
yyjson_mut_arr_foreach(event_arr, idx, max, item) {
1552-
if (is_cmm_hook_entry(item, matcher_str)) {
1568+
if (is_cmm_hook_entry(item, matcher_str, old_matchers)) {
15531569
yyjson_mut_arr_remove(event_arr, idx);
15541570
break;
15551571
}
@@ -1563,6 +1579,9 @@ static int upsert_hooks_json(hooks_upsert_args_t args) {
15631579
yyjson_mut_val *hook_obj = yyjson_mut_obj(mdoc);
15641580
yyjson_mut_obj_add_str(mdoc, hook_obj, "type", "command");
15651581
yyjson_mut_obj_add_str(mdoc, hook_obj, "command", command_str);
1582+
if (args.timeout_sec > 0) {
1583+
yyjson_mut_obj_add_int(mdoc, hook_obj, "timeout", args.timeout_sec);
1584+
}
15661585
yyjson_mut_arr_append(hooks_arr, hook_obj);
15671586
yyjson_mut_obj_add_val(mdoc, entry, "hooks", hooks_arr);
15681587

@@ -1579,11 +1598,13 @@ typedef struct {
15791598
const char *settings_path;
15801599
const char *hook_event;
15811600
const char *matcher_str;
1601+
const char *const *old_matchers; /* NULL-terminated; may be NULL */
15821602
} hooks_remove_args_t;
15831603
static int remove_hooks_json(hooks_remove_args_t args) {
15841604
const char *settings_path = args.settings_path;
15851605
const char *hook_event = args.hook_event;
15861606
const char *matcher_str = args.matcher_str;
1607+
const char *const *old_matchers = args.old_matchers;
15871608
if (!settings_path) {
15881609
return CLI_ERR;
15891610
}
@@ -1618,7 +1639,7 @@ static int remove_hooks_json(hooks_remove_args_t args) {
16181639
size_t max;
16191640
yyjson_mut_val *item;
16201641
yyjson_mut_arr_foreach(event_arr, idx, max, item) {
1621-
if (is_cmm_hook_entry(item, matcher_str)) {
1642+
if (is_cmm_hook_entry(item, matcher_str, old_matchers)) {
16221643
yyjson_mut_arr_remove(event_arr, idx);
16231644
break;
16241645
}
@@ -1630,20 +1651,40 @@ static int remove_hooks_json(hooks_remove_args_t args) {
16301651
}
16311652

16321653
int cbm_upsert_claude_hooks(const char *settings_path) {
1633-
return upsert_hooks_json(
1634-
(hooks_upsert_args_t){settings_path, "PreToolUse", CMM_HOOK_MATCHER, CMM_HOOK_COMMAND});
1654+
return upsert_hooks_json((hooks_upsert_args_t){
1655+
.settings_path = settings_path,
1656+
.hook_event = "PreToolUse",
1657+
.matcher_str = CMM_HOOK_MATCHER,
1658+
.command_str = CMM_HOOK_COMMAND,
1659+
.old_matchers = cmm_claude_old_matchers,
1660+
.timeout_sec = CMM_HOOK_TIMEOUT_SEC,
1661+
});
16351662
}
16361663

16371664
int cbm_remove_claude_hooks(const char *settings_path) {
1638-
return remove_hooks_json((hooks_remove_args_t){settings_path, "PreToolUse", CMM_HOOK_MATCHER});
1639-
}
1640-
1641-
/* Install the code discovery gate script to ~/.claude/hooks/.
1642-
* Blocks the first Grep/Glob/Read/Search call per session (exit 2 + stderr),
1643-
* nudging Claude toward codebase-memory-mcp. All subsequent calls in the same
1644-
* session pass through (gate file keyed on PPID). */
1645-
static void cbm_install_hook_gate_script(const char *home) {
1646-
if (!home) {
1665+
return remove_hooks_json((hooks_remove_args_t){
1666+
.settings_path = settings_path,
1667+
.hook_event = "PreToolUse",
1668+
.matcher_str = CMM_HOOK_MATCHER,
1669+
.old_matchers = cmm_claude_old_matchers,
1670+
});
1671+
}
1672+
1673+
/* Install the search-augmenter shim to ~/.claude/hooks/.
1674+
* The shim is a thin wrapper that delegates to `<binary> hook-augment`,
1675+
* which adds graph context to Grep/Glob calls. It NEVER blocks a tool call:
1676+
* a missing/old/hung binary results in a silent exit 0 (issue #362/#288).
1677+
* The legacy filename `cbm-code-discovery-gate` is retained so existing
1678+
* settings.json entries and uninstall keep working with zero migration. */
1679+
static void cbm_install_hook_gate_script(const char *home, const char *binary_path) {
1680+
if (!home || !binary_path) {
1681+
return;
1682+
}
1683+
/* Defensive: refuse to embed a binary path containing a double-quote, which
1684+
* would break the BIN="..." shell quoting in the generated shim. In normal
1685+
* installs this is unreachable (paths come from cbm_detect_self_path), but
1686+
* fail-loud here beats silently emitting a malformed script. */
1687+
if (strchr(binary_path, '"') != NULL) {
16471688
return;
16481689
}
16491690
char hooks_dir[CLI_BUF_1K];
@@ -1657,22 +1698,18 @@ static void cbm_install_hook_gate_script(const char *home) {
16571698
if (!f) {
16581699
return;
16591700
}
1660-
(void)fprintf(f, "#!/bin/bash\n"
1661-
"# Gate hook: nudges Claude toward codebase-memory-mcp for code discovery.\n"
1662-
"# First Grep/Glob/Read/Search per session -> block. Subsequent -> allow.\n"
1663-
"# PPID = Claude Code process PID, unique per session.\n"
1664-
"GATE=/tmp/cbm-code-discovery-gate-$PPID\n"
1665-
"find /tmp -name 'cbm-code-discovery-gate-*' -mtime +1 -delete 2>/dev/null\n"
1666-
"if [ -f \"$GATE\" ]; then\n"
1667-
" exit 0\n"
1668-
"fi\n"
1669-
"touch \"$GATE\"\n"
1670-
"echo 'BLOCKED: For code discovery, use codebase-memory-mcp tools first: "
1671-
"search_graph(name_pattern) to find functions/classes, trace_path() for "
1672-
"call chains, get_code_snippet(qualified_name) to read source. If the graph "
1673-
"is not indexed yet, call index_repository first. Fall back to Grep/Glob/Read "
1674-
"only for text content search. If you need Grep, retry.' >&2\n"
1675-
"exit 2\n");
1701+
(void)fprintf(
1702+
f,
1703+
"#!/bin/bash\n"
1704+
"# codebase-memory-mcp search augmenter (Claude Code PreToolUse).\n"
1705+
"# NOTE: the legacy filename is kept for zero-migration upgrades.\n"
1706+
"# Despite the name this NEVER blocks a tool call - it only adds\n"
1707+
"# graph context. Any failure is silent (exit 0, no output).\n"
1708+
"BIN=\"%s\"\n"
1709+
"[ -x \"$BIN\" ] || exit 0\n"
1710+
"\"$BIN\" hook-augment 2>/dev/null\n"
1711+
"exit 0\n",
1712+
binary_path);
16761713
/* fchmod before close to avoid TOCTOU race (CodeQL cpp/toctou-race-condition) */
16771714
#ifndef _WIN32
16781715
fchmod(fileno(f), CLI_OCTAL_PERM);
@@ -1710,11 +1747,12 @@ static void cbm_install_session_reminder_script(const char *home) {
17101747
"1. ALWAYS use codebase-memory-mcp tools FIRST for ANY code exploration:\n"
17111748
" - search_graph(name_pattern/label/qn_pattern) to find functions/classes/routes\n"
17121749
" - trace_path(function_name, mode=calls|data_flow|cross_service) for call chains\n"
1713-
" - get_code_snippet(qualified_name) to read source (NOT Read/cat)\n"
1750+
" - get_code_snippet(qualified_name) for exact symbol source (precise ranges)\n"
17141751
" - query_graph(query) for complex Cypher patterns\n"
17151752
" - get_architecture(aspects) for project structure\n"
17161753
" - search_code(pattern) for text search (graph-augmented grep)\n"
1717-
"2. Fall back to Grep/Glob/Read ONLY for text content, config values, non-code files.\n"
1754+
"2. Use Grep/Glob/Read freely for text, configs, non-code files, and\n"
1755+
" always Read a file before editing it.\n"
17181756
"3. If a project is not indexed yet, run index_repository FIRST.\n"
17191757
"REMINDER\n");
17201758
#ifndef _WIN32
@@ -1730,8 +1768,10 @@ static int cbm_upsert_session_hooks(const char *settings_path) {
17301768
static const char *matchers[] = {"startup", "resume", "clear", "compact"};
17311769
int rc = 0;
17321770
for (int i = 0; i < NUM_DIRS; i++) {
1733-
if (upsert_hooks_json((hooks_upsert_args_t){settings_path, "SessionStart", matchers[i],
1734-
CMM_SESSION_COMMAND}) != 0) {
1771+
if (upsert_hooks_json((hooks_upsert_args_t){.settings_path = settings_path,
1772+
.hook_event = "SessionStart",
1773+
.matcher_str = matchers[i],
1774+
.command_str = CMM_SESSION_COMMAND}) != 0) {
17351775
rc = CLI_ERR;
17361776
}
17371777
}
@@ -1742,27 +1782,39 @@ static int cbm_remove_session_hooks(const char *settings_path) {
17421782
static const char *matchers[] = {"startup", "resume", "clear", "compact"};
17431783
int rc = 0;
17441784
for (int i = 0; i < NUM_DIRS; i++) {
1745-
if (remove_hooks_json((hooks_remove_args_t){settings_path, "SessionStart", matchers[i]}) !=
1746-
0) {
1785+
if (remove_hooks_json((hooks_remove_args_t){.settings_path = settings_path,
1786+
.hook_event = "SessionStart",
1787+
.matcher_str = matchers[i]}) != 0) {
17471788
rc = CLI_ERR;
17481789
}
17491790
}
17501791
return rc;
17511792
}
17521793

1753-
#define GEMINI_HOOK_MATCHER "google_search|read_file|grep_search"
1794+
/* Matcher excludes read_file for consistency with the Claude fix: the hook
1795+
* is an advisory reminder, not a gate over the agent's file reads. */
1796+
#define GEMINI_HOOK_MATCHER "google_search|grep_search"
17541797
#define GEMINI_HOOK_COMMAND \
17551798
"echo 'Reminder: prefer codebase-memory-mcp search_graph/trace_path/" \
17561799
"get_code_snippet over grep/file search for code discovery.' >&2"
17571800

17581801
int cbm_upsert_gemini_hooks(const char *settings_path) {
1759-
return upsert_hooks_json((hooks_upsert_args_t){settings_path, "BeforeTool", GEMINI_HOOK_MATCHER,
1760-
GEMINI_HOOK_COMMAND});
1802+
return upsert_hooks_json((hooks_upsert_args_t){
1803+
.settings_path = settings_path,
1804+
.hook_event = "BeforeTool",
1805+
.matcher_str = GEMINI_HOOK_MATCHER,
1806+
.command_str = GEMINI_HOOK_COMMAND,
1807+
.old_matchers = cmm_gemini_old_matchers,
1808+
});
17611809
}
17621810

17631811
int cbm_remove_gemini_hooks(const char *settings_path) {
1764-
return remove_hooks_json(
1765-
(hooks_remove_args_t){settings_path, "BeforeTool", GEMINI_HOOK_MATCHER});
1812+
return remove_hooks_json((hooks_remove_args_t){
1813+
.settings_path = settings_path,
1814+
.hook_event = "BeforeTool",
1815+
.matcher_str = GEMINI_HOOK_MATCHER,
1816+
.old_matchers = cmm_gemini_old_matchers,
1817+
});
17661818
}
17671819

17681820
/* ── PATH management ──────────────────────────────────────────── */
@@ -2654,11 +2706,11 @@ static void install_claude_code_config(const char *home, const char *binary_path
26542706
snprintf(settings_path, sizeof(settings_path), "%s/.claude/settings.json", home);
26552707
if (!dry_run) {
26562708
cbm_upsert_claude_hooks(settings_path);
2657-
cbm_install_hook_gate_script(home);
2709+
cbm_install_hook_gate_script(home, binary_path);
26582710
cbm_install_session_reminder_script(home);
26592711
cbm_upsert_session_hooks(settings_path);
26602712
}
2661-
printf(" hooks: PreToolUse (code discovery gate)\n");
2713+
printf(" hooks: PreToolUse (Grep/Glob search-graph augmenter, non-blocking)\n");
26622714
printf(" hooks: SessionStart (MCP usage reminder on startup/resume/clear/compact)\n");
26632715
}
26642716

‎src/cli/cli.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,10 @@ int cbm_cmd_update(int argc, char **argv);
260260
/* config: get/set/list/reset runtime config values. */
261261
int cbm_cmd_config(int argc, char **argv);
262262

263+
/* hook-augment: stdin-driven Claude Code PreToolUse augmenter.
264+
* Reads the hook JSON from stdin and emits hookSpecificOutput.additionalContext
265+
* with search_graph hits for Grep/Glob calls. NEVER blocks: every failure
266+
* path returns 0 with no stdout output. */
267+
int cbm_cmd_hook_augment(void);
268+
263269
#endif /* CBM_CLI_H */

0 commit comments

Comments
 (0)