Skip to content

feat: add Gemini CLI support via rtk init --gemini#573

Open
ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
ousamabenyounes:feat/gemini-support-v2
Open

feat: add Gemini CLI support via rtk init --gemini#573
ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
ousamabenyounes:feat/gemini-support-v2

Conversation

@ousamabenyounes
Copy link
Contributor

Summary

Replaces #174 (too many conflicts after upstream restructuring). Clean implementation on latest develop.

  • rtk hook gemini: Native Rust hook processor for Gemini CLI BeforeTool hooks. Reads JSON from stdin, delegates to rewrite_command() (single source of truth — no duplicate rewrite logic), outputs Gemini-format JSON response.
  • rtk init -g --gemini: Installs hook wrapper (~/.gemini/hooks/rtk-hook-gemini.sh), GEMINI.md, and patches ~/.gemini/settings.json.
  • rtk init -g --gemini --uninstall: Clean removal of all Gemini artifacts.

Key design decisions

  1. Reuses rewrite_command() from discover/registry.rs instead of duplicating rewrite rules (unlike the old PR). One source of truth for all hook engines.
  2. Thin shell wrapper (exec rtk hook gemini) keeps the hook script minimal and testable — all logic is in Rust.
  3. Additive only — no changes to existing Claude Code or OpenCode hooks. --gemini is a new opt-in flag.

Files changed

File Change
src/hook_cmd.rs New module — Gemini BeforeTool hook processor
src/main.rs --gemini flag, Hook subcommand routing
src/init.rs run_gemini(), patch_gemini_settings(), uninstall_gemini()
README.md Gemini CLI section

Test plan

  • cargo fmt --all --check — OK
  • cargo clippy --all-targets — 0 new warnings
  • cargo test — 905 passed, 3 ignored
  • 6 unit tests in hook_cmd.rs covering hook format, rewrite delegation, env prefix, exclusions
  • Manual: rtk init -g --gemini on a machine with Gemini CLI installed
  • Manual: verify git status is rewritten in Gemini CLI session

Closes #174

🤖 Generated with Claude Code

- Add `rtk hook gemini` command: native Rust hook processor for Gemini CLI
  BeforeTool hooks. Reads JSON from stdin, delegates to `rewrite_command()`
  (single source of truth), outputs Gemini-format JSON response.
- Add `--gemini` flag to `rtk init`: installs hook wrapper script, GEMINI.md,
  and patches ~/.gemini/settings.json with BeforeTool hook entry.
- Add `rtk init -g --gemini --uninstall`: clean removal of all Gemini artifacts.
- 6 unit tests covering hook format, rewrite delegation, and exclusions.

Replaces PR rtk-ai#174 which had too many conflicts after upstream restructuring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
@ousamabenyounes
Copy link
Contributor Author

Live testing on Gemini CLI ✅

Tested on Gemini CLI 0.32.1 (Linux) — hook works end-to-end:

Setup:

rtk init -g --gemini --auto-patch
# → Hook: ~/.gemini/hooks/rtk-hook-gemini.sh
# → GEMINI.md installed
# → settings.json patched with BeforeTool hook

Result: Gemini types git status, hook rewrites to rtk git status — compact output returned:

┌─ Shell: rtk git status ──────────────────────────────────┐
│ 📌 feat-live-translate...origin/feat-live-translate      │
│ 📝 Modified: 1 files                                    │
│    Caddyfile                                             │
└──────────────────────────────────────────────────────────┘

3 lines instead of ~15 — standard RTK compression.

Hook processor verified with all command families:

Input Rewritten Status
git status rtk git status
cargo test rtk cargo test
RUST_LOG=debug cargo build RUST_LOG=debug rtk cargo build ✅ env prefix preserved
rtk git log passthrough (no double rewrite)
echo hello {"decision":"allow"} (no rewrite)
non-shell tool (read_file) {"decision":"allow"} (ignored)

Install/uninstall cycle:

  • rtk init -g --gemini --auto-patch → creates hook + GEMINI.md + patches settings.json ✅
  • Re-run → idempotent (no duplicate hook entry) ✅
  • rtk init -g --gemini --uninstall → removes all 3 artifacts cleanly ✅
  • Re-install after uninstall → works correctly ✅

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.

1 participant