The cleanup command removes stale session files, kills orphaned daemon processes, and optionally terminates Chrome instances. Use this to recover from crashed sessions or clean up after abnormal termination.
# Ensure clean state before test runbdg cleanup --aggressive# Run testsbdg https://staging.example.com --headless# ... test commands ...bdg stop# Cleanup after (removes output too)bdg cleanup --remove-output
Error: Session is still active (PID 12345)Suggestion: Stop gracefully: bdg stop Force cleanup: bdg cleanup --forceWarning: Force cleanup will remove session files but will NOT kill the running process
When to Use Cleanup: Run cleanup when bdg status shows no session but you can’t start a new one, or after crashes/force quits.
Stale Detection: If a session appears active but you force cleaned it, the running daemon will continue operating but be inaccessible. Use --aggressive to kill it.
CI/CD Best Practice: Always run bdg cleanup --aggressive before AND after test runs to ensure clean state.
Data Loss: Cleanup removes session files without saving data. If you need the data, use bdg stop instead.
Aggressive Mode Danger: --aggressive kills ALL Chrome instances on the system using chrome-launcher.killAll(). Don’t use if you have other Chrome windows open.
Force Cleanup Limitation: --force removes files but doesn’t terminate processes. The orphaned daemon/Chrome may consume resources until killed manually or with --aggressive.