All over CHDK we use things like
if (mode_get()&MODE_MASK) == MODE_REC) foo()
to determine the current mode. Search the code around for mode_get() and more examples of its use. AFAIK mode during startup is not stored permanently, but if you find it to be necessary, I suppose you need add this to a suitable place near CHDK startup. I don't know what the perfect place would be and how foolproof it will be (I often press the power on button and switch to rec mode pretty much simultaneously, often switching to REC mode before CHDK has fully booted; I've made it a habit to keep the rec/play lever in 'play' when the camera is not in use so that the lens wouldn't come out if the button gets pressed accidentally).