I am using WP-CLI shell to quickly debug some code, but every time I run into a fatal exception (e.g. undefined constants/functions) the shell exits and I lose my shell session. Is there a way to prevent this?

wp> new DoesntExist();
Fatal error: Class 'DoesntExist' not found in phar:///usr/local/bin/wp/php/WP_CLI/REPL.php(37) : eval()'d code on line 1

Shell exits..


1 Answer 1


This is the default behavior of WP-CLI's built-in PHP REPL. If you look at the wp shell documentation, it shows that you can also use the Boris or PsySH PHP REPLs.

The Boris REPL does not seem to be actively maintained; however the PsySH REPL has fairly recent maintenance, and it fixes the problem that you're experiencing.

The easiest way to integrate PsySH with WP-CLI is to use the wp-cli-psysh plugin:

# Make sure WP-CLI is up to date
wp cli update

# Install the plugin
wp package install [email protected]:schlessera/wp-cli-psysh.git

After installing the plugin, running wp shell should show you a PsySH header that's similar to this:

$ wp shell

Psy Shell v0.9.9 (PHP 7.3.1-1+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman

  • I'm noticing installing schlessera/wp-cli-psysh requires memory_limit > 512M, or install process will run out of memory. Setting 1024M worked everywhere, I didn't bother trying intermediary values.
    – lkraav
    Feb 13, 2020 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.