<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Terminal-Agent on RockB</title><link>https://baeseokjae.github.io/tags/terminal-agent/</link><description>Recent content in Terminal-Agent on RockB</description><image><title>RockB</title><url>https://baeseokjae.github.io/images/og-default.png</url><link>https://baeseokjae.github.io/images/og-default.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 23 May 2026 04:15:40 +0000</lastBuildDate><atom:link href="https://baeseokjae.github.io/tags/terminal-agent/index.xml" rel="self" type="application/rss+xml"/><item><title>Google Agentic Terminal Agent 2026: ReAct Loop + MCP + 1M Context Setup Guide</title><link>https://baeseokjae.github.io/posts/google-agentic-terminal-agent-guide-2026/</link><pubDate>Sat, 23 May 2026 04:15:40 +0000</pubDate><guid>https://baeseokjae.github.io/posts/google-agentic-terminal-agent-guide-2026/</guid><description>Complete setup guide for Gemini CLI as an agentic terminal agent — ReAct loop internals, MCP server config, and 1M token context window best practices.</description><content:encoded><![CDATA[<p>Gemini CLI is Google&rsquo;s open-source agentic terminal agent built on Gemini 2.5 Pro, offering a 1M token context window, a native ReAct reasoning loop, and MCP server integration — free at 1,000 requests/day with a personal Google account. Here&rsquo;s the complete setup and configuration guide for 2026.</p>
<h2 id="what-is-gemini-cli-googles-open-source-agentic-terminal-agent">What Is Gemini CLI? Google&rsquo;s Open-Source Agentic Terminal Agent</h2>
<p>Gemini CLI is a command-line interface that wraps Gemini 2.5 Pro&rsquo;s reasoning capabilities into an autonomous coding agent capable of reading files, running shell commands, calling external tools, and iterating on errors — all from your terminal. Unlike a simple chat interface, Gemini CLI implements a full ReAct (Reason-and-Act) loop where the model reasons about a goal, selects a tool, executes it, observes the result, and continues reasoning until the task is complete. Released in late 2025 and significantly updated in early 2026, it supports MCP (Model Context Protocol) for extending its toolset, and ships with built-in capabilities for Google Search grounding, file operations, and web fetching. The free tier offers 60 requests/minute and 1,000 requests/day with a personal Google account — enough for real development workflows. Gemini 2.5 Pro&rsquo;s 1M token context window is roughly 5x the capacity of standard Claude tiers and 8x that of GPT-4o, enabling full codebase analysis without chunking or RAG pipelines.</p>
<h3 id="how-it-differs-from-traditional-cli-tools">How It Differs From Traditional CLI Tools</h3>
<p>Gemini CLI isn&rsquo;t a shell wrapper or a code completion plugin. It&rsquo;s an autonomous loop: you describe a goal, and the agent plans, executes, observes results, and adapts — handling multi-step workflows that would require manual orchestration with any other tool. A 600K-token Next.js codebase was loaded in a single context window, and Gemini 2.5 Pro correctly identified a cross-module bug spanning four files without chunking. That&rsquo;s not possible with tools capped at 128K or 200K tokens.</p>
<h2 id="inside-the-react-loop-how-gemini-cli-reasons-and-acts">Inside the ReAct Loop: How Gemini CLI Reasons and Acts</h2>
<p>Gemini CLI&rsquo;s agentic core implements a ReAct (Reason + Act) loop that processes every user prompt through a structured cycle: receive input → reason about goal and available tools → select tool → execute → observe output → reason again → repeat until done. This loop is not a fixed workflow — it&rsquo;s a dynamic planning system where the model decides at each step whether to call another tool, ask for clarification, or declare the task complete. Internally, the loop runs through <code>discoverMcpTools()</code>, which iterates configured MCP servers from <code>settings.json</code>, establishes connections, fetches tool definitions, and sanitizes schemas to match Gemini API format. When a shell command fails, the ReAct loop reads the error output and automatically attempts a fix — often correcting syntax errors, missing permissions, or wrong file paths without user intervention. This error-retry mechanism is what separates agentic terminals from simple prompt-and-response chat interfaces. As of 2026, 52% of executives in gen-AI-using organizations report deployed AI agents — and the terminal agent pattern is central to that adoption.</p>
<h3 id="tool-discovery-and-schema-validation">Tool Discovery and Schema Validation</h3>
<p>When Gemini CLI starts, it calls <code>discoverMcpTools()</code> for each server listed under <code>mcpServers</code> in <code>~/.gemini/settings.json</code>. The function opens a transport connection (Stdio, SSE, or HTTP), fetches the <code>tools/list</code> endpoint, and validates each returned schema against Gemini&rsquo;s function-calling spec. Tools with invalid schemas are silently skipped — so if a tool isn&rsquo;t appearing in <code>/mcp</code>, check the server&rsquo;s schema output for missing <code>type</code> fields or malformed JSON. The sanitized tools become available in the reasoning loop exactly like built-in tools.</p>
<h3 id="error-retry-and-self-correction">Error Retry and Self-Correction</h3>
<p>When a command returns a non-zero exit code, Gemini CLI feeds the stderr output back into the reasoning loop. The model reasons about what went wrong, generates a corrected command, and retries — up to a configurable maximum. This means a command like <code>npm install</code> that fails due to a missing <code>.nvmrc</code> will trigger the agent to check the Node version, switch it, and retry — without you intervening. Set <code>maxRetries</code> in <code>settings.json</code> to control this behavior.</p>
<h2 id="installation-and-initial-authentication-setup">Installation and Initial Authentication Setup</h2>
<p>Installing Gemini CLI takes under two minutes on any system with Node.js 18+: install via npm (<code>npm install -g @google/gemini-cli</code>), run <code>gemini</code> to trigger the OAuth flow, and authenticate with your personal Google account. The tool stores OAuth credentials in <code>~/.gemini/credentials.json</code> and reads all configuration from <code>~/.gemini/settings.json</code>. For team or CI environments, set the <code>GEMINI_API_KEY</code> environment variable instead of OAuth — this bypasses free-tier rate limits and routes requests through your billed API quota, which supports higher throughput and removes the 1,000 request/day ceiling. The personal free tier provides 60 requests/minute and 1,000 requests/day at no cost, making it practical for solo development workflows without any payment setup. Plan Mode, MCP server configuration, and context window settings are all managed via <code>settings.json</code> — no separate config command is needed after the initial install.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Install globally</span>
</span></span><span style="display:flex;"><span>npm install -g @google/gemini-cli
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># First run triggers OAuth</span>
</span></span><span style="display:flex;"><span>gemini
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Or set an API key for CI/team use</span>
</span></span><span style="display:flex;"><span>export GEMINI_API_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;your-key-here&#34;</span>
</span></span><span style="display:flex;"><span>gemini <span style="color:#e6db74">&#34;summarize the changes in this PR&#34;</span>
</span></span></code></pre></div><h3 id="verifying-your-setup">Verifying Your Setup</h3>
<p>Run <code>gemini --version</code> to confirm the install, and <code>gemini /tools</code> to see which built-in tools are available. If you&rsquo;ve configured MCP servers, run <code>gemini /mcp</code> to check connection status and list available tools from each server. A healthy output shows each server name, status (<code>connected</code>), and a list of discovered tool names.</p>
<h2 id="configuring-mcp-servers-in-geminisettingsjson">Configuring MCP Servers in ~/.gemini/settings.json</h2>
<p>MCP server configuration lives in <code>~/.gemini/settings.json</code> under the <code>mcpServers</code> block. Each entry names a server and specifies its launch command, arguments, and optional environment variables. Environment variables in the <code>env</code> block are auto-expanded at startup — this is the secure way to inject API keys and credentials without hardcoding them in the config file. To add a server, edit <code>settings.json</code> directly (there&rsquo;s no GUI config tool), then restart Gemini CLI. Use <code>gemini mcp enable &lt;name&gt;</code> and <code>gemini mcp disable &lt;name&gt;</code> to toggle servers without editing the file. Run <code>/mcp</code> inside a session to inspect connection status and confirm tools loaded correctly.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;mcpServers&#34;</span>: {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;filesystem&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;command&#34;</span>: <span style="color:#e6db74">&#34;npx&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;args&#34;</span>: [<span style="color:#e6db74">&#34;-y&#34;</span>, <span style="color:#e6db74">&#34;@modelcontextprotocol/server-filesystem&#34;</span>, <span style="color:#e6db74">&#34;/workspace&#34;</span>],
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;transport&#34;</span>: <span style="color:#e6db74">&#34;stdio&#34;</span>
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;github&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;command&#34;</span>: <span style="color:#e6db74">&#34;npx&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;args&#34;</span>: [<span style="color:#e6db74">&#34;-y&#34;</span>, <span style="color:#e6db74">&#34;@modelcontextprotocol/server-github&#34;</span>],
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;transport&#34;</span>: <span style="color:#e6db74">&#34;stdio&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;env&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;GITHUB_TOKEN&#34;</span>: <span style="color:#e6db74">&#34;${GITHUB_TOKEN}&#34;</span>
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;postgres&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;command&#34;</span>: <span style="color:#e6db74">&#34;npx&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;args&#34;</span>: [<span style="color:#e6db74">&#34;-y&#34;</span>, <span style="color:#e6db74">&#34;@modelcontextprotocol/server-postgres&#34;</span>],
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;transport&#34;</span>: <span style="color:#e6db74">&#34;stdio&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;env&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;DATABASE_URL&#34;</span>: <span style="color:#e6db74">&#34;${DATABASE_URL}&#34;</span>
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h3 id="enabling-and-disabling-servers">Enabling and Disabling Servers</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Toggle without editing settings.json</span>
</span></span><span style="display:flex;"><span>gemini mcp disable github
</span></span><span style="display:flex;"><span>gemini mcp enable github
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Check status in a live session</span>
</span></span><span style="display:flex;"><span>gemini
</span></span><span style="display:flex;"><span>&gt; /mcp
</span></span></code></pre></div><h2 id="transport-options-stdio-vs-sse-vs-streamable-http">Transport Options: Stdio vs SSE vs Streamable HTTP</h2>
<p>Gemini CLI supports three MCP transport protocols, and picking the right one depends on where your server runs and how it handles connections. Stdio is the default and most reliable option for local servers — Gemini CLI spawns the server as a child process, connects via stdin/stdout pipes, and manages the lifecycle automatically. SSE (Server-Sent Events) works for remote servers that push events over HTTP — useful when the MCP server is a persistent service rather than a per-request process. Streamable HTTP is the newest transport, designed for high-throughput scenarios where SSE&rsquo;s uni-directional model is limiting; it uses HTTP/2 streaming and handles bidirectional communication more efficiently. For local tools (filesystem, database, git), use Stdio. For shared team tools or cloud services, use SSE or Streamable HTTP with proper authentication headers.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;mcpServers&#34;</span>: {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;local-tool&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;command&#34;</span>: <span style="color:#e6db74">&#34;node&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;args&#34;</span>: [<span style="color:#e6db74">&#34;./mcp-server.js&#34;</span>],
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;transport&#34;</span>: <span style="color:#e6db74">&#34;stdio&#34;</span>
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;remote-tool&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;url&#34;</span>: <span style="color:#e6db74">&#34;https://tools.example.com/mcp/sse&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;transport&#34;</span>: <span style="color:#e6db74">&#34;sse&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;headers&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;Authorization&#34;</span>: <span style="color:#e6db74">&#34;Bearer ${REMOTE_TOOL_API_KEY}&#34;</span>
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;high-throughput-tool&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;url&#34;</span>: <span style="color:#e6db74">&#34;https://tools.example.com/mcp/stream&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;transport&#34;</span>: <span style="color:#e6db74">&#34;http&#34;</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h3 id="when-sse-causes-problems">When SSE Causes Problems</h3>
<p>SSE connections drop silently if the server doesn&rsquo;t send keepalive events. If a remote MCP tool shows <code>connected</code> in <code>/mcp</code> but fails when invoked, add a timeout check: <code>gemini mcp test &lt;name&gt;</code>. Locally-run Stdio servers restart automatically on failure; remote SSE servers require your server infrastructure to handle reconnection.</p>
<h2 id="leveraging-the-1m-token-context-window-for-large-codebases">Leveraging the 1M Token Context Window for Large Codebases</h2>
<p>Gemini 2.5 Pro&rsquo;s 1M token context window eliminates the chunking and RAG pipelines that smaller-context models require for large-codebase analysis. At roughly 4 characters per token, 1M tokens covers approximately 4MB of raw text — enough for most production monorepos, complete API documentation sets, or the combined source, test, and configuration files of a mid-size service. This is roughly 5x the capacity of standard Claude tiers and 8x that of GPT-4o, which means Gemini CLI can hold an entire backend service in context while the agent reasons across all files simultaneously. The practical sweet spot for reliable analysis sits around 600–700K tokens; accuracy begins to degrade near the extreme ceiling. Load a codebase by pointing Gemini CLI at a directory: <code>gemini &quot;analyze the auth module&quot; --context ./src</code>. No semantic search, no chunking, no approximate retrieval — the entire codebase is in the reasoning window at once.</p>
<h3 id="what-to-load-and-what-to-leave-out">What to Load and What to Leave Out</h3>
<p>Token budget allocation matters even with 1M tokens. Load source files, tests, and configuration. Exclude build artifacts (<code>node_modules</code>, <code>dist</code>, <code>.next</code>), binary files, and auto-generated code — they consume tokens without adding signal. Use <code>.geminiignore</code> (same syntax as <code>.gitignore</code>) to exclude patterns automatically.</p>



<div class="goat svg-container ">
  
    <svg
      xmlns="http://www.w3.org/2000/svg"
      font-family="Menlo,Lucida Console,monospace"
      
        viewBox="0 0 128 121"
      >
      <g transform='translate(8,16)'>
<circle cx='0' cy='64' r='6' stroke='currentColor' fill='currentColor'></circle>
<circle cx='0' cy='96' r='6' stroke='currentColor' fill='currentColor'></circle>
<text text-anchor='middle' x='0' y='4' fill='currentColor' style='font-size:1em'>#</text>
<text text-anchor='middle' x='0' y='20' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='0' y='36' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='0' y='52' fill='currentColor' style='font-size:1em'>.</text>
<text text-anchor='middle' x='0' y='84' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='8' y='20' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='8' y='36' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='8' y='52' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='8' y='68' fill='currentColor' style='font-size:1em'>.</text>
<text text-anchor='middle' x='8' y='84' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='8' y='100' fill='currentColor' style='font-size:1em'>.</text>
<text text-anchor='middle' x='16' y='4' fill='currentColor' style='font-size:1em'>.</text>
<text text-anchor='middle' x='16' y='20' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='16' y='36' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='16' y='52' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='16' y='68' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='16' y='84' fill='currentColor' style='font-size:1em'>v</text>
<text text-anchor='middle' x='16' y='100' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='24' y='4' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='24' y='20' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='24' y='36' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='24' y='52' fill='currentColor' style='font-size:1em'>x</text>
<text text-anchor='middle' x='24' y='68' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='24' y='84' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='24' y='100' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='32' y='4' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='32' y='20' fill='currentColor' style='font-size:1em'>_</text>
<text text-anchor='middle' x='32' y='36' fill='currentColor' style='font-size:1em'>/</text>
<text text-anchor='middle' x='32' y='52' fill='currentColor' style='font-size:1em'>t</text>
<text text-anchor='middle' x='32' y='68' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='32' y='84' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='32' y='100' fill='currentColor' style='font-size:1em'>c</text>
<text text-anchor='middle' x='40' y='4' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='40' y='20' fill='currentColor' style='font-size:1em'>m</text>
<text text-anchor='middle' x='40' y='52' fill='currentColor' style='font-size:1em'>/</text>
<text text-anchor='middle' x='40' y='68' fill='currentColor' style='font-size:1em'>.</text>
<text text-anchor='middle' x='40' y='84' fill='currentColor' style='font-size:1em'>a</text>
<text text-anchor='middle' x='40' y='100' fill='currentColor' style='font-size:1em'>k</text>
<text text-anchor='middle' x='48' y='4' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='48' y='20' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='48' y='68' fill='currentColor' style='font-size:1em'>j</text>
<text text-anchor='middle' x='48' y='84' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='56' y='4' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='56' y='20' fill='currentColor' style='font-size:1em'>d</text>
<text text-anchor='middle' x='56' y='68' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='56' y='84' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='64' y='4' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='64' y='20' fill='currentColor' style='font-size:1em'>u</text>
<text text-anchor='middle' x='64' y='84' fill='currentColor' style='font-size:1em'>/</text>
<text text-anchor='middle' x='72' y='4' fill='currentColor' style='font-size:1em'>i</text>
<text text-anchor='middle' x='72' y='20' fill='currentColor' style='font-size:1em'>l</text>
<text text-anchor='middle' x='80' y='4' fill='currentColor' style='font-size:1em'>g</text>
<text text-anchor='middle' x='80' y='20' fill='currentColor' style='font-size:1em'>e</text>
<text text-anchor='middle' x='88' y='4' fill='currentColor' style='font-size:1em'>n</text>
<text text-anchor='middle' x='88' y='20' fill='currentColor' style='font-size:1em'>s</text>
<text text-anchor='middle' x='96' y='4' fill='currentColor' style='font-size:1em'>o</text>
<text text-anchor='middle' x='96' y='20' fill='currentColor' style='font-size:1em'>/</text>
<text text-anchor='middle' x='104' y='4' fill='currentColor' style='font-size:1em'>r</text>
<text text-anchor='middle' x='112' y='4' fill='currentColor' style='font-size:1em'>e</text>
</g>

    </svg>
  
</div>
<h3 id="real-world-codebase-analysis">Real-World Codebase Analysis</h3>
<p>A 600K-token Next.js codebase was analyzed by Gemini 2.5 Pro in a single context — the model identified a bug where a middleware caching layer was invalidating session tokens for a specific user-agent pattern, tracing the issue across four files (<code>middleware.ts</code>, <code>auth/session.ts</code>, <code>api/user.ts</code>, and a utility in <code>lib/cache.ts</code>). A chunked approach with RAG would have required the right semantic query to surface all four files simultaneously. With the full context loaded, the model found the interaction pattern without any query tuning.</p>
<h2 id="integrating-google-adk-for-multi-agent-workflows">Integrating Google ADK for Multi-Agent Workflows</h2>
<p>Google ADK (Agent Development Kit) integrates with Gemini CLI to add multi-agent orchestration on top of the terminal interface. ADK supports Python, Go, Java, and TypeScript as of 2026, and allows you to define sub-agents with specialized tools, route tasks between them, and aggregate results — all while using Gemini CLI as the user-facing frontend. ADK agents can act as MCP clients (consuming tools from MCP servers) and can themselves expose tools via MCP servers, making them composable. The most useful pattern is a supervisor agent that delegates to specialist agents: a code-review agent, a test-runner agent, and a deployment agent, each with different tool access and system prompts, orchestrated by a parent Gemini CLI session. This eliminates the friction between terminal convenience and the complex multi-step workflows that production engineering tasks require.</p>
<h3 id="setting-up-a-basic-adk-agent">Setting Up a Basic ADK Agent</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># agent.py — minimal ADK agent that Gemini CLI can invoke</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">from</span> google.adk <span style="color:#f92672">import</span> Agent, Tool
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">@Tool</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">run_tests</span>(path: str) <span style="color:#f92672">-&gt;</span> str:
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;&#34;&#34;Run the test suite at the given path and return results.&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">import</span> subprocess
</span></span><span style="display:flex;"><span>    result <span style="color:#f92672">=</span> subprocess<span style="color:#f92672">.</span>run([<span style="color:#e6db74">&#34;pytest&#34;</span>, path, <span style="color:#e6db74">&#34;--tb=short&#34;</span>], capture_output<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>, text<span style="color:#f92672">=</span><span style="color:#66d9ef">True</span>)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> result<span style="color:#f92672">.</span>stdout <span style="color:#f92672">+</span> result<span style="color:#f92672">.</span>stderr
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>agent <span style="color:#f92672">=</span> Agent(
</span></span><span style="display:flex;"><span>    name<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;test-runner&#34;</span>,
</span></span><span style="display:flex;"><span>    model<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;gemini-2.5-pro&#34;</span>,
</span></span><span style="display:flex;"><span>    tools<span style="color:#f92672">=</span>[run_tests],
</span></span><span style="display:flex;"><span>    system_prompt<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;You are a test runner agent. Run tests and report failures with fix suggestions.&#34;</span>
</span></span><span style="display:flex;"><span>)
</span></span></code></pre></div><p>Register the ADK agent as an MCP server in <code>settings.json</code>, and Gemini CLI can call it as a tool in its ReAct loop.</p>
<h3 id="adk-multi-agent-pattern">ADK Multi-Agent Pattern</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">from</span> google.adk <span style="color:#f92672">import</span> Agent, Router
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>code_reviewer <span style="color:#f92672">=</span> Agent(name<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;reviewer&#34;</span>, tools<span style="color:#f92672">=</span>[read_pr, post_comment])
</span></span><span style="display:flex;"><span>test_runner <span style="color:#f92672">=</span> Agent(name<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;tester&#34;</span>, tools<span style="color:#f92672">=</span>[run_tests, read_coverage])
</span></span><span style="display:flex;"><span>deployer <span style="color:#f92672">=</span> Agent(name<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;deployer&#34;</span>, tools<span style="color:#f92672">=</span>[run_deploy, check_health])
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>supervisor <span style="color:#f92672">=</span> Router(
</span></span><span style="display:flex;"><span>    agents<span style="color:#f92672">=</span>[code_reviewer, test_runner, deployer],
</span></span><span style="display:flex;"><span>    model<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;gemini-2.5-pro&#34;</span>,
</span></span><span style="display:flex;"><span>    routing_prompt<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Route tasks to the appropriate specialist agent based on the request.&#34;</span>
</span></span><span style="display:flex;"><span>)
</span></span></code></pre></div><h2 id="gemini-cli-vs-claude-code-vs-codex-cli-2026-honest-comparison">Gemini CLI vs Claude Code vs Codex CLI: 2026 Honest Comparison</h2>
<p>Each of the three major agentic terminal tools — Gemini CLI, Claude Code, and Codex CLI — has a distinct sweet spot, and the right choice depends on your workflow, budget, and performance requirements. Gemini CLI wins on context window (1M tokens) and free tier (1,000 req/day at no cost), making it the clear choice for large-codebase analysis and cost-sensitive teams. Claude Code wins on code quality benchmarks, scoring 80.9% on SWE-bench Verified with 95% first-pass accuracy — measurably better for complex multi-file refactors where output correctness matters most. Codex CLI, rebuilt in Rust, achieves 77.3% on Terminal-Bench 2.0 and offers kernel-level sandboxing and the tightest MCP integration for security-sensitive environments. All three support MCP, all three implement ReAct-style agentic loops, and all three handle multi-step coding tasks autonomously. The differentiators are cost structure, context capacity, and benchmark accuracy on the specific task types you run most.</p>
<table>
  <thead>
      <tr>
          <th>Feature</th>
          <th>Gemini CLI</th>
          <th>Claude Code</th>
          <th>Codex CLI</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Context Window</td>
          <td>1M tokens</td>
          <td>200K tokens</td>
          <td>128K tokens</td>
      </tr>
      <tr>
          <td>Free Tier</td>
          <td>1,000 req/day</td>
          <td>No free tier</td>
          <td>No free tier</td>
      </tr>
      <tr>
          <td>SWE-bench Score</td>
          <td>Not published</td>
          <td>80.9%</td>
          <td>77.3% (Terminal-Bench)</td>
      </tr>
      <tr>
          <td>MCP Support</td>
          <td>Yes (Stdio/SSE/HTTP)</td>
          <td>Yes</td>
          <td>Yes (kernel-level)</td>
      </tr>
      <tr>
          <td>Plan Mode</td>
          <td>Yes (March 2026)</td>
          <td>Yes</td>
          <td>Yes</td>
      </tr>
      <tr>
          <td>Multi-Agent</td>
          <td>Via ADK</td>
          <td>Via Claude API</td>
          <td>Via integrations</td>
      </tr>
      <tr>
          <td>Best For</td>
          <td>Large codebases, cost efficiency</td>
          <td>Code quality, accuracy</td>
          <td>Security-sensitive, performance</td>
      </tr>
  </tbody>
</table>
<h3 id="when-to-use-each">When to Use Each</h3>
<p>Use Gemini CLI when you&rsquo;re analyzing a large codebase, want a free daily quota for experimentation, or need ADK-based multi-agent orchestration. Use Claude Code when output correctness on complex refactors or bug fixes is the priority. Use Codex CLI when operating in a sandboxed or security-restricted environment where kernel-level isolation matters. Many developers use Gemini CLI for exploration (leveraging the context window) and Claude Code for high-stakes changes (leveraging the accuracy benchmark).</p>
<h2 id="security-best-practices-env-variables-sandboxing-and-audit-trails">Security Best Practices: Env Variables, Sandboxing, and Audit Trails</h2>
<p>Running an autonomous agent in your terminal introduces real security considerations — the agent has shell access, can read files, and can make network requests. The first line of defense is environment variable injection: never put API keys or credentials in the <code>args</code> array of <code>settings.json</code> (they appear in process listings); always use the <code>env</code> block with <code>${VAR_NAME}</code> expansion. The second is scope limitation: configure MCP filesystem servers with path restrictions, database servers with read-only credentials for exploration sessions, and network tools with domain allowlists. Gemini CLI&rsquo;s Plan Mode (added March 2026) provides a read-only phase where the agent proposes a plan before executing any file writes — enable it with <code>--plan-mode</code> or in <code>settings.json</code> as <code>&quot;planMode&quot;: true</code>. For production systems, run Gemini CLI inside a container or VM rather than directly on your workstation, so the agent&rsquo;s shell access is bounded.</p>
<h3 id="settingsjson-security-hardening">settings.json Security Hardening</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;planMode&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;maxRetries&#34;</span>: <span style="color:#ae81ff">3</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;sandbox&#34;</span>: {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;enabled&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;allowedPaths&#34;</span>: [<span style="color:#e6db74">&#34;/workspace&#34;</span>, <span style="color:#e6db74">&#34;/tmp&#34;</span>],
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;blockedCommands&#34;</span>: [<span style="color:#e6db74">&#34;rm -rf /&#34;</span>, <span style="color:#e6db74">&#34;sudo&#34;</span>, <span style="color:#e6db74">&#34;su&#34;</span>]
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;mcpServers&#34;</span>: {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;filesystem&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;command&#34;</span>: <span style="color:#e6db74">&#34;npx&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;args&#34;</span>: [<span style="color:#e6db74">&#34;-y&#34;</span>, <span style="color:#e6db74">&#34;@modelcontextprotocol/server-filesystem&#34;</span>, <span style="color:#e6db74">&#34;/workspace&#34;</span>],
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;env&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;READ_ONLY&#34;</span>: <span style="color:#e6db74">&#34;false&#34;</span>
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;database&#34;</span>: {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;command&#34;</span>: <span style="color:#e6db74">&#34;npx&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;args&#34;</span>: [<span style="color:#e6db74">&#34;-y&#34;</span>, <span style="color:#e6db74">&#34;@modelcontextprotocol/server-postgres&#34;</span>],
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;env&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;DATABASE_URL&#34;</span>: <span style="color:#e6db74">&#34;${DATABASE_READONLY_URL}&#34;</span>
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h3 id="audit-logging">Audit Logging</h3>
<p>Enable session logging in <code>settings.json</code> with <code>&quot;sessionLog&quot;: &quot;~/.gemini/logs/&quot;</code>. Each session creates a timestamped JSON file recording every tool call, argument, and result — useful for auditing what an agent did during an autonomous run, and essential for any team that needs traceability on AI-assisted code changes.</p>
<h2 id="frequently-asked-questions">Frequently Asked Questions</h2>
<p><strong>Q: Is Gemini CLI free to use for serious development work?</strong>
A: The free tier gives you 60 requests/minute and 1,000 requests/day with a personal Google account — enough for active development sessions. For CI pipelines, team use, or higher volume, set <code>GEMINI_API_KEY</code> to use your billed quota. Gemini 2.5 Pro API pricing as of 2026 is competitive with other frontier models at similar context sizes.</p>
<p><strong>Q: How do I debug an MCP server that shows as connected but whose tools fail?</strong>
A: Run <code>gemini mcp test &lt;server-name&gt;</code> to invoke a test call and see the raw error. Check the server&rsquo;s stderr output (Stdio transport logs to <code>~/.gemini/logs/mcp-&lt;name&gt;.log</code> if session logging is enabled). Common causes: schema validation failure (missing <code>type</code> field in tool definition), environment variable not expanded (check <code>${VAR_NAME}</code> syntax), or the server process crashing silently.</p>
<p><strong>Q: Can I use Gemini CLI in CI/CD pipelines?</strong>
A: Yes — set <code>GEMINI_API_KEY</code>, use <code>--non-interactive</code> mode to disable prompts, and pipe your task as stdin: <code>echo &quot;run tests and report failures&quot; | gemini --non-interactive</code>. For PR review automation, pair with an ADK agent that has a restricted GitHub MCP tool configured with a read-only token.</p>
<p><strong>Q: What&rsquo;s the difference between Plan Mode and the normal ReAct loop?</strong>
A: In the standard ReAct loop, the agent can immediately execute file writes and shell commands as it reasons. Plan Mode adds a checkpoint: the agent runs a read-only exploration phase, proposes a written plan, waits for your approval, and only then proceeds to execute. Enable it per-session with <code>--plan-mode</code> or globally in <code>settings.json</code>. It significantly reduces unwanted side effects during exploratory tasks.</p>
<p><strong>Q: How does Gemini CLI handle secrets if my codebase contains them?</strong>
A: Gemini CLI sends context to Google&rsquo;s API endpoints. Never load files containing production secrets, private keys, or credentials into the context window. Use <code>.geminiignore</code> to exclude <code>.env</code> files, key directories, and credential stores. For security-sensitive environments, prefer Codex CLI&rsquo;s kernel-level sandboxing or run Gemini CLI against a sanitized codebase copy rather than your live repository.</p>
]]></content:encoded></item></channel></rss>