rtk icon indicating copy to clipboard operation
rtk copied to clipboard

Gemini CLI --yolo to read files, it uses the read_file tool

Open generik0 opened this issue 8 months ago • 3 comments

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?

generik0 avatar Mar 24 '26 10:03 generik0

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 fix to attempt it.


Triaged automatically by wshm · This is an automated analysis, not a human review.

pszymkowiak avatar Mar 24 '26 10:03 pszymkowiak

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:

  1. Reads the file and applies RTK's existing FilterLevel::Minimal filter (same engine used by rtk read)
  2. Writes the filtered content to a temp file at ~/.local/share/rtk/filtered/
  3. Redirects Gemini to read the temp file via hookSpecificOutput.tool_input.file_path
  4. 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
  5. Safe fallbacks — binary/unreadable files, small files (<500 chars), and files with negligible savings (<10%) are passed through unchanged
  6. Temp file rotation — keeps last 20 filtered files, mirroring the existing tee.rs pattern

No new dependencies. All 1094 tests pass.

Ross-cripto avatar Mar 25 '26 08:03 Ross-cripto

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

Ziyad avatar Mar 25 '26 11:03 Ziyad