The basic solution is to define a base class or interface that can be accessed by the statically compiled code, then extend that base class or implement that interface in the generated class.
So, to change what the compiled template code looks like, we just have to create a new skeleton file and perform whatever customization we want, but still leave these basic elements in place.
Source code instrumentation: the most basic technique is to add instrumentation at the source code phase so that the compiled and deployed classes already contain the instrumentation at run time.