Shell interception hook: answer grep/rg/cat on indexed code via code-index and record real fallbacks (zero-fallback) #560

Closed
opened 2026-11-09 12:29:11 +01:00 by buildagent · 1 comment
Member

Part of the zero-fallback epic (#555). Cause: habit. The shell is the first thing an agent's training reaches for.

Proposal

An optional agent-harness hook (Claude Code PreToolUse on Bash; equivalent for Codex if feasible), shipped beside the existing blast-radius hook (crates/cli/src/hooks/blast_radius.py) and using the 24 ms code-index query CLI:

  • It recognises grep/rg/cat/sed -n/head on paths the index covers (index_coverage semantics) and answers it with code-index directly. The hook returns the equivalent code-index result, plus the one-line tool call that would have produced it, so the next lookup goes direct.
  • It never blocks non-code shell use (logs, git log, cargo) and never blocks when code-index cannot answer. In that case it lets the command run and appends a fallback record (the sub-issue-1 format), so the gap gets measured.
  • It can be turned off per session.

Acceptance

  • Hook test: rg -n foo crates/ on an indexed tree → the reply comes from code-index with the suggested call. rg foo target/ passes through.
  • The fallback rate on the benchmark drops measurably with the hook on. The hook adds ≤ 50 ms p95.
Part of the zero-fallback epic (#555). Cause: **habit.** The shell is the first thing an agent's training reaches for. ## Proposal An optional agent-harness hook (Claude Code `PreToolUse` on `Bash`; equivalent for Codex if feasible), shipped beside the existing blast-radius hook (`crates/cli/src/hooks/blast_radius.py`) and using the 24 ms `code-index query` CLI: - It recognises `grep`/`rg`/`cat`/`sed -n`/`head` on paths the index covers (`index_coverage` semantics) and answers it with code-index directly. The hook returns the equivalent code-index result, plus the one-line tool call that would have produced it, so the next lookup goes direct. - It never blocks non-code shell use (logs, git log, cargo) and never blocks when code-index cannot answer. In that case it lets the command run and appends a fallback record (the sub-issue-1 format), so the gap gets measured. - It can be turned off per session. ## Acceptance - Hook test: `rg -n foo crates/` on an indexed tree → the reply comes from code-index with the suggested call. `rg foo target/` passes through. - The fallback rate on the benchmark drops measurably with the hook on. The hook adds ≤ 50 ms p95.
Author
Member

Merged into #571.
No shell translation hook is implemented; the old rules/hook installer was removed in v0.41.49 (crates/cli/src/skill.rs is the opt-in skill path).
Remaining: Optional shell hook, subject to the operator’s channel decision and real-agent measurement.

Merged into #571. No shell translation hook is implemented; the old rules/hook installer was removed in v0.41.49 (crates/cli/src/skill.rs is the opt-in skill path). Remaining: Optional shell hook, subject to the operator’s channel decision and real-agent measurement.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
h-dv/code-index#560
No description provided.