Gemini CLI Workflows
Master practical development workflows with Gemini CLI. Step-by-step examples for bug fixing, feature development, code review, test writing, refactoring, and documentation generation.
Workflow 1: Bug Fixing
One of the most valuable uses of Gemini CLI is tracking down and fixing bugs:
-
Describe the bug
Start by clearly describing the symptoms, including error messages, unexpected behavior, and steps to reproduce.
-
Let Gemini investigate
Gemini CLI will read relevant files, trace the code path, and identify the root cause.
-
Review the fix
Gemini proposes a fix with a diff. Review it carefully before approving.
-
Verify with tests
Ask Gemini to run the existing tests or write a new test that covers the bug.
# Step 1: Describe the bug > Users are getting a 500 error when they try to update their profile with a special character in their name (like O'Brien). The error log shows "unescaped single quote in SQL query." # Gemini reads the relevant files... Reading src/routes/profile.ts... Reading src/db/queries.ts... # Gemini identifies the issue: I found the problem. In src/db/queries.ts line 45, the user name is being interpolated directly into the SQL query string instead of using parameterized queries. This causes SQL injection vulnerabilities and breaks with special characters. # Gemini proposes the fix and tests
Workflow 2: Feature Development
Build new features by describing what you want in natural language:
# Describe the feature > Add a password reset flow to this Express app. It should: 1. POST /api/auth/forgot-password - accepts email, generates a reset token, sends an email 2. POST /api/auth/reset-password - accepts token and new password, validates token expiry, updates the password 3. Use the existing email service in src/services/ 4. Add rate limiting (max 3 requests per hour) 5. Tokens should expire after 1 hour # Gemini CLI will: 1. Read existing code to understand patterns 2. Create new route handlers 3. Add database migration for reset tokens 4. Integrate with existing email service 5. Add rate limiting middleware 6. Write tests for the new endpoints
Workflow 3: Code Review
Use Gemini CLI as a second pair of eyes before committing code:
# Review staged changes > Review my git diff and check for: - Bugs or logic errors - Security vulnerabilities - Performance issues - Missing error handling - Code style inconsistencies # Review a specific file > Review src/api/payments.ts for security issues. This handles credit card processing. # Review against best practices > Check if my React components follow current best practices. Look for: - Unnecessary re-renders - Missing memoization - Incorrect useEffect dependencies - Accessibility issues
Workflow 4: Test Writing
Generate comprehensive test suites for existing code:
# Generate tests for a specific file > Write comprehensive unit tests for src/services/order.ts using Jest. Cover: - Happy path for each function - Edge cases (empty inputs, nulls) - Error conditions - Async operations Use the existing test patterns from this project. # Generate integration tests > Write integration tests for the /api/orders endpoints. Test the full request/response cycle including database operations. # Add tests for untested code > Find functions with no test coverage and write tests for them. Start with the most critical ones.
Workflow 5: Refactoring
Restructure code while maintaining functionality:
# Extract common logic > The validation logic is duplicated across src/routes/users.ts, src/routes/products.ts, and src/routes/orders.ts. Extract it into a shared validation middleware. # Modernize code > Convert the callback-based database code in src/db/ to use async/await. Make sure all error handling is preserved. # Improve architecture > Refactor src/services/notification.ts to use the strategy pattern so we can easily add new notification channels (currently only email, need to add SMS and push notifications).
Workflow 6: Documentation Generation
Create documentation directly from your codebase:
# Generate API documentation > Generate OpenAPI/Swagger documentation for all API endpoints in this project. Include request/ response schemas, status codes, and examples. # Add inline documentation > Add JSDoc comments to all exported functions in src/utils/. Include parameter descriptions, return types, and usage examples. # Generate a README > Create a comprehensive README.md for this project covering: overview, installation, usage, API reference, contributing guidelines, and license.
💡 Try It: Fix a Real Bug
Find a known bug or TODO item in one of your projects. Start Gemini CLI, describe the issue, and let it investigate and propose a fix. Review the proposed changes carefully before accepting them. Compare the fix with what you would have done manually.
Lilly Tech Systems