I’m a big fan of xdebug I’ve been using it for years to dig into scripts.
But I’ve only used it on websites. And as I’m dipping my toes into wp-cli the need for command line debugging is increasing.
Like often Jetbrains has a good guide to set it up: “Working with Remote PHP Interpreters in PhpStorm”
For those interested in xdebug and PhpStorm start here.