How to execute custom code at start of macro-user-callerid?

every auto-generated context has an include => contextname-custom

In many cases, this is not usable, as you have learned from reading how Asterisk processes includes. This is just auto-generated everywhere as there is no harm and some places it is useful.

If you want to put your own code in an auto-generated context, you have two options:

You can write a module that spices into the beginning of the context and adds your code. Have a look at modules like blacklist which do that with inbound routes, or languages which splice into the middle of macro-user-callerid.

Your other option is to completely re-define the entire macro by copying it into the override file and then modifying it. Be very careful if you do this. First keep in mind that future updates to that macro, like new functionality or bug fixes, will be overwritten by your change. Secondly, make sure you replace every single priority that is in the original macro or include appropriate ‘hangup’ or alternative instructions because anything that you don’t cover will have ours blended into yours and you can get some really hard to find bugs.