Change the API for the extensions. The method register and unregister must be called explicitly. The extensions are unregistered when the shell/cli is ended.
Provide a callback with the registerExtension function.