$UserBaseDirectory/Kernel/init.m the most obvious place to put code which should be autoloaded has been mentioned.
But I think it might be worth mentioning that there is also the
Autoload directory within
$UserBaseDirectory where you can put any package file or package directory and those will automatically be loaded at startup. For the purpose mentioned I think that might be an even better place (after having the code set up as a proper package of course...).
init.m files and
Autoload packages are loaded during kernel initialization when certain functions, such as
Catch, cannot be safely evaluated. A lot of complex functionality depends on these, and is therefore unsafe to use in init files. It is generally best to limit initialization files to issuing definitions and basic operations.
The initialization is done in this order:
- load paclet manager
- load files passed with the
-initfile command line option
The loading is triggered in
SystemFiles/Kernel/SystemResources/$SystemID/sysinit.m, which you can examine for more information on the initialization process. Some documentation is here.
Subkernels used by the parallel tools are launched with
-noinit, so they don't load the standard
Kernel/init.m files. They do load