# Claude-Gemini Collaborative Integration
This document provides instructions for Claude Code to collaborate with Gemini CLI for iterative problem-solving and real-time discussions.
## Overview
When working on complex tasks, Claude can start collaborative conversations with Gemini, where both AIs can discuss, iterate, and refine solutions together in real-time.
## Collaborative Server
The collaborative server runs at `http://localhost:8080` and provides:
- `/start_conversation` - Start a new collaboration
- `/consult_gemini` - Discuss with Gemini (with context)
- `/add_message` - Add messages to ongoing conversations
- `/conversation/{id}` - Get conversation history
- `/health` - Check server status
## How to Use Collaboration
### Starting a Collaboration
When the user asks you to collaborate with Gemini:
1. **Start a conversation**: Use the collaboration tools to begin
2. **Discuss iteratively**: Exchange ideas back and forth
3. **Refine together**: Build upon each other's contributions
4. **Present final solution**: Synthesize the collaborative result
### Available Functions
```python
import asyncio
import sys
sys.path.append('/Users/jamiearonson/Documents/claude-gemini-integration')
from claude_gemini_tools import (
start_collaboration_with_gemini,
ask_gemini,
brainstorm_with_gemini,
get_gemini_review,
iterative_plan_with_gemini
)
# Start collaboration
result = await start_collaboration_with_gemini("Topic")
# Ask Gemini something
response = await ask_gemini("What do you think about X?")
# Brainstorm together
ideas = await brainstorm_with_gemini("Mobile app features")
# Get review
feedback = await get_gemini_review("Here's my code...")
# Iterative planning
plan = await iterative_plan_with_gemini("Initial plan", rounds=3)
```
## When to Collaborate
1. **Complex Planning**: Architecture decisions, project planning
2. **Creative Tasks**: Brainstorming, design discussions
3. **Code Review**: Getting second opinions on implementations
4. **Problem Solving**: When multiple approaches are possible
5. **Learning**: Exploring topics from different perspectives
## Collaboration Workflow
### Example: Planning a New Feature
1. **User Request**: "I need to plan a new authentication system"
2. **Claude Starts**: Begin collaboration with Gemini
3. **Initial Discussion**: Present the problem to Gemini
4. **Iterative Refinement**: Bounce ideas back and forth
5. **Final Synthesis**: Present the collaborative solution
### Example: Code Review
1. **User Request**: "Review this code with Gemini"
2. **Start Collaboration**: Begin code review discussion
3. **Share Code**: Present code to Gemini for analysis
4. **Discuss Issues**: Exchange findings and suggestions
5. **Refined Recommendations**: Provide comprehensive feedback
## Response Format
When presenting collaborative results:
```markdown
## Collaborative Solution
[Synthesized solution from the discussion]
### Discussion Summary
- **Initial Approach**: [Starting point]
- **Gemini's Input**: [Key contributions from Gemini]
- **Refinements**: [How the solution evolved]
- **Final Decision**: [What we agreed on]
### Implementation Details
[Specific steps and code if applicable]
### Alternative Approaches Considered
[Other options discussed]
```
## Sample Collaboration Flow
```python
# Example: Planning a web application
async def plan_web_app():
# Start collaboration
await start_collaboration_with_gemini("Web Application Architecture")
# Initial discussion
claude_plan = "I'm thinking of a React frontend with Node.js backend..."
gemini_response = await ask_gemini(f"Here's my initial plan: {claude_plan}. What are your thoughts?")
# Iterate on the plan
refined_plan = await ask_gemini("Based on your feedback, should we consider microservices?")
# Get final review
final_review = await get_gemini_review("Here's our refined architecture...")
return final_review
```
## Best Practices
1. **Set Clear Context**: Start with the problem statement
2. **Iterate Meaningfully**: Ask specific questions for refinement
3. **Build on Responses**: Reference previous discussion points
4. **Synthesize Results**: Combine insights into coherent solutions
5. **Document the Process**: Show how the collaboration evolved
## Rate Limiting
- Gemini CLI: 60 requests/minute
- Server handles rate limiting automatically
- Conversations persist across rate limit delays
## Error Handling
- If Gemini is unavailable, proceed with best judgment
- Note collaboration attempts in responses
- Suggest manual verification for critical decisions
## Example Usage Scenarios
### Scenario 1: User asks for collaboration
```
User: "Work with Gemini to design a database schema for my e-commerce site"
Claude: [Starts collaboration, discusses with Gemini, presents results]
```
### Scenario 2: Complex technical decision
```
User: "I need to choose between different caching strategies"
Claude: [Collaborates with Gemini to evaluate options]
```
### Scenario 3: Code review
```
User: "Review this code with Gemini and suggest improvements"
Claude: [Starts collaboration, reviews code together, provides feedback]
```
Remember: The goal is true collaboration - not just comparison, but iterative discussion and refinement leading to better solutions.