How to prevent full-screen exit on second monitor, when I close macbook lid?
Disable extended desktop

By default the system will attempt to use both the external monitor and internal display in a dual-display setup; however, you can force the system to only use one display with a custom boot argument PRAM setting . To do this, open the Terminal utility and run the following command:

sudo nvram boot-args="iog=0x0"


Following this command, restart the system and your system will now either use the internal display, or only use an attached external display. To revert this setting, you can either reset the PRAM or run the following command to clear this value from the boot arguments (reboot for the change to take effect):

sudo nvram boot-args=""


Source: