Proving an identity used in general relativity I need to prove the following identity for scalar field ($\phi:M\rightarrow R$) in curved spacetime without torsion called $M$
$\nabla_{\mu}[\Box \phi \nabla^{\mu}\phi-\frac{1}{2}\nabla^{\mu}(\nabla \phi)^{2}]=(\Box \phi)^{2}-
R_{\mu\nu}\nabla^{\mu}\phi\nabla^{\nu}\phi- \nabla^{\mu}\nabla^{\nu}\phi \nabla_{\mu}\nabla_{\nu}\phi$.
I opened up the total derivative and the term $(\Box \phi)^{2}$ appears but the others I cannot get the right combination. I tried to use the following  identity to make appears the terms $R_{\mu\nu}\nabla^{\mu}\phi\nabla^{\nu}\phi$, namely, $[\nabla_\mu, \nabla_\nu]X_{\alpha}=-R^{\kappa}_{\alpha\mu\nu}X_{\kappa}$, but I got stuck at some point, and the  third term does not appear at all.
Any help would be much appreciated.
 A: This is the differential form of the Reilly formula. It holds for a function on any pseudo-Riemannian manifold. (Robert C. Reilly. Applications of the Hessian operator in a Riemannian manifold, Indiana Univ. Math. J. 26 (1977), no. 3, 459–472, doi:10.1512/iumj.1977.26.26036)
Use the product rule to say
$$(\Delta f)^2=\operatorname{div}(\Delta f\cdot\nabla f)-\langle\nabla f,\nabla\Delta f\rangle.$$
Use the commutation formula for covariant derivatives to replace the last term by
$$\langle\nabla f,\nabla\Delta f\rangle=\langle\nabla f,\Delta\nabla f\rangle-\operatorname{Ric}(\nabla f,\nabla f).$$
Use the product rule to replace the second to last term by
$$\langle\nabla f,\Delta\nabla f\rangle=\operatorname{div}\big(\nabla^2f(\nabla f,\cdot)\big)-|\nabla\nabla f|^2.$$
Finally $\nabla^2f(\nabla f,\cdot)=\frac{1}{2}\nabla|\nabla f|^2$. This gives your formula.
Edit. As pointed out by Jeffrey Case below, this also follows from the Bochner formula
$$\frac{1}{2}\Delta|\nabla f|^2=|\nabla\nabla f|^2+\langle\nabla\Delta f,\nabla f\rangle+\operatorname{Ric}(\nabla f,\nabla f),$$
where you just need to use the very first line above to replace the middle term on the RHS. The proof of the Bochner formula is by the other lines above
