Examples
Practical examples of using CommitWeave in real-world scenarios
Basic Examples
Simple Feature Addition
# Add a new user registration form
git add src/components/RegistrationForm.tsx
commitweave quick --type feat --scope auth
# Generated commit:
# feat(auth): ✨ add user registration form componentBug Fix with Context
# Fix validation error in login
git add src/utils/validation.ts
commitweave ai --context "Fix email validation regex that was rejecting valid domains"
# Generated commit:
# fix(auth): 🐛 resolve email validation for international domainsDocumentation Update
# Update API documentation
git add docs/api.md README.md
commitweave quick --type docs --message "update API documentation and README"
# Generated commit:
# docs: 📚 update API documentation and READMEAI-Powered Workflows
Staged-Only Commit Analysis
Let AI analyze only your staged changes without considering working directory files.
See commitweave ai for all available options.
# Stage specific files
git add src/auth/login.ts src/auth/session.ts
# AI analyzes only staged changes
commitweave ai
# AI generates based on staged diff:
# feat(auth): ✨ implement secure session managementAI Fallback Strategy
Configure fallback providers when primary AI service is unavailable.
Reference: commitweave ai options and troubleshooting AI issues.
# Primary: OpenAI, Fallback: Anthropic
export OPENAI_API_KEY="sk-..."
export CLAUDE_API_KEY="sk-ant-..."
commitweave ai --fallback --provider openai
# If OpenAI fails, automatically falls back to ClaudeAdvanced Team Workflows
Cross-Platform Development
# Unix-style development workflow
git add src/platform/unix/
commitweave quick --type feat --scope platform
export COMMITWEAVE_EDITOR="vim"
commitweave commit --editor vimMonorepo with Scoped Commits
Handle multiple packages in a single repository:
# Frontend changes
git add packages/web/ packages/mobile/
commitweave quick --type feat --scope "web,mobile"
# Generated:
# feat(web,mobile): ✨ add shared component libraryPerformance Optimization
Performance Flags
Optimize CommitWeave for large repositories.
See performance troubleshooting for more optimization tips.
# Skip expensive git operations
commitweave ai --fast --no-hooks
# Minimal analysis for speed
commitweave quick --type feat --fastGit Hook Integration
Advanced Hook Setup
#!/bin/sh
# .git/hooks/pre-commit
# Validate staged changes before commit
commitweave validate --staged --strict
if [ $? -ne 0 ]; then
echo "❌ Staged changes don't meet commit standards"
echo "💡 Run: commitweave doctor --fix"
exit 1
fiContinuous Integration
GitHub Actions Integration
# .github/workflows/commit-validation.yml
name: Validate Commits
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install CommitWeave
run: npm install -g commitweave
- name: Validate commit messages
run: |
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
# Validate PR commits
commitweave validate --range origin/main..HEAD --strict
else
# Validate pushed commits
commitweave validate --range HEAD~${{ github.event.push.commits.length }}..HEAD
fiError Recovery and Debugging
Commit Message Amending
Fix commits after they've been made:
# Let AI rewrite the last commit message
git add additional-changes.ts
commitweave ai --amend
# Combines staged changes with last commit
# and generates new messageDebugging and Diagnostics
See commitweave doctor reference for comprehensive diagnostic options.
# Debug AI response issues
commitweave ai --verbose --dry-run
# Shows:
# 🔍 Analyzing 5 staged files...
# 🤖 Calling OpenAI GPT-4 (tokens: 1200/4000)
# ✨ Generated message: feat(auth): implement OAuth2...Advanced Configuration Examples
Dynamic Configuration
# Different config per project type
if [ -f "package.json" ]; then
# Node.js project
commitweave ai --config .commitweave.node.json
elif [ -f "Cargo.toml" ]; then
# Rust project
commitweave ai --config .commitweave.rust.json
else
# Default config
commitweave ai
fiIntegration Examples
IDE Integration
# VS Code task configuration
# .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "CommitWeave: AI Commit",
"type": "shell",
"command": "commitweave",
"args": ["ai"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}Next Steps:
- See the complete CLI Reference for all command options
- Check Troubleshooting when issues arise
- Review Configuration Templates for team setups