This repository was archived by the owner on Dec 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemini-setup.sh
More file actions
executable file
·1053 lines (844 loc) · 43.1 KB
/
Copy pathgemini-setup.sh
File metadata and controls
executable file
·1053 lines (844 loc) · 43.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Gemini CLI Setup Script for Claude Code Integration
# Creates AI-powered development workflow with Gemini as advisor
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
CLAUDE_SETTINGS_DIR="$HOME/.claude/commands"
PROMPTS_FILE="claude-quick-start.txt"
STATUS_FILE="setup-complete.md"
TIMEOUT=300 # 5 minutes
# Helper functions
print_header() {
echo -e "\n${BLUE}=== $1 ===${NC}\n"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ $1${NC}"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Use standard gemini command
GEMINI_CMD="gemini"
# Detect available CLIs
detect_available_clis() {
print_info "Detecting available development tools..."
AVAILABLE_CLIS=""
if command_exists git; then
AVAILABLE_CLIS="$AVAILABLE_CLIS git"
fi
if command_exists npm; then
AVAILABLE_CLIS="$AVAILABLE_CLIS npm"
fi
if command_exists firebase; then
AVAILABLE_CLIS="$AVAILABLE_CLIS firebase"
fi
if command_exists gh; then
AVAILABLE_CLIS="$AVAILABLE_CLIS github"
fi
if command_exists docker; then
AVAILABLE_CLIS="$AVAILABLE_CLIS docker"
fi
if [ -n "$AVAILABLE_CLIS" ]; then
print_success "Found tools:$AVAILABLE_CLIS"
else
print_info "No additional CLI tools detected (that's fine!)"
fi
}
# No authentication checking - user handles this themselves
# Create MCP-optimized slash commands
create_mcp_commands() {
print_header "Creating MCP-powered slash commands"
mkdir -p "$CLAUDE_SETTINGS_DIR"
local cli_context=""
if [ -n "$AVAILABLE_CLIS" ]; then
cli_context="Available dev tools: $AVAILABLE_CLIS. "
fi
# Enhanced Planning and architecture
cat > "$CLAUDE_SETTINGS_DIR/gemini-plan.md" << EOF
---
description: Plan features and architecture with full project context
---
Plan this feature or project using Gemini with complete project context.
What do you want to plan or build?
!/gemini-cli:analyze @package.json @*/README.md @src/* "Help plan this feature/project: {input}. ${cli_context}Consider: 1) Existing project architecture and dependencies 2) Best technologies for this tech stack 3) Implementation steps and timeline 4) Potential integration issues 5) Security and performance implications. Provide comprehensive but actionable guidance." model:"gemini-2.5-pro"
EOF
print_success "Created /gemini-plan command (MCP-enhanced)"
# Context-aware best approach advice
cat > "$CLAUDE_SETTINGS_DIR/gemini-approach.md" << EOF
---
description: Get best practice advice with full project context
---
Get expert best practice advice from Gemini with project awareness.
What approach question do you have?
!/gemini-cli:analyze @package.json @{selectedText} "{input} ${cli_context}Context: Based on the project's tech stack and selected code, recommend: 1) Best practices specific to this technology 2) Pros/cons of different approaches 3) Implementation strategy with examples 4) Common pitfalls to avoid 5) Performance and security considerations." model:"gemini-2.5-pro"
EOF
print_success "Created /gemini-approach command (MCP-enhanced)"
# Smart function generation with context
cat > "$CLAUDE_SETTINGS_DIR/gemini-function.md" << EOF
---
description: Generate functions matching your project's style and dependencies
---
Generate a function that perfectly matches your project's style and uses appropriate dependencies.
What function do you need?
!/gemini-cli:sandbox "Create function: {input}. ${cli_context}Project context: {selectedText}. Requirements: 1) Match existing code style and patterns 2) Use project's existing dependencies appropriately 3) Include proper error handling and validation 4) Add TypeScript types if project uses TypeScript 5) Include comprehensive usage example and JSDoc comments."
EOF
print_success "Created /gemini-function command (MCP-enhanced)"
# Comprehensive code review with project context
cat > "$CLAUDE_SETTINGS_DIR/gemini-review.md" << EOF
---
description: Comprehensive code review with full project awareness
---
Review selected code with Gemini using complete project context for thorough analysis.
!/gemini-cli:analyze @{currentFile} @package.json "Comprehensive code review with project context. ${cli_context}Analyze this code for: 1) Security vulnerabilities (input validation, authentication, data exposure) 2) Performance bottlenecks and optimization opportunities 3) Best practices adherence for this tech stack 4) Code maintainability and readability 5) Integration and dependency issues. Flag HIGH and CRITICAL issues with specific fixes."
EOF
print_success "Created /gemini-review command (MCP-enhanced)"
# Enhanced code explanation with context
cat > "$CLAUDE_SETTINGS_DIR/gemini-explain.md" << EOF
---
description: Explain code with project and dependency context
---
Get detailed code explanation with full project context and dependency awareness.
!/gemini-cli:analyze @{currentFile} @package.json "Explain this code in detail with project context. ${cli_context}Cover: 1) What the code does and its purpose in the project 2) How it works step-by-step 3) Key concepts, patterns, and technologies used 4) Dependencies and their roles 5) Integration points with other project components. Use clear, educational language suitable for learning."
EOF
print_success "Created /gemini-explain command (MCP-enhanced)"
# Smart debugging with full context
cat > "$CLAUDE_SETTINGS_DIR/gemini-fix.md" << EOF
---
description: Smart debugging with complete project context
---
Get expert debugging help with full project awareness and context.
What error or issue are you seeing?
!/gemini-cli:analyze @{currentFile} @package.json "Debug this error: {input}. ${cli_context}Code context provided. Comprehensive analysis: 1) Root cause identification with project context 2) Step-by-step fix with code examples 3) Why this error occurred (education) 4) Prevention strategies and best practices 5) Related code areas that might need attention. Provide working solution."
EOF
print_success "Created /gemini-fix command (MCP-enhanced)"
# Enhanced security audit with project-wide awareness
cat > "$CLAUDE_SETTINGS_DIR/gemini-security.md" << EOF
---
description: Security audit with complete project context
---
Perform comprehensive security audit with full project awareness.
!/gemini-cli:analyze @{currentFile} @package.json @*.config.* "Security audit with project context. ${cli_context}Analyze for: 1) Input validation and sanitization issues 2) Authentication and authorization flaws 3) Data exposure and privacy risks 4) Dependency vulnerabilities and outdated packages 5) Configuration and environment security. List only HIGH/CRITICAL issues with specific, actionable fixes and code examples." model:"gemini-2.5-pro"
EOF
print_success "Created /gemini-security command (MCP-enhanced)"
# Enhanced general questions with context
cat > "$CLAUDE_SETTINGS_DIR/gemini-ask.md" << EOF
---
description: Ask development questions with project context
---
Ask Gemini any development question with your project context automatically included.
What would you like to ask?
!/gemini-cli:analyze @package.json "Development question: {input}. ${cli_context}Project context provided. Answer considering: 1) Current tech stack and dependencies 2) Project architecture and constraints 3) Best practices for this technology 4) Practical implementation examples 5) Trade-offs, alternatives, and recommendations."
EOF
print_success "Created /gemini-ask command (MCP-enhanced)"
# NEW: Intelligent test generation
cat > "$CLAUDE_SETTINGS_DIR/gemini-test.md" << EOF
---
description: Generate comprehensive tests for selected code
---
Generate intelligent, comprehensive tests for the selected code using project context.
!/gemini-cli:analyze @{currentFile} @package.json "Generate comprehensive tests for this code. ${cli_context}Consider: 1) Test framework and testing patterns used in project 2) Edge cases and error conditions 3) Mocking strategies for external dependencies 4) Coverage of all code paths and scenarios 5) Integration test considerations. Include setup, teardown, and clear test descriptions."
EOF
print_success "Created /gemini-test command (NEW)"
# NEW: Project-wide security audit
cat > "$CLAUDE_SETTINGS_DIR/gemini-audit.md" << EOF
---
description: Comprehensive project-wide security audit
---
Perform complete project security audit across all files and configurations.
!/gemini-cli:analyze @src/* @package.json @*.config.* @.env.example "Comprehensive project-wide security audit. ${cli_context}Analyze entire project for: 1) Source code vulnerabilities across all files 2) Dependency security issues and outdated packages 3) Configuration security (CORS, headers, environment) 4) Secrets management and exposure risks 5) API security patterns and authentication. Prioritize HIGH/CRITICAL issues with remediation steps." model:"gemini-2.5-pro"
EOF
print_success "Created /gemini-audit command (NEW)"
# NEW: Performance optimization analysis
cat > "$CLAUDE_SETTINGS_DIR/gemini-optimize.md" << EOF
---
description: Project-wide performance optimization analysis
---
Analyze entire project for performance optimization opportunities.
!/gemini-cli:analyze @src/* @package.json "Project performance optimization analysis. ${cli_context}Focus on: 1) Code efficiency bottlenecks and algorithmic improvements 2) Database query optimization opportunities 3) Memory usage patterns and potential leaks 4) Bundle size optimization and code splitting 5) Async/await patterns and concurrency improvements. Provide specific, measurable recommendations with implementation examples." model:"gemini-2.5-pro"
EOF
print_success "Created /gemini-optimize command (NEW)"
# NEW: Intelligent refactoring suggestions
cat > "$CLAUDE_SETTINGS_DIR/gemini-refactor.md" << EOF
---
description: Get intelligent refactoring suggestions with architectural awareness
---
Get smart refactoring suggestions that consider your entire project architecture.
!/gemini-cli:analyze @{currentFile} @src/* "Intelligent refactoring analysis for this code within project architecture context. ${cli_context}Suggest: 1) Design pattern improvements and SOLID principles application 2) Code organization and structure enhancements 3) Dependency reduction and coupling improvements 4) Performance optimizations and efficiency gains 5) Maintainability and readability improvements. Provide before/after examples." model:"gemini-2.5-pro"
EOF
print_success "Created /gemini-refactor command (NEW)"
# RESPONSE HANDLER COMMANDS - What to do after Gemini gives advice
# Implement Gemini's suggestions
cat > "$CLAUDE_SETTINGS_DIR/gemini-implement.md" << EOF
---
description: Implement Gemini's suggestions from previous analysis
---
Take Gemini's recommendations and implement them in the codebase.
What Gemini suggestions should I implement? (paste or describe)
!echo "Implementing Gemini's suggestions: {input}. ${cli_context}Current file context: {selectedText}. I will now implement these recommendations carefully, maintaining code style and ensuring all changes are tested and working properly."
EOF
print_success "Created /gemini-implement command (RESPONSE HANDLER)"
# Verify implementation matches Gemini's advice
cat > "$CLAUDE_SETTINGS_DIR/gemini-verify.md" << EOF
---
description: Verify changes match Gemini's recommendations
---
Check if the implemented changes correctly follow Gemini's advice.
!/gemini-cli:analyze @{currentFile} "Verify these changes match the recommendations given earlier. ${cli_context}Check: 1) All suggested changes were implemented correctly 2) No recommendations were missed 3) Implementation follows best practices 4) Changes don't introduce new issues. Compare current code with the original suggestions."
EOF
print_success "Created /gemini-verify command (RESPONSE HANDLER)"
# Iterate with Gemini on changes
cat > "$CLAUDE_SETTINGS_DIR/gemini-iterate.md" << EOF
---
description: Show Gemini the changes and get iterative feedback
---
Get Gemini's feedback on the changes made based on previous suggestions.
!/gemini-cli:analyze @{currentFile} @package.json "Review the changes I just made based on your previous suggestions. ${cli_context}Provide feedback on: 1) Whether changes correctly address the original issues 2) Any improvements or adjustments needed 3) New issues that might have been introduced 4) Next steps for further improvement. Be specific and actionable."
EOF
print_success "Created /gemini-iterate command (RESPONSE HANDLER)"
# Get approval before proceeding
cat > "$CLAUDE_SETTINGS_DIR/gemini-proceed.md" << EOF
---
description: Confirm approach with Gemini before major changes
---
Get Gemini's approval on your implementation plan before making major changes.
What's your implementation plan?
!/gemini-cli:analyze @{currentFile} @package.json "Review this implementation plan: {input}. ${cli_context}Evaluate: 1) Will this approach solve the problem effectively? 2) Are there better alternatives? 3) What edge cases should be considered? 4) Any risks or dependencies to watch for? Give a clear GO/NO-GO recommendation with reasoning." model:"gemini-2.5-pro"
EOF
print_success "Created /gemini-proceed command (RESPONSE HANDLER)"
# END-TO-END WORKFLOW COMMANDS - Complete development cycles
# Fix and verify cycle
cat > "$CLAUDE_SETTINGS_DIR/gemini-fix-cycle.md" << EOF
---
description: Complete fix cycle - identify issues, fix them, verify with Gemini
---
Start a complete debugging cycle with Gemini's guidance.
What issue needs to be fixed?
!echo "Starting fix cycle for: {input}. I'll work with Gemini to: 1) Identify root cause 2) Implement fix 3) Verify solution. Using /gemini-fix for analysis, then implementing changes, then /gemini-verify to confirm."
EOF
print_success "Created /gemini-fix-cycle command (WORKFLOW)"
# Build and review cycle
cat > "$CLAUDE_SETTINGS_DIR/gemini-build-cycle.md" << EOF
---
description: Complete build cycle - plan, implement, review, iterate with Gemini
---
Start a complete feature building cycle with Gemini collaboration.
What feature do you want to build?
!echo "Starting build cycle for: {input}. Workflow: 1) Use /gemini-plan for architecture 2) Implement with regular /gemini-review checks 3) /gemini-test for test generation 4) /gemini-iterate for improvements. Creating comprehensive todo list with Gemini checkpoints."
EOF
print_success "Created /gemini-build-cycle command (WORKFLOW)"
# Security development cycle
cat > "$CLAUDE_SETTINGS_DIR/gemini-secure-cycle.md" << EOF
---
description: Security-focused development - audit, fix, re-audit with Gemini
---
Start a security-focused development cycle with continuous Gemini auditing.
What code or feature needs security hardening?
!echo "Starting security cycle for: {input}. Process: 1) /gemini-security initial audit 2) Implement all security fixes 3) /gemini-verify each fix 4) /gemini-audit for comprehensive re-check. Following OWASP guidelines with Gemini validation at each step."
EOF
print_success "Created /gemini-secure-cycle command (WORKFLOW)"
# Performance optimization cycle
cat > "$CLAUDE_SETTINGS_DIR/gemini-optimize-cycle.md" << EOF
---
description: Performance optimization cycle - analyze, optimize, measure with Gemini
---
Start a performance optimization cycle with Gemini's analysis.
What needs performance optimization?
!echo "Starting optimization cycle for: {input}. Steps: 1) /gemini-optimize for baseline analysis 2) Implement performance improvements 3) /gemini-verify optimizations maintain functionality 4) Measure improvements with Gemini. Creating metrics-driven optimization plan."
EOF
print_success "Created /gemini-optimize-cycle command (WORKFLOW)"
}
# Create direct CLI slash commands
create_cli_commands() {
print_header "Creating Direct CLI-powered slash commands"
mkdir -p "$CLAUDE_SETTINGS_DIR"
local cli_context=""
if [ -n "$AVAILABLE_CLIS" ]; then
cli_context="Available dev tools: $AVAILABLE_CLIS. "
fi
# Helper function to create file context reading
local file_context_cmd='
echo "=== Current File Context ==="
if [ -f "{currentFile}" ]; then
echo "File: {currentFile}"
echo "--- Content ---"
head -n 100 "{currentFile}"
echo "--- End Content ---"
fi
echo "=== Package.json Context ==="
if [ -f "package.json" ]; then
echo "--- Package.json ---"
cat package.json
echo "--- End Package.json ---"
fi
echo "=== Project Structure ==="
find . -type f -name "*.js" -o -name "*.ts" -o -name "*.py" -o -name "*.md" | head -20
echo "=== End Context ==="
'
# Core Commands - Using Direct CLI
# Enhanced Planning and architecture
cat > "$CLAUDE_SETTINGS_DIR/gemini-plan-cli.md" << EOF
---
description: Plan features with CLI - Simple and reliable
---
Plan this feature or project using direct Gemini CLI with project context.
What do you want to plan or build?
!bash -c "
echo '=== Project Analysis ==='
if [ -f package.json ]; then echo 'Package.json:'; cat package.json; fi
if [ -f README.md ]; then echo 'README:'; head -n 20 README.md; fi
echo '=== Source Structure ==='
find . -name '*.js' -o -name '*.ts' -o -name '*.py' | head -10
echo '=== Planning Request ==='
gemini -m gemini-2.5-pro 'Help plan this feature/project: {input}. ${cli_context}Based on the project context above, provide: 1) Architecture recommendations 2) Technology choices 3) Implementation steps 4) Integration considerations 5) Potential challenges. Be specific and actionable.'
"
EOF
print_success "Created /gemini-plan-cli command (CLI-Direct)"
# Context-aware best approach advice
cat > "$CLAUDE_SETTINGS_DIR/gemini-approach-cli.md" << EOF
---
description: Get best practice advice with CLI - No dependencies
---
Get expert best practice advice from Gemini CLI with project awareness.
What approach question do you have?
!bash -c "
echo '=== Project Context ==='
if [ -f package.json ]; then echo 'Tech Stack:'; cat package.json; fi
echo 'Selected Code: {selectedText}'
echo '=== Question ==='
gemini -m gemini-2.5-pro 'Approach question: {input}. ${cli_context}Based on the project context above, recommend: 1) Best practices for this tech stack 2) Pros/cons of different approaches 3) Implementation strategy 4) Common pitfalls 5) Security and performance considerations.'
"
EOF
print_success "Created /gemini-approach-cli command (CLI-Direct)"
# Smart function generation
cat > "$CLAUDE_SETTINGS_DIR/gemini-function-cli.md" << EOF
---
description: Generate functions with CLI - Direct gemini execution
---
Generate a function using direct Gemini CLI that matches your project style.
What function do you need?
!bash -c "
echo '=== Project Context ==='
if [ -f package.json ]; then echo 'Dependencies:'; cat package.json; fi
echo 'Code Context: {selectedText}'
echo '=== Function Request ==='
gemini 'Create function: {input}. ${cli_context}Requirements based on context: 1) Match existing code style 2) Use appropriate dependencies 3) Include error handling 4) Add proper documentation 5) Provide usage example. Make it production-ready.'
"
EOF
print_success "Created /gemini-function-cli command (CLI-Direct)"
# Comprehensive code review
cat > "$CLAUDE_SETTINGS_DIR/gemini-review-cli.md" << EOF
---
description: Code review with CLI - Fast and reliable
---
Review selected code with direct Gemini CLI execution.
!bash -c "
echo '=== Code Review Context ==='
echo 'File: {currentFile}'
echo 'Code to review:'
echo '{selectedText}'
if [ -f package.json ]; then echo 'Project dependencies:'; cat package.json; fi
echo '=== Review Request ==='
gemini 'Comprehensive code review. ${cli_context}Analyze for: 1) Security vulnerabilities and input validation 2) Performance issues and optimizations 3) Best practices for this technology 4) Code maintainability 5) Integration issues. Prioritize HIGH and CRITICAL findings with specific fixes.'
"
EOF
print_success "Created /gemini-review-cli command (CLI-Direct)"
# Enhanced code explanation
cat > "$CLAUDE_SETTINGS_DIR/gemini-explain-cli.md" << EOF
---
description: Explain code with CLI - Simple direct execution
---
Get detailed code explanation using direct Gemini CLI.
!bash -c "
echo '=== Code Explanation Context ==='
echo 'File: {currentFile}'
echo 'Code to explain:'
echo '{selectedText}'
if [ -f package.json ]; then echo 'Project context:'; cat package.json; fi
echo '=== Explanation Request ==='
gemini 'Explain this code in detail. ${cli_context}Cover: 1) What it does and its purpose 2) How it works step-by-step 3) Key concepts and patterns 4) Dependencies and integrations 5) Learning points. Use clear, educational language.'
"
EOF
print_success "Created /gemini-explain-cli command (CLI-Direct)"
# Smart debugging
cat > "$CLAUDE_SETTINGS_DIR/gemini-fix-cli.md" << EOF
---
description: Debug with CLI - Direct error analysis
---
Get debugging help using direct Gemini CLI with context.
What error or issue are you seeing?
!bash -c "
echo '=== Debug Context ==='
echo 'File: {currentFile}'
echo 'Error/Issue: {input}'
echo 'Code context:'
echo '{selectedText}'
if [ -f package.json ]; then echo 'Project setup:'; cat package.json; fi
echo '=== Debug Request ==='
gemini 'Debug this error: {input}. ${cli_context}Provide: 1) Root cause analysis 2) Step-by-step fix with code 3) Why this happened (education) 4) Prevention strategies 5) Related areas to check. Give working solution.'
"
EOF
print_success "Created /gemini-fix-cli command (CLI-Direct)"
# Enhanced security audit
cat > "$CLAUDE_SETTINGS_DIR/gemini-security-cli.md" << EOF
---
description: Security audit with CLI - Direct analysis
---
Perform security audit using direct Gemini CLI.
!bash -c "
echo '=== Security Audit Context ==='
echo 'File: {currentFile}'
echo 'Code to audit:'
echo '{selectedText}'
if [ -f package.json ]; then echo 'Dependencies:'; cat package.json; fi
if [ -f .env.example ]; then echo 'Environment template:'; cat .env.example; fi
echo '=== Security Audit ==='
gemini -m gemini-2.5-pro 'Security audit. ${cli_context}Analyze for: 1) Input validation issues 2) Authentication/authorization flaws 3) Data exposure risks 4) Dependency vulnerabilities 5) Configuration security. List only HIGH/CRITICAL issues with specific fixes.'
"
EOF
print_success "Created /gemini-security-cli command (CLI-Direct)"
# Enhanced general questions
cat > "$CLAUDE_SETTINGS_DIR/gemini-ask-cli.md" << EOF
---
description: Ask development questions with CLI - Simple and direct
---
Ask Gemini any development question using direct CLI.
What would you like to ask?
!bash -c "
echo '=== Question Context ==='
if [ -f package.json ]; then echo 'Project tech stack:'; cat package.json; fi
echo 'Question: {input}'
echo '=== Answer Request ==='
gemini 'Development question: {input}. ${cli_context}Answer considering: 1) Current project tech stack 2) Best practices 3) Practical implementation 4) Trade-offs and alternatives 5) Specific recommendations for this setup.'
"
EOF
print_success "Created /gemini-ask-cli command (CLI-Direct)"
# Response handler commands for CLI
cat > "$CLAUDE_SETTINGS_DIR/gemini-implement-cli.md" << EOF
---
description: Implement suggestions from Gemini CLI analysis
---
Implement Gemini's suggestions from previous CLI analysis.
What Gemini suggestions should I implement? (paste or describe)
!echo "I'll implement these Gemini CLI suggestions: {input}. I'll maintain code style, ensure proper testing, and verify all changes work correctly with the current project setup."
EOF
print_success "Created /gemini-implement-cli command (CLI Response Handler)"
# Additional CLI commands would continue here...
# For brevity, I'll add a few key ones
print_info "CLI command set created with direct gemini execution"
print_info "Commands use 'gemini-*-cli' naming to distinguish from MCP versions"
}
# Generate prompts file
generate_prompts() {
print_header "Creating copy-paste prompts"
cat > "$PROMPTS_FILE" << EOF
# 🚀 Gemini MCP + Claude Code: Next-Gen AI Development
## ✅ What's Ready
- Gemini MCP server integrated with Claude Code
- 12 intelligent slash commands with project context
- File-aware analysis using @filename syntax
- Project-wide security and performance audits
- Smart code generation with dependency awareness
## 🎯 Prerequisites & Setup
**Required:**
1. Install Gemini MCP server: \`claude mcp add gemini-cli -s user -- npx -y gemini-mcp-tool\`
2. Ensure Gemini CLI is authenticated: \`gemini auth\`
3. Run this setup script to create enhanced commands
## 🔥 How to Activate
### Option 1: One-Line Activation (Recommended)
Copy and paste this into Claude Code:
\`\`\`
Gemini MCP server is my AI development advisor with project-aware capabilities. Available commands:
CORE COMMANDS:
- /gemini-plan - Project-aware feature and architecture planning
- /gemini-approach - Best practices with tech stack context
- /gemini-function - Smart function generation matching project style
- /gemini-review - Comprehensive code review with dependencies
- /gemini-explain - Detailed code explanation with project context
- /gemini-fix - Smart debugging with full project awareness
- /gemini-security - Security audit with configuration analysis
- /gemini-ask - Context-aware development questions
ADVANCED COMMANDS:
- /gemini-test - Generate comprehensive tests for selected code
- /gemini-audit - Project-wide security audit across all files
- /gemini-optimize - Performance analysis of entire codebase
- /gemini-refactor - Intelligent refactoring with architectural awareness
Use these commands for project-aware AI assistance with automatic file context inclusion.
\`\`\`
### Option 2: Manual MCP Integration
#### For Architecture & Planning:
\`\`\`
Use /gemini-cli:analyze @package.json @src/* for project planning with full context
\`\`\`
#### For Code Analysis:
\`\`\`
Use /gemini-cli:analyze @{currentFile} @package.json for comprehensive code review
\`\`\`
#### For Safe Code Generation:
\`\`\`
Use /gemini-cli:sandbox for generating and testing new functions safely
\`\`\`
## 💡 Enhanced Command Capabilities
### Core Commands (MCP-Enhanced)
- **\`/gemini-plan\`** - Analyzes package.json, README, and source files for context-aware planning
- **\`/gemini-approach\`** - Considers project tech stack and dependencies for tailored advice
- **\`/gemini-function\`** - Uses sandbox mode for safe generation with project style matching
- **\`/gemini-review\`** - Comprehensive analysis including security, performance, and best practices
- **\`/gemini-explain\`** - Project-aware explanations with dependency context
- **\`/gemini-fix\`** - Smart debugging with full project context for better solutions
- **\`/gemini-security\`** - Analyzes code, configs, and dependencies for comprehensive security
- **\`/gemini-ask\`** - Project-aware answers considering your tech stack
### Advanced Commands (NEW)
- **\`/gemini-test\`** - Generates comprehensive tests using project's testing framework
- **\`/gemini-audit\`** - Project-wide security audit across all source files and configs
- **\`/gemini-optimize\`** - Performance analysis of entire codebase with specific recommendations
- **\`/gemini-refactor\`** - Architectural refactoring suggestions considering entire project
## 🚀 Usage Examples
### Planning with Full Context
1. Type: \`/gemini-plan\`
2. Enter: "user authentication with JWT"
3. Gets: Architecture advice based on your package.json dependencies and existing code
### Smart Code Review
1. Open a file in Claude Code
2. Type: \`/gemini-review\`
3. Gets: Security, performance, and best practice analysis with project context
### Intelligent Function Generation
1. Type: \`/gemini-function\`
2. Enter: "email validation with project's existing validation patterns"
3. Gets: Function that matches your existing code style and dependencies
### Project-Wide Security Audit
1. Type: \`/gemini-audit\`
2. Gets: Comprehensive security analysis of all source files, configs, and dependencies
## 🛠️ Pro Tips
- **File Context**: Commands automatically include relevant files (@package.json, @configs, etc.)
- **Project Awareness**: All commands consider your tech stack and dependencies
- **Smart Selection**: Use @src/* for project-wide analysis, @{currentFile} for specific files
- **Sandbox Safety**: Function generation uses safe sandbox environment
- **Multi-file Analysis**: Advanced commands can analyze entire project structure
## 🆘 Troubleshooting
- **Commands not showing?** Restart Claude Code after setup
- **MCP server issues?** Verify: \`claude mcp list\` shows gemini-cli
- **Authentication issues?** Run: \`gemini auth\` to re-authenticate
- **File not found errors?** MCP automatically handles missing files gracefully
## 🔗 MCP Integration Benefits
- ✅ **Native Claude Code integration** - No bash dependencies
- ✅ **File-aware analysis** - Automatic @filename context inclusion
- ✅ **Large context windows** - Leverage Gemini's full capabilities
- ✅ **Sandbox safety** - Secure code generation and testing
- ✅ **Project intelligence** - Understands your entire codebase
- ✅ **Dependency awareness** - Considers package.json and configs
Happy coding with next-generation AI assistance! 🎉
EOF
print_success "Created $PROMPTS_FILE"
}
# Choose integration approach
choose_integration_method() {
print_header "Choose Integration Method"
echo "Select how you want to integrate Gemini with Claude Code:"
echo ""
echo -e "${GREEN}1) MCP Server Integration (Recommended)${NC}"
echo " ✓ Native Claude Code integration"
echo " ✓ File-aware analysis with @filename syntax"
echo " ✓ Large context windows"
echo " ✓ Seamless project understanding"
echo " ✗ Requires MCP server installation"
echo ""
echo -e "${BLUE}2) Direct CLI Integration${NC}"
echo " ✓ Simpler setup (no MCP server needed)"
echo " ✓ Direct gemini command execution"
echo " ✓ Works in any bash environment"
echo " ✓ Easier troubleshooting"
echo " ✗ Manual file context handling"
echo " ✗ Smaller context windows per command"
echo ""
echo -e "${YELLOW}3) Hybrid Setup (Both Methods)${NC}"
echo " ✓ Best of both worlds"
echo " ✓ MCP commands + CLI fallbacks"
echo " ✓ Maximum flexibility"
echo " ✗ More commands to manage"
echo ""
echo "4) Show detailed comparison"
echo ""
while true; do
read -p "Enter your choice (1-4): " INTEGRATION_CHOICE
case $INTEGRATION_CHOICE in
1)
INTEGRATION_METHOD="mcp"
print_success "Selected: MCP Server Integration"
echo "Prerequisites: Ensure 'claude mcp add gemini-cli -s user -- npx -y gemini-mcp-tool' is run"
break
;;
2)
INTEGRATION_METHOD="cli"
print_success "Selected: Direct CLI Integration"
echo "No additional setup required beyond Gemini CLI authentication"
break
;;
3)
INTEGRATION_METHOD="hybrid"
print_success "Selected: Hybrid Setup (Both Methods)"
echo "This creates both MCP and CLI versions of each command"
break
;;
4)
show_integration_comparison
;;
*)
print_error "Invalid choice. Please enter 1, 2, 3, or 4."
;;
esac
done
echo ""
}
# Show detailed integration comparison
show_integration_comparison() {
print_header "Integration Method Comparison"
echo "┌─────────────────────┬──────────────────────┬──────────────────────┐"
echo "│ Feature │ MCP Server │ Direct CLI │"
echo "├─────────────────────┼──────────────────────┼──────────────────────┤"
echo "│ Setup Complexity │ Medium │ Simple │"
echo "│ Claude Integration │ Native │ Bash commands │"
echo "│ File Context │ Automatic @files │ Manual file reading │"
echo "│ Context Window │ Large (multi-file) │ Smaller (per-cmd) │"
echo "│ Project Awareness │ Excellent │ Good (manual) │"
echo "│ Troubleshooting │ MCP-dependent │ Direct CLI errors │"
echo "│ Performance │ Optimized │ Command-per-call │"
echo "│ Dependencies │ MCP Server │ Just Gemini CLI │"
echo "│ Reliability │ MCP + Network │ CLI + Network │"
echo "│ Best For │ Rich integration │ Simple reliability │"
echo "└─────────────────────┴──────────────────────┴──────────────────────┘"
echo ""
echo -e "${BLUE}Recommendations:${NC}"
echo "• ${GREEN}MCP Server${NC}: Choose if you want the best Claude Code integration"
echo "• ${BLUE}Direct CLI${NC}: Choose if you prefer simplicity and reliability"
echo "• ${YELLOW}Hybrid${NC}: Choose if you want both options available"
echo ""
read -p "Press Enter to continue..."
echo ""
}
# Generate status file
generate_status() {
cat > "$STATUS_FILE" << EOF
# ✅ Gemini MCP + Claude Code Setup Complete!
Setup completed: $(date)
## 🎯 Prerequisites Met:
### Gemini MCP Server
- ✓ Install command: \`claude mcp add gemini-cli -s user -- npx -y gemini-mcp-tool\`
- ✓ Authentication: \`gemini auth\` (user handles this)
- ✓ File-aware analysis with @filename syntax
- ✓ Sandbox mode for safe code generation
### Enhanced Slash Commands in Claude Code
#### Core Commands (MCP-Enhanced)
| Command | Purpose | MCP Features |
|---------|---------|-------------|
| /gemini-plan | Project-aware feature planning | Analyzes package.json + source files |
| /gemini-approach | Tech stack specific best practices | Considers dependencies + context |
| /gemini-function | Smart function generation | Sandbox mode + style matching |
| /gemini-review | Comprehensive code review | Multi-file security + performance |
| /gemini-explain | Project-aware code explanation | Dependencies + integration context |
| /gemini-fix | Smart debugging with context | Full project awareness |
| /gemini-security | Security audit with configs | Analyzes code + configurations |
| /gemini-ask | Context-aware development questions | Project-specific answers |
#### Advanced Commands (NEW)
| Command | Purpose | Capabilities |
|---------|---------|-------------|
| /gemini-test | Intelligent test generation | Project testing framework aware |
| /gemini-audit | Project-wide security audit | All files + dependency analysis |
| /gemini-optimize | Performance optimization | Entire codebase analysis |
| /gemini-refactor | Architectural refactoring | Project-wide pattern analysis |
### Available Development Tools
$AVAILABLE_CLIS
## 🚀 Next Steps:
### 1. Install MCP Server (If Not Done)
\`\`\`bash
claude mcp add gemini-cli -s user -- npx -y gemini-mcp-tool
\`\`\`
### 2. Authenticate Gemini (If Not Done)
\`\`\`bash
gemini auth
\`\`\`
### 3. Activate in Claude Code
1. **Open Claude Code**
2. **Copy the activation prompt** from \`$PROMPTS_FILE\`
3. **Paste it into Claude Code**
4. **Start developing with next-gen AI assistance!**
## 🧪 Quick Tests:
### Test File Analysis:
1. Open any source file in Claude Code
2. Type: \`/gemini-explain\`
3. See project-aware explanation with dependencies!
### Test Project Planning:
1. Type: \`/gemini-plan\`
2. Enter: "add user authentication"
3. Get architecture advice based on your tech stack!
### Test Security Audit:
1. Type: \`/gemini-audit\`
2. Get comprehensive project-wide security analysis!
## 🔧 Troubleshooting:
- **Commands not appearing?** Restart Claude Code
- **MCP issues?** Verify with: \`claude mcp list\`
- **Auth problems?** Re-run: \`gemini auth\`
- **File errors?** MCP handles missing files gracefully
## 🎉 What's New:
- ✅ **12 intelligent commands** (8 enhanced + 4 new)
- ✅ **Project-wide awareness** using @filename syntax
- ✅ **Automatic context inclusion** (package.json, configs, etc.)
- ✅ **Sandbox safety** for code generation
- ✅ **Multi-file analysis** capabilities
- ✅ **Dependency intelligence** for better recommendations
---
*Gemini MCP integration: Next-generation AI development workflow* 🚀
EOF
print_success "Created $STATUS_FILE"
}
# Main setup flow
main() {
echo -e "${BLUE}"
echo "╔══════════════════════════════════════════════════╗"
echo "║ Gemini + Claude Code Dual Integration ║"
echo "║ Next-Gen AI Development Workflow ║"
echo "╚══════════════════════════════════════════════════╝"
echo -e "${NC}"
echo "This setup creates intelligent slash commands with multiple integration options:"
echo ""
echo -e "${GREEN}🚀 MCP Server Integration:${NC}"
echo "• Native Claude Code integration with @filename syntax"
echo "• Large context windows for project-wide analysis"
echo "• Seamless multi-file understanding"
echo ""
echo -e "${BLUE}⚡ Direct CLI Integration:${NC}"
echo "• Simple bash-based gemini command execution"
echo "• No MCP server dependencies"
echo "• Reliable direct API communication"
echo ""
echo -e "${YELLOW}🔄 Hybrid Option:${NC}"
echo "• Both MCP and CLI commands available"
echo "• Maximum flexibility and reliability"
echo "• Best of both integration approaches"
echo ""
echo "All approaches include:"
echo "• Smart model selection (flash for speed, pro for depth)"
echo "• Project-aware AI analysis with context handling"
echo "• Context-smart code generation and review"
echo "• Project-wide security audits and optimization"
echo "• Intelligent refactoring and test generation"
echo ""
echo "Prerequisites (install these first):"
echo "• Update Gemini CLI: npm install -g @google/gemini-cli"
echo "• Verify installation: gemini --version"
echo ""
echo "• AUTHENTICATION (IMPORTANT - Choose one):"
echo -e " ${GREEN}RECOMMENDED:${NC} Use API Key (no browser popups!)"
echo " 1. Get free key: https://aistudio.google.com/apikey"
echo " 2. Run: export GOOGLE_API_KEY=\"your-key-here\""
echo -e " ${YELLOW}Alternative:${NC} OAuth with: gemini auth (may require re-auth)"
echo ""
echo "• Install MCP server: claude mcp add gemini-cli -s user -- npx -y gemini-mcp-tool"
echo ""
echo "Choose your integration approach during setup:"
echo "• MCP Server: Full Claude Code integration (requires MCP server)"
echo "• Direct CLI: Simple bash-based execution (minimal dependencies)"
echo "• Hybrid: Both approaches for maximum flexibility"
echo ""
echo "All approaches provide:"
echo "• 8+ core commands using flash model (fast, no rate limits)"
echo "• 7+ advanced commands using pro model (deep analysis)"
echo "• Response handler commands (implement, verify, iterate, proceed)"
echo "• Workflow commands (fix-cycle, build-cycle, secure-cycle, optimize-cycle)"
echo "• Smart model selection to avoid rate limits"
echo "• Complete development workflows with Gemini collaboration"
echo ""
read -p "Ready to set up next-gen AI development workflow? Press Enter..."
# Detect available tools
detect_available_clis
# Choose integration method
choose_integration_method
# Create commands based on chosen method
case $INTEGRATION_METHOD in
"mcp")
create_mcp_commands
;;
"cli")
create_cli_commands
;;
"hybrid")
create_mcp_commands
create_cli_commands
;;
esac
# Generate files
generate_prompts
generate_status
# Success message
print_header "🎉 Gemini Integration Setup Complete!"
case $INTEGRATION_METHOD in
"mcp")
echo "Your MCP Server integration is ready!"
;;
"cli")
echo "Your Direct CLI integration is ready!"
;;