Gemini CLI --yolo to read files, it uses the read_file tool
RTK only registers a BeforeTool hook on run_shell_command. But when Gemini CLI uses --yolo to read files, it uses the read_file tool
Can we extend rtk to hook into read_file also?
wshm · Automated triage by AI
🔍 Automated Triage
| ✨ Category | feature |
| 🟢 Priority | low |
| 🎯 Confidence | 92% |
Summary
Request to extend RTK's BeforeTool hook to cover read_file in addition to run_shell_command; PR #806 already in progress.
This looks like a simple fix that could be auto-resolved. Repo maintainers can use
/wshm fixto attempt it.
Triaged automatically by wshm · This is an automated analysis, not a human review.
Hey, picked this up and have a working fix ready.
run_gemini() had a hard guard that exited immediately for any tool that wasn't run_shell_command, so read_file was always passed through untouched — RTK never saw it.
What the fix does
Extends the Gemini BeforeTool hook to intercept read_file alongside run_shell_command:
- Reads the file and applies RTK's existing
FilterLevel::Minimalfilter (same engine used byrtk read) - Writes the filtered content to a temp file at
~/.local/share/rtk/filtered/ - Redirects Gemini to read the temp file via
hookSpecificOutput.tool_input.file_path - Correctly handles
start_line/end_line— the slice is pre-applied before filtering, and both fields are overridden in the response to prevent Gemini's merge from re-applying the original (now wrong) line numbers to the filtered file - Safe fallbacks — binary/unreadable files, small files (<500 chars), and files with negligible savings (<10%) are passed through unchanged
- Temp file rotation — keeps last 20 filtered files, mirroring the existing
tee.rspattern
No new dependencies. All 1094 tests pass.
If we disable the tools (read_file, read_many_files) via policy/config then Gemini will fallback to using run_shell_command therefore using conventional shell commands and hitting the RTK hook path