Creating Custom Tools

Extend Gemini CLI with custom tools, scripts, and integrations tailored to your specific workflow needs.

Custom Aliases

Create shortcuts for frequently used commands:

gemini config set alias.review "Review this code for bugs and improvements:"

gemini config set alias.docs "Generate documentation for:"

gemini config set alias.test "Create unit tests for:"

Usage: gemini review < myfile.js

Shell Script Integration

Code Review Script

#!/bin/bash

# review-code.sh

for file in "$@"; do

echo "Reviewing $file..."

gemini "Review this code" < "$file" > "$file.review"

done

Documentation Generator

#!/bin/bash

# generate-docs.sh

gemini "Create comprehensive documentation" < "$1" > "docs/$(basename "$1" .js).md"

API Integration Tools

Custom MCP Server

Create your own MCP server for specific APIs:

npm create mcp-server my-custom-tool

cd my-custom-tool

# Edit src/index.ts with your custom logic

npm run build

gemini mcp add my-tool ./dist/index.js

External API Wrapper

#!/bin/bash

# jira-integration.sh

TICKET_ID="$1"

DESCRIPTION=$(gemini "Summarize these changes" < changes.diff)

curl -X POST "https://company.atlassian.net/rest/api/2/issue/$TICKET_ID/comment" \

-H "Authorization: Basic $JIRA_TOKEN" \

-d "{"body": "$DESCRIPTION"}"

Workflow Automation

Git Hook Integration

#!/bin/bash

# .git/hooks/pre-commit

changed_files=$(git diff --cached --name-only --diff-filter=AM | grep '\\.js$')

for file in $changed_files; do

issues=$(gemini "Find potential issues" < "$file")

if [[ "$issues" == *"CRITICAL"* ]]; then

echo "Critical issues found in $file"

exit 1

fi

done

CI/CD Integration

# GitHub Actions workflow

- name: Code Analysis

run: |

for file in $(git diff --name-only HEAD~1); do

gemini "Analyze for security issues" < "$file" >> security-report.md

done

Custom Prompt Templates

Template Configuration

{ "templates": { "security-review": "Perform a thorough security review of this code, checking for: SQL injection, XSS vulnerabilities, authentication bypass, data validation issues, and insecure dependencies. Provide specific recommendations.", "performance-audit": "Analyze this code for performance bottlenecks including: algorithmic complexity, memory usage, I/O operations, and caching opportunities. Suggest specific optimizations.", "accessibility-check": "Review this frontend code for accessibility compliance including: ARIA labels, keyboard navigation, color contrast, screen reader compatibility, and WCAG 2.1 guidelines." } }

Usage: gemini template security-review < auth.js

Real-World Integration Examples

Slack Notifications

Send code review summaries to team channels

Issue Tracking

Auto-create tickets for detected code issues

Documentation Updates

Automatically update docs when code changes

Code Metrics

Generate complexity and quality reports

Build Your Tools

Start creating custom tools for your workflow: