Skip to content

Instantly share code, notes, and snippets.

@smarteist
Last active September 4, 2026 09:20
Show Gist options
  • Select an option

  • Save smarteist/5c54adbd6008f29aca12e4c9e34a95b9 to your computer and use it in GitHub Desktop.

Select an option

Save smarteist/5c54adbd6008f29aca12e4c9e34a95b9 to your computer and use it in GitHub Desktop.
RTK for Antigravity CLI setup
#!/usr/bin/env bash
set -euo pipefail
CLI_SETTINGS_DIR="$HOME/.gemini/antigravity-cli"
SETTINGS_FILE="$CLI_SETTINGS_DIR/settings.json"
HOOKS_DIR="$HOME/.gemini/hooks"
SCRIPT_FILE="$HOOKS_DIR/rtk-hook-agy.sh"
# Ensure jq is installed
if ! command -v jq >/dev/null 2>&1; then
echo "Error: jq is required to merge settings.json" >&2
exit 1
fi
mkdir -p "$CLI_SETTINGS_DIR" "$HOOKS_DIR"
# 1. Write the hook script
cat <<'EOF' > "$SCRIPT_FILE"
#!/usr/bin/env bash
set -euo pipefail
PAYLOAD=$(cat)
if command -v rtk >/dev/null 2>&1; then
echo "$PAYLOAD" | rtk hook gemini >/dev/null 2>&1 || true
fi
cat <<JSON
{
"decision": "allow"
}
JSON
EOF
chmod +x "$SCRIPT_FILE"
# 2. Initialize settings.json if missing
if [[ ! -f "$SETTINGS_FILE" ]]; then
echo "{}" > "$SETTINGS_FILE"
fi
# 3. Merge hook entry into settings.json preserving existing keys
TMP_FILE=$(mktemp)
jq --arg cmd "$SCRIPT_FILE" '
.hooks["rtk-interceptor"] = {
"PreToolUse": [
{
"matcher": "run_command",
"hooks": [
{
"type": "command",
"command": $cmd,
"timeout": 15
}
]
}
]
}
' "$SETTINGS_FILE" > "$TMP_FILE"
mv "$TMP_FILE" "$SETTINGS_FILE"
chmod 644 "$SETTINGS_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment