Gary Hocking wrote up some excellent tips on getting xdebug to work smoothly with PHPStorm while developing CLI tools (for example debugging a PHPUnit test). You can read his post here

I tend to work across a collection if environments and projects at once so its helpful for me to enable/disable debugging independent of my IDE. To achieve this I put the following aliases in my ~/.bash_aliases (or ~/.bashrc depending on the system) and it helps me toggle on and off debug.

alias xdebugon='export XDEBUG_CONFIG=idekey=PHPSTORM'
alias xdebugoff='unset XDEBUG_CONFIG'

Using it is as simple as

$ xdebugon
$ php myprogram.php --args
$ xdebugoff
$ #do some non debug work.

This doesn’t stop xdebug being in the php runtime, it just stops my IDE connecting to xdebug. When working in the CLI in and out of tools this is much faster than alt-tabbing to my IDE.