Strategic patterns for codebase exploration using Gemini's large context window. Covers token thresholds, model routing, and exploration strategies. Use when deciding between Claude and Gemini for exploration, analyzing large codebases, or choosing between Flash and Pro models for context size.
Limited to specific tools
Additional assets for this skill
This skill is limited to using the following tools:
STOP - Before providing ANY response about Gemini exploration:
- INVOKE
gemini-cli-docsskill- QUERY for the specific exploration/context topic
- BASE all responses EXCLUSIVELY on official documentation loaded
This skill provides strategic guidance for leveraging Gemini CLI's large context window for codebase exploration. It covers when to delegate exploration to Gemini, which model to use, and how to structure outputs for Claude to consume.
Keywords: explore codebase, analyze architecture, large context, token limit, gemini exploration, codebase analysis, when to use gemini, model selection
Use this skill when:
| Codebase Size | Tokens | Recommended Agent | Rationale |
|---|---|---|---|
| Small | <50K | Claude native | Claude's tools are faster |
| Medium | 50K-500K | Gemini Flash | Good balance of speed/cost |
| Large | 500K-1M | Gemini Flash + chunking | Stay within Flash limits |
| Very Large | 1M-2M | Gemini Pro | Need extended context |
| Massive | >2M | Gemini Pro + progressive | Multi-pass exploration |
# Quick estimation: 1 token ~ 4 characters
chars=$(find . -name "*.ts" -o -name "*.py" | xargs wc -c | tail -1 | awk '{print $1}')
tokens=$((chars / 4))
echo "Estimated tokens: $tokens"
IF estimated_tokens < 50,000:
USE Claude's native Explore agent
ELIF estimated_tokens < 1,000,000:
USE Gemini Flash via /gemini-explore
ELIF estimated_tokens < 2,000,000:
USE Gemini Pro via /gemini-explore --pro
ELSE:
USE Progressive exploration (chunk by module)
Context: Large (exact limits set by Google, check current API docs) Cost: Lower Speed: Faster
Best for:
Context: Very large (exact limits set by Google, check current API docs) Cost: Higher Speed: Slower
Best for:
Best for: Understanding overall architecture
# Collect all source files
find . -type f \( -name "*.ts" -o -name "*.tsx" \) \
-not -path "*/node_modules/*" \
-not -path "*/.git/*" \
| xargs cat | gemini "Analyze architecture" --output-format json
Best for: Very large codebases (>2M tokens)
# Explore each top-level module separately
for dir in src/*/; do
echo "=== Exploring $dir ==="
find "$dir" -name "*.ts" | xargs cat | gemini "Analyze this module" --output-format json
done
Best for: Understanding execution flow
# Focus on entry points and their dependencies
cat package.json src/index.ts src/main.ts | gemini "Analyze entry points and startup flow" --output-format json
Best for: Understanding relationships
# Package manifests + import statements
find . -name "package.json" -o -name "requirements.txt" -o -name "go.mod" | xargs cat
grep -r "^import\|^from" src/ | head -1000
Best for: Iterative understanding
All Gemini exploration outputs should follow this format for Claude consumption:
---
generated-by: gemini-cli
model: gemini-2.5-flash
timestamp: 2025-11-30T12:00:00Z
tokens: 150000
scope: architecture|dependencies|patterns|all
---
{
"type": "exploration",
"scope": "architecture",
"tokens_used": 150000,
"model": "gemini-2.5-flash",
"key_findings": [
"Uses Clean Architecture pattern",
"React frontend with Express backend",
"PostgreSQL database with Prisma ORM"
],
"files_analyzed": 245,
"entry_points": ["src/index.ts", "src/server.ts"]
}
Structured markdown with clear sections:
Specific, actionable guidance:
## Recommendations for Claude
### Files to Read First
1. `src/index.ts` - Main entry point
2. `src/config/index.ts` - Configuration patterns
3. `CLAUDE.md` - Project conventions
### Patterns to Follow
- Use dependency injection for services
- Follow the existing error handling pattern in `src/errors/`
### Areas of Concern
- Complex state management in `src/store/` - read carefully
- Database migrations in `prisma/migrations/` - check before schema changes
# Source code
-name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx"
-name "*.py" -o -name "*.go" -o -name "*.rs" -o -name "*.java"
# Configuration
-name "*.json" -o -name "*.yaml" -o -name "*.yml" -o -name "*.toml"
# Documentation
-name "*.md" -o -name "README*"
-not -path "*/node_modules/*"
-not -path "*/.git/*"
-not -path "*/dist/*"
-not -path "*/build/*"
-not -path "*/__pycache__/*"
-not -path "*/.next/*"
-not -path "*/coverage/*"
-not -path "*/.cache/*"
head -500 for file lists# Bad: Many small calls
for file in *.ts; do gemini "analyze $file"; done
# Good: One large call
cat *.ts | gemini "analyze all files"
gemini-delegation-patterns - When to delegate any task to Geminigemini-token-optimization - Cost optimization strategiesgemini-cli-execution - CLI invocation patternsgemini-workspace-bridge - Artifact storage and exchange/gemini-explore - Execute exploration with standard output/gemini-plan - Generate implementation plans| Topic | Keywords |
|---|---|
| Token limits | context window, token limit, large context |
| Model selection | flash vs pro, which model, model routing |
| Exploration | explore codebase, analyze architecture, understand code |
| Cost | reduce tokens, optimize cost, batch calls |
| Output | exploration format, cross-cli artifact, claude readable |
Query: "Should I use Claude or Gemini to explore this codebase?" Expected Behavior:
Query: "Should I use Flash or Pro for codebase analysis?" Expected Behavior:
Query: "How do I analyze a very large codebase with Gemini?" Expected Behavior: