Better environment detection for CLI