I'm trying to write a plugin that changes the layout when the last tab in a group is closed, but when trying to call the set_layout command in the on_close method, sublime crashes. Any pointers on how I should go about it?

Have you tried using sublime.set_timeout with a callback that changes the layout? Try for maybe 400 ms to start, and keep in mind that it's a weird race condition thing and if you have a fast computer it could crash on other people's.Not that I had a bad experience crashing Sublime while trying to change the layout or anything...