@@ -243,6 +243,20 @@ static void ha_emit(const char *text) {
243243 yyjson_mut_doc_free (doc );
244244}
245245
246+ /* True for an absolute path we can walk up: POSIX "/..." or a Windows drive
247+ * root — "X:/..." or a bare "X:" (callers normalize '\\' to '/' first).
248+ * Declared in cli.h so the Windows drive-letter handling (#618) has direct
249+ * regression coverage. */
250+ bool cbm_hook_path_is_abs (const char * d ) {
251+ if (!d || !d [0 ]) {
252+ return false;
253+ }
254+ if (d [0 ] == '/' ) {
255+ return true;
256+ }
257+ return isalpha ((unsigned char )d [0 ]) && d [1 ] == ':' && (d [2 ] == '/' || d [2 ] == '\0' );
258+ }
259+
246260/* Walk up from `start`, deriving a project name at each level and querying
247261 * search_graph until an indexed project is found (or the walk is exhausted).
248262 * Stops at the first non-error result: a valid project with zero hits is a
@@ -251,7 +265,7 @@ static char *ha_resolve_and_query(cbm_mcp_server_t *srv, const char *start, cons
251265 char dir [4096 ];
252266 snprintf (dir , sizeof (dir ), "%s" , start );
253267
254- for (int level = 0 ; level < HA_MAX_WALKUP && dir [ 0 ] == '/' ; level ++ ) {
268+ for (int level = 0 ; level < HA_MAX_WALKUP && cbm_hook_path_is_abs ( dir ) ; level ++ ) {
255269 char * project = cbm_project_name_from_path (dir );
256270 if (project ) {
257271 char * args = ha_build_args (project , token );
@@ -275,7 +289,10 @@ static char *ha_resolve_and_query(cbm_mcp_server_t *srv, const char *start, cons
275289 /* Not indexed at this level — climb to the parent. */
276290 char * slash = strrchr (dir , '/' );
277291 if (!slash || slash == dir ) {
278- break ;
292+ break ; /* POSIX root "/" */
293+ }
294+ if (slash == dir + 2 && dir [1 ] == ':' ) {
295+ break ; /* Windows drive root "X:/" — don't strip to "X:" */
279296 }
280297 * slash = '\0' ;
281298 }
@@ -313,9 +330,9 @@ int cbm_cmd_hook_augment(void) {
313330 }
314331
315332 const char * cwd = ha_obj_str (root , "cwd" );
316- #ifndef _WIN32
317333 char cwdbuf [4096 ];
318- if (!cwd || cwd [0 ] != '/' ) {
334+ #ifndef _WIN32
335+ if (!cwd || !cbm_hook_path_is_abs (cwd )) {
319336 if (!getcwd (cwdbuf , sizeof (cwdbuf ))) {
320337 yyjson_doc_free (doc );
321338 free (input );
@@ -324,10 +341,20 @@ int cbm_cmd_hook_augment(void) {
324341 cwd = cwdbuf ;
325342 }
326343#else
327- /* Windows: Claude Code passes cwd in the hook payload. The walk-up loop
328- * below requires POSIX-style absolute paths ('/'-prefixed), so without a
329- * usable cwd there is nothing to augment — fail open cleanly. */
330- if (!cwd || cwd [0 ] != '/' ) {
344+ /* Windows: Claude Code passes an absolute drive-letter cwd in the hook
345+ * payload (e.g. C:\repo). Normalize '\\' -> '/' and require an absolute
346+ * path; the walk-up loop handles POSIX and "X:/..." roots alike. Without
347+ * a usable cwd there is nothing to augment — fail open cleanly. */
348+ if (cwd ) {
349+ snprintf (cwdbuf , sizeof (cwdbuf ), "%s" , cwd );
350+ for (char * p = cwdbuf ; * p ; p ++ ) {
351+ if (* p == '\\' ) {
352+ * p = '/' ;
353+ }
354+ }
355+ cwd = cwdbuf ;
356+ }
357+ if (!cwd || !cbm_hook_path_is_abs (cwd )) {
331358 yyjson_doc_free (doc );
332359 free (input );
333360 return 0 ;
0 commit comments