This follows Carroll's Gravity book (page 110).
An observer with four-velocity $U^{\mu}$ (such that $g_{\mu\nu}U^{\mu}U^{\mu}=-1$) measures the energy of a particle along a geodesic $$p^{\mu} = \frac{dx^{\mu}}{d\lambda}\tag{3.62}$$ to be $$ E = - p_{\mu}U^{\mu} \ , \tag{3.63} $$ where the particle is on either a timelike or null geodesic.
Can someone give some more intuition as to where this comes from? I see that it is an invariant and so will be the same in all frames, sot hat makes sense.
However what's confusing me is for generic $U^{\mu} = ( U^0, \mathbf{U} )$ and $p^{\mu} = (p^0, \mathbf{P})$ this has a nontrivial form, and I don't understand why this is the energy of the particle. Should this be simply understood as a definition of energy?