Official Technical Documentation
Gemini CLI Chatbot Documentation
Detailed documentation covering pure Bash Server-Sent Events stream chunk parsing, REST JSON construction, and Unix stdin piping workflows.
Gemini CLI Architecture Overview
Gemini CLI is an open-source terminal interface for Google's Gemini models built entirely using POSIX Shell / Bash, curl, and jq. It requires no Python or Node.js runtime, ensuring sub-second startup times and less than 1 MB of memory usage.
RuntimePure Bash 4.x + curl + jq
Models Supportedgemini-1.5-flash, gemini-1.5-pro
Streaming ProtocolServer-Sent Events (SSE) Chunk Parser
Memory Usage< 0.8 MB RAM footprint
API Key Setup & Verification
Obtain a Google Gemini API Key from Google AI Studio and configure your shell environment:
# Temporary session export
export GEMINI_API_KEY="AIzaSyYourSecretKeyHere"
# Permanent shell export (add to ~/.bashrc or ~/.zshrc)
echo 'export GEMINI_API_KEY="AIzaSyYourSecretKeyHere"' >> ~/.bashrc
source ~/.bashrc
# Test connectivity
./gemini.sh "Hello Gemini, are you online?"
Pure Bash SSE Streaming Parser
The script uses curl --no-buffer -N -s connected directly to a while-read stream parser:
# Streaming line processor
curl -s -N -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" | while IFS= read -r line; do
if [[ "$line" =~ ^data:\ (.*) ]]; then
token=$(echo "${BASH_REMATCH[1]}" | jq -r '.candidates[0].content.parts[0].text // empty')
printf "%s" "$token"
fi
done
Interactive REPL Commands
| Command | Description |
|---|---|
/clear | Clears active terminal screen and memory context |
/model <name> | Switches model (e.g. /model gemini-1.5-pro) |
/save <file> | Exports conversation transcript to Markdown |
/tokens | Displays current session token usage metrics |
/system <prompt> | Updates the active system instruction dynamically |
/exit | Safely exits the session and saves session log |
Unix Piping Workflows
Automate terminal diagnostics by piping standard output into Gemini CLI:
# 1. Analyze git diff before committing
git diff | gemini "Review this diff and suggest a conventional commit message"
# 2. Diagnose failing systemd service
journalctl -u nginx.service -n 50 --no-pager | gemini "Explain the root cause of this failure"
# 3. Refactor code file
cat script.py | gemini "Refactor with type annotations and docstrings" > script_clean.py
Troubleshooting & FAQ
Error: jq command not found
Install jq using your package manager:
sudo apt install jq or brew install jq.
HTTP 429 Too Many Requests
You have exceeded Google API rate limits. Switch to
gemini-1.5-flash for higher RPM allowances.