sonar_cleanup
Clean up unused SonarQube projects and expired tokens.
Description
Identifies and removes stale SonarQube projects and tokens that haven't been used recently. Helps maintain a clean SonarQube environment and free up resources.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
olderThanDays | number | No | 30 | Remove items older than N days |
dryRun | boolean | No | false | Preview without deleting |
Usage
Preview Cleanup
What old projects can be cleaned up?
Tool call:
{
"dryRun": true
}
Execute Cleanup
Clean up old SonarQube projects
Tool call:
{
"dryRun": false
}
Custom Age Threshold
Remove projects not used in 90 days
Tool call:
{
"olderThanDays": 90,
"dryRun": false
}
Response Format
Dry Run (Preview)
CLEANUP PREVIEW (DRY RUN)
━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ No changes will be made
📊 PROJECTS TO REMOVE (older than 30 days):
┌─────────────────────────────────────────┬───────────────┬────────────┐
│ Project Key │ Last Analysis │ Days Old │
├─────────────────────────────────────────┼───────────────┼────────────┤
│ old-test-project-abc123 │ 2023-10-15 │ 92 │
│ deprecated-api-def456 │ 2023-11-01 │ 76 │
│ temp-experiment-ghi789 │ 2023-12-01 │ 46 │
└─────────────────────────────────────────┴───────────────┴────────────┘
📋 TOKENS TO REVOKE:
┌─────────────────────────────────────────┬───────────────┬────────────┐
│ Token Name │ Last Used │ Days Old │
├─────────────────────────────────────────┼───────────────┼────────────┤
│ old-test-project-token │ 2023-10-15 │ 92 │
│ deprecated-api-token │ 2023-11-01 │ 76 │
└─────────────────────────────────────────┴───────────────┴────────────┘
SUMMARY:
Projects to delete: 3
Tokens to revoke: 2
Space to free: ~15 MB
To execute cleanup, run again with:
{ "dryRun": false }
Actual Cleanup
CLEANUP COMPLETE
━━━━━━━━━━━━━━━━
✅ Cleanup executed successfully
📊 PROJECTS REMOVED:
✓ old-test-project-abc123
✓ deprecated-api-def456
✓ temp-experiment-ghi789
📋 TOKENS REVOKED:
✓ old-test-project-token
✓ deprecated-api-token
SUMMARY:
Projects deleted: 3
Tokens revoked: 2
Space freed: ~15 MB
⚠️ These actions cannot be undone.
Recreate projects with sonar_auto_setup if needed.
Nothing to Clean
CLEANUP STATUS
━━━━━━━━━━━━━━
✅ Nothing to clean up
All projects and tokens are within the 30-day threshold.
Current status:
Active projects: 5
Valid tokens: 8
Oldest project: myapp-a1b2c3 (15 days ago)
Age Calculation
| Item | Age Based On |
|---|---|
| Projects | Last successful analysis |
| Tokens | Last usage for API call |
Examples
Example 1: Regular Maintenance
Prompt:
Clean up old projects from last month
Tool Call:
{
"olderThanDays": 30,
"dryRun": false
}
Example 2: Conservative Cleanup
Prompt:
Remove only very old projects (3+ months)
Tool Call:
{
"olderThanDays": 90,
"dryRun": false
}
Example 3: Safety Preview
Prompt:
Show me what would be cleaned without doing it
Tool Call:
{
"olderThanDays": 30,
"dryRun": true
}
What Gets Cleaned
Projects
- Projects created by Bob the Fixer
- No analysis in X days
- Associated data and history
Tokens
- Tokens created by Bob the Fixer
- Not used in X days
- Project analysis tokens
What's NOT Cleaned
- Projects created manually in SonarQube
- System/admin tokens
- Projects with recent activity
Safety Features
| Feature | Description |
|---|---|
| Dry run default | Preview before deleting |
| Bob-only cleanup | Only cleans Bob-created items |
| Activity check | Verifies no recent usage |
| Confirmation | Reports what was deleted |
Best Practices
- Always dry run first - Preview before executing
- Regular cleanup - Run monthly or quarterly
- Reasonable threshold - 30-60 days is typical
- Check before demos - Don't delete active projects
Common Issues
"No projects found"
Cause: No Bob-created projects exist.
Solution: This is normal for fresh installations.
"Permission denied"
Cause: Token lacks delete permissions.
Solution: Run sonar_diagnose_permissions to check.
"Some projects not deleted"
Cause: Projects have recent activity or were created externally.
Solution: Use SonarQube UI for manual cleanup.
Automation
For CI/CD cleanup:
# Example: Weekly cleanup job
cleanup:
schedule: "0 0 * * 0" # Weekly on Sunday
script:
- sonar_cleanup --older-than-days 60
Related Tools
sonar_delete_project- Delete specific projectsonar_config_manager- View configurationsonar_diagnose_permissions- Check permissions