ONLINE

Installing Claude & Gemini in the Terminal

Published:

Introduction

Why click through web interfaces when you can have AI at your fingertips in the terminal? This tutorial covers installing and configuring both Claude Code (Anthropic’s official CLI) and Gemini CLI for terminal-based AI assistance.

What You’ll Learn

  • Installing Claude Code via npm
  • Setting up API keys securely
  • Installing Gemini CLI
  • Basic usage and commands
  • Tips for effective terminal AI workflows

Prerequisites

  • Node.js 18+ installed
  • Terminal/command line access
  • API keys from Anthropic and/or Google

Prerequisites Check

  1. Node.js 18+ (for Claude Code):
node --version
# Should show v18.x.x or higher
  1. Python 3.8+ (for Gemini CLI):
python --version
# or python3 --version
  1. Package managers:
npm --version
pip --version

Don’t have Node.js? Download from nodejs.org

Part 1: Claude Code Setup

Claude Code is Anthropic’s official CLI tool for developers. It’s incredibly powerful for coding tasks.

Installation

# Install globally via npm
npm install -g @anthropic-ai/claude-code

# Verify installation
claude --version

Getting Your API Key

  1. Create Anthropic account: Visit console.anthropic.com
  2. Get API key: Go to Settings > API Keys > Create Key
  3. Copy the key: It starts with sk-ant-api03-...

Important: Keep this key secure! Never commit it to git.

Configuration

Method 1: Environment Variable (Recommended)

# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
export ANTHROPIC_API_KEY="sk-ant-api03-your-key-here"

# Reload shell
source ~/.bashrc  # or ~/.zshrc

Method 2: Config File

# Create config directory
mkdir -p ~/.config/claude

# Add API key to config
echo "ANTHROPIC_API_KEY=sk-ant-api03-your-key-here" > ~/.config/claude/config

Method 3: Interactive Setup

claude auth
# Follow prompts to add your API key

Basic Claude Code Usage

Simple chat:

claude "Explain async/await in JavaScript"

Code-focused requests:

claude "Write a Python function to merge two sorted lists"

File context (amazing for debugging):

# Analyze a specific file
claude "Review this code for bugs" --file src/app.js

# Multiple files
claude "Optimize these components" --file src/*.jsx

Interactive mode:

# Start interactive session
claude -i

# Now you can chat back and forth
> How do I implement rate limiting?
> Can you show me code examples?
> What about Redis-based solutions?

Advanced Claude Code Features

Project context:

# Analyze entire project
claude "Suggest improvements to this codebase" --include "src/**/*.js"

# Ignore certain files
claude "Review my code" --include "src/**" --exclude "node_modules/**"

Different Claude models:

# Use Claude 4 Opus (default)
claude "Complex coding task here"

# Use Claude 3.5 Sonnet (faster, cheaper)
claude "Simple question" --model claude-3-5-sonnet-20241022

Output to file:

claude "Generate unit tests for this module" --file src/utils.js > tests/utils.test.js

Part 2: Gemini CLI Setup

Google’s Gemini is excellent for research, analysis, and multimodal tasks.

Installation

Option 1: Google AI Studio CLI (Official)

pip install google-generativeai

# Create a simple wrapper script
cat > ~/.local/bin/gemini << 'EOF'
#!/usr/bin/env python3
import google.generativeai as genai
import sys
import os

genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
model = genai.GenerativeModel('gemini-pro')

if len(sys.argv) < 2:
    print("Usage: gemini 'your prompt here'")
    sys.exit(1)

prompt = ' '.join(sys.argv[1:])
response = model.generate_content(prompt)
print(response.text)
EOF

chmod +x ~/.local/bin/gemini

Option 2: Third-party CLI (simpler)

npm install -g gemini-cli

Getting Your Gemini API Key

  1. Visit Google AI Studio: makersuite.google.com
  2. Get API key: Click “Get API key” > “Create API key”
  3. Copy the key: Starts with AIza...

Configuration

# Add to shell profile
export GOOGLE_API_KEY="AIza-your-key-here"

# Reload shell
source ~/.bashrc

Basic Gemini Usage

Simple queries:

gemini "Summarize the latest developments in AI"

Research tasks:

gemini "Compare React vs Vue vs Angular in 2024"

Data analysis:

gemini "Analyze these sales figures and suggest improvements" < data.csv

Part 3: Advanced Workflows

Combining Both AIs

Use Claude for coding, Gemini for research:

# Research first
gemini "What are the best practices for Node.js error handling?" > research.md

# Then implement
claude "Based on this research, refactor my error handling" --file app.js research.md

Shell Integration

Add to your .bashrc/.zshrc:

# Quick AI aliases
alias ai-code="claude"
alias ai-research="gemini"
alias ai-review="claude 'Review this code for security and performance'"

# Function for quick explanations
explain() {
    gemini "Explain in simple terms: $*"
}

# Function for code help
code-help() {
    claude "Help me with this coding problem: $*"
}

Usage:

explain "quantum computing"
code-help "implementing JWT authentication in Express.js"

VS Code Integration

Claude Code extension:

  1. Install the official Claude Code VS Code extension
  2. Set up API key in settings
  3. Use Ctrl/Cmd+Shift+P > “Claude: Chat”

Tmux/Screen Integration

Create dedicated AI panes:

# Start tmux session
tmux new-session -d -s ai

# Create panes for different AIs
tmux split-window -h
tmux send-keys -t ai:0 'claude -i' Enter
tmux send-keys -t ai:1 'python3 -c "import google.generativeai as ai"' Enter

# Attach to session
tmux attach -t ai

Part 4: Pro Tips & Best Practices

Prompt Engineering for Terminal

Be specific about output format:

claude "Generate a bash script to backup MySQL. Include comments and error handling."

gemini "List the top 5 JavaScript frameworks. Format as: Name - Use Case - Popularity"

Use context effectively:

# Good: Provide context
claude "This API endpoint is returning 500 errors. Here's the code:" --file api/users.js

# Better: Include logs too
claude "Debug this 500 error" --file api/users.js --file logs/error.log

Security Best Practices

  1. Environment variables: Never hardcode API keys
  2. Separate profiles: Use different keys for development/production
  3. Rate limiting: Be mindful of API costs
  4. Sensitive data: Don’t send passwords, private keys, or personal data

Performance Optimization

Claude Code:

  • Use appropriate model for task complexity
  • Batch similar requests
  • Cache responses locally when possible

Gemini:

  • Use streaming for long responses
  • Implement retry logic for network issues

Useful Scripts

AI-powered git commit messages:

#!/bin/bash
# File: ai-commit.sh
DIFF=$(git diff --cached)
if [ -z "$DIFF" ]; then
    echo "No staged changes"
    exit 1
fi

MESSAGE=$(claude "Generate a concise git commit message for these changes: $DIFF")
echo "Suggested commit: $MESSAGE"
read -p "Use this message? (y/N): " confirm

if [[ $confirm == [yY] ]]; then
    git commit -m "$MESSAGE"
else
    echo "Commit cancelled"
fi

Code review automation:

#!/bin/bash
# File: ai-review.sh
FILES=$(git diff --name-only HEAD~1)
for file in $FILES; do
    echo "=== Reviewing $file ==="
    claude "Review this file for bugs and improvements" --file "$file"
    echo ""
done

Part 5: Integration Examples

Documentation Generation

# Generate README
claude "Create a comprehensive README for this project" --include "src/**" > README.md

# API documentation
claude "Generate OpenAPI spec from this Express app" --file routes/*.js > api-spec.yaml

Code Refactoring

# Modernize old code
claude "Refactor this to use modern ES6+ syntax" --file legacy/app.js > modern/app.js

# Add TypeScript types
claude "Add TypeScript types to this JavaScript file" --file src/utils.js > src/utils.ts

Learning & Research

# Learn new concepts
gemini "Explain microservices architecture with pros and cons"

# Compare technologies
gemini "Compare Docker vs Podman vs LXC for container orchestration"

Troubleshooting

Claude Code Issues

“Command not found”:

# Check if installed globally
npm list -g @anthropic-ai/claude-code

# Fix PATH issues
echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.bashrc

“Invalid API key”:

# Check key format
echo $ANTHROPIC_API_KEY
# Should start with sk-ant-api03-

# Test key
claude "Hello" --verbose

Gemini Issues

“Module not found”:

# Reinstall with correct Python
pip3 install google-generativeai

# Check Python path
which python3

“API key not working”:

# Test key manually
python3 -c "import google.generativeai as genai; genai.configure(api_key='$GOOGLE_API_KEY'); print('Key works!')"

General Issues

Rate limiting:

  • Claude: Check usage at console.anthropic.com
  • Gemini: Check quota at console.cloud.google.com

Network issues:

  • Use VPN if blocked in your region
  • Check corporate firewall settings

Congratulations! 🎉 You now have both Claude and Gemini accessible from your terminal. This setup will revolutionize your coding and research workflows.

Next steps: Experiment with different prompt styles, create custom scripts, and integrate AI into your daily development routine.