Skip to content

fix(ContextSearch): resolve ripgrep when no real rg binary exists#1486

Closed
anikinsasha wants to merge 1 commit into
danielmiessler:mainfrom
anikinsasha:fix/contextsearch-rg-fallback
Closed

fix(ContextSearch): resolve ripgrep when no real rg binary exists#1486
anikinsasha wants to merge 1 commit into
danielmiessler:mainfrom
anikinsasha:fix/contextsearch-rg-fallback

Conversation

@anikinsasha

Copy link
Copy Markdown

Problem

ContextSearch's ripgrep() helper spawns rg via Bun.spawn. Claude Code's shell integration provides rg as a shell function wrapping the CLI's embedded ripgrep (ARGV0=rg "$CLAUDE_CODE_EXECPATH"), which Bun.spawn cannot see. On machines without a standalone ripgrep install this makes every rg-backed source (ISA bodies, conversation logs) die with:

ContextSearch error: Executable not found in $PATH: "rg"

— so the tool exits 1 on every query, silently losing two of its five sources' coverage. Easy to miss because machines with brew install ripgrep never hit it.

Fix

Resolve the binary at spawn time:

  1. A real rg on PATH (Bun.which) — used as before; zero behavior change for machines that have ripgrep.
  2. Fallback: run the Claude Code executable (CLAUDE_CODE_EXECPATH or ~/.local/bin/claude) with argv0: "rg" — the same mechanism the shell function uses to expose the embedded ripgrep.
  3. Last resort: original "rg" literal, preserving the original error if neither exists.

Testing

On a machine with no ripgrep binary (only the shell function): before the patch, every query exits 1 with the error above; after the patch, all five sources return results (verified against live MEMORY/WORK ISAs and conversation JSONLs, ~1s wall time). On a machine with real ripgrep, Bun.which("rg") short-circuits and behavior is byte-identical.

Claude Code's shell integration provides rg as a shell function wrapping its
embedded ripgrep. Bun.spawn cannot see shell functions, so on machines without
a standalone ripgrep install, every rg-backed source (ISA bodies, conversation
logs) fails with 'Executable not found in $PATH: rg' and ContextSearch exits 1.

Resolve the binary at spawn time: prefer a real rg on PATH (Bun.which), fall
back to the Claude Code executable run with argv0=rg — the same mechanism the
shell function uses. No behavior change on machines that have ripgrep installed.
@danielmiessler

Copy link
Copy Markdown
Owner

Ported to the private source tree essentially verbatim, with credit. The shell-function-invisible-to-Bun.spawn diagnosis was spot on, and the argv0="rg" trick mirroring what the shell integration does is clean. Verified ISA-body and conversation-log search working after the port.

Closing because the public repo is generated from private source at release time; your fix ships in the next release, credited in the commit. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants