Examples
Here are some practical examples of how to use AI CLI in your development workflow.
Search for Solutions
Debugging a TypeScript Error
ai search "TypeError: Cannot read property 'map' of undefined in React component"
This will:
- Search GitHub issues and Stack Overflow for similar errors
- Analyze the results with AI
- Provide a detailed solution with code examples
Finding Best Practices
ai search "React hooks best practices useEffect cleanup"
Troubleshooting Build Issues
ai search "pnpm install error ENOENT: no such file or directory"
Generate Documentation
Document a React Component
ai describe src/components/UserProfile.tsx
This will create src/components/UserProfile.md
with:
- Component overview
- Props documentation
- Usage examples
- Key implementation details
Document an API Service
ai describe src/services/api.ts
Debug Code
Debug a Complex Error
ai debug
# Then paste your error:
TypeError: Cannot read property 'map' of undefined
at UserList (./src/components/UserList.tsx:15:8)
at renderWithHooks (./node_modules/react-dom/cjs/react-dom.development.js:14803:9)
^D
# Then paste the relevant code:
const UserList = ({ users }) => {
return users.map(user => <UserCard key={user.id} user={user} />);
};
Collect and Analyze Code
Analyze a Feature
# Collect all TypeScript files in the feature directory
ai collect ./src/features/user-management
# This will:
# 1. Create a concatenated file in .ai-cli/user-management.txt
# 2. Generate an analysis in .ai-cli/user-management_analysis.md
Review a Module
# Collect and analyze a specific module
ai collect ./src/utils
Configuration Examples
Set Up Multiple AI Models
# Use Claude for search (faster, good for general queries)
ai config-model search anthropic claude-3-haiku-20240307
# Use GPT-4 for debugging (more detailed analysis)
ai config-model debug openai gpt-4
# Use Claude for documentation (good balance of speed and quality)
ai config-model describe anthropic claude-3-sonnet-20240229
Configure API Keys
# Set up Anthropic API key
ai config anthropic sk-ant-xxxxx
# Set up GitHub token for search
ai config github ghp_xxxxx
# Verify configuration
ai config-list
Real-World Workflow
Here's a complete example of using AI CLI in a typical development workflow:
- Start a New Feature
# Collect existing code to understand the codebase
ai collect ./src/features
- Debug an Issue
# Get AI-powered debugging help
ai debug
# Paste error and code
- Search for Solutions
# Find similar implementations
ai search "React form validation with TypeScript"
- Document Your Code
# Generate documentation for new components
ai describe src/features/new-feature/components/Form.tsx
- Review Changes
# Collect and analyze modified files
ai collect ./src/features/new-feature
Tips and Best Practices
- Use Search with Specific Limits
# Get more detailed results
ai search "React hooks" -g 5 -s 5
- Combine Commands
# Generate documentation and then search for improvements
ai describe src/components/DataTable.tsx
ai search "React table component best practices"
- Use Interactive Debug Mode
ai debug
# Take your time to paste the complete error stack trace
# Then provide relevant code context
- Keep Documentation Up to Date
# After making changes, regenerate documentation
ai describe src/components/UpdatedComponent.tsx