Skip to main content

Gemini CLI

Use Google's Gemini CLI with 1M token context for Trix memory integration and automation.

Overview

Gemini CLI is Google's command-line AI assistant with impressive context windows (1M tokens) and a generous free tier. It supports MCP servers, extensions, and automation workflows, making it excellent for Trix memory integration tasks.

Gemini CLI's massive context window (1M tokens) allows it to understand entire codebases, including all Trix platform documentation, in a single prompt. The free tier offers 60 requests/min and 1,000 requests/day.

Installation & Setup

Install Gemini CLI

Install via npm (requires Node.js 18+):

terminal
npm install -g @google/generative-ai-cli

# Or use npx without installing
npx @google/generative-ai-cli

Authentication

Authenticate with your Google account:

terminal
gemini auth login

This opens a browser window for Google OAuth authentication.

The free tier provides generous limits with your personal Google account. For higher limits, you can use Google Cloud credentials with a Vertex AI project.

Verify Installation

terminal
gemini "Hello! Can you help me with Trix SDK integration?"

Basic Usage

Simple Prompts

Ask Gemini about Trix directly from the terminal:

terminal
gemini "How do I store and search memories with the Trix API?"

gemini "Show me how to add persistent memory to my AI chatbot with Trix"

gemini "What's the best way to organize Trix memory spaces for multi-tenant apps?"

Providing File Context

Include files in your prompt:

terminal
gemini "Review this Trix memory service and suggest improvements" < src/services/memory.ts

gemini "Debug this Trix API configuration" < src/config/trix.ts

Interactive Mode

Start an interactive session for back-and-forth conversation:

terminal
gemini chat

# Now in interactive mode:
> Help me set up Trix memory SDK with TypeScript
> How do I search memories with metadata filters?
> Show me the RAG integration pattern

Project Context with GEMINI.md

Create a GEMINI.md file in your project root to provide persistent context:

GEMINI.md
# Trix Memory Integration

## Overview
This project uses the Trix memory platform for [describe your use case].

## Tech Stack
- Framework: React 18 with TypeScript
- Trix SDK: @trixdb/client
- API Base URL: https://api.trixdb.com
- MCP Server: @trix/mcp

## Project Structure
- `src/services/memory.ts` - Trix memory service
- `src/hooks/useMemory.ts` - Custom memory hook
- `src/utils/search.ts` - Search and retrieval helpers
- `src/types/trix.ts` - TypeScript types for Trix API

## Trix Configuration
- API key via TRIX_API_KEY environment variable
- Default space for user isolation
- Metadata filters for content categorization
- Webhook events for memory changes

## Common Commands
```bash
npm run dev        # Start development server
npm run build      # Build for production
npm test          # Run tests
```

## Known Issues
- [List any known issues or workarounds]

Gemini CLI automatically reads this file when you run commands in the project directory.

Advanced Features

MCP Server Integration

Gemini CLI supports MCP servers for extended capabilities. Configure in ~/.gemini/settings.json:

~/.gemini/settings.json
{
  "mcpServers": {
    "trix-memory": {
      "command": "npx",
      "args": ["-y", "@trix/mcp"],
      "env": {
        "TRIX_API_KEY": "your_api_key_here"
      }
    }
  }
}

Now Gemini can store and recall memories from your Trix account:

terminal
gemini "Remember that we're using React 18 with TypeScript for our Trix integration"

gemini "What do you know about our Trix setup?"

Custom Extensions

Create custom extensions in .gemini/extensions/ for project-specific tools:

.gemini/extensions/trix-helper/index.js
// .gemini/extensions/trix-helper/index.js
export default {
  name: 'trix-helper',
  description: 'Helper tools for Trix memory integration',

  tools: {
    searchMemories: {
      description: 'Search Trix memories for relevant context',
      parameters: {
        query: { type: 'string', description: 'Search query' }
      },
      execute: async ({ query }) => {
        // Custom search logic using Trix API
        return results;
      }
    }
  }
};

Automation with Headless Mode

Use headless mode for scripts and automation:

scripts/review-trix-pr.sh
#!/bin/bash
# scripts/review-trix-pr.sh

gemini --headless --json "Review this Trix integration PR for:
- API usage patterns
- Security concerns (API key handling)
- Performance (batch operations, search optimization)
- Error handling completeness

$(git diff main...HEAD)" | jq -r '.response'

Policy Engine

Control which tools Gemini can use with policy files:

.gemini/policy.json
// .gemini/policy.json
{
  "allowedTools": [
    "read_file",
    "write_file",
    "run_shell_command"
  ],
  "deniedTools": [
    "run_shell_command"  // Prevent shell execution in CI
  ],
  "requireConfirmation": [
    "write_file"  // Always confirm file writes
  ]
}

Common Workflows

Initial Trix Setup

terminal
gemini "Set up Trix memory SDK in this TypeScript project:
1. Install @trixdb/client package
2. Create memory service with types
3. Add store, search, and delete methods
4. Configure API authentication
5. Export from index"

Code Review

terminal
gemini "Review this Trix memory integration for issues" < src/services/memory.ts

Generate Documentation

terminal
gemini "Generate JSDoc comments for this Trix memory utility file" < src/utils/memory-helpers.ts > src/utils/memory-helpers.documented.ts

Debugging

terminal
gemini "Debug this Trix API error:
$(npm run dev 2>&1 | tail -n 20)

My configuration:
$(cat src/config/trix.ts)"

Refactoring

terminal
gemini chat
> I need to refactor my memory service to use the new Trix SDK patterns
> [paste current code]
> Can you show me the updated version?

VS Code Integration

Use the Gemini CLI VS Code extension for IDE integration:

  1. Install the "Gemini CLI" extension from VS Code marketplace
  2. Configure the extension in settings
  3. Use Command Palette (Cmd+Shift+P) → "Gemini: Ask"
  4. View responses in the integrated terminal

The VS Code extension provides diff viewing and inline suggestions while maintaining the power of the CLI.

Tips for Best Results

  • Leverage large context - Gemini can handle entire codebases in one prompt
  • Use GEMINI.md - Provide project context automatically
  • Chain commands - Pipe Gemini output to other tools (jq, grep, etc.)
  • Interactive for exploration - Use interactive mode for back-and-forth problem solving
  • Headless for automation - Integrate Gemini into CI/CD pipelines
  • MCP for memory - Use MCP servers to remember project-specific context

Example Prompts

Setup Prompts

terminal
gemini "Set up Trix memory SDK with TypeScript and configure API authentication"

gemini "Create a memory service for my Next.js app with server-side search"

gemini "Configure the Trix MCP server for Gemini CLI integration"

Memory & Search Prompts

terminal
gemini "Build a RAG pipeline using Trix memory for context retrieval"

gemini "Implement batch memory import from a CSV file"

gemini "Create space-based isolation for multi-tenant memory management"

Debugging Prompts

terminal
gemini "Why are my Trix memory searches returning irrelevant results?"

gemini "Debug this Trix API authentication error: [error message]"

gemini "Optimize my Trix memory pipeline for high-throughput ingestion"

For more prompts, see the Prompt Library.

When to Use Gemini CLI

Use CaseWhy Gemini CLI
Large Codebases1M token context can hold entire projects
Free TierGenerous limits with personal Google account
AutomationHeadless mode for scripts and CI/CD
Terminal WorkflowsNative CLI fits terminal-centric development
MCP IntegrationBuilt-in support for MCP servers

Next Steps