expression
even at the cost of one's life; with one's life
Fixed expression used to emphasize that one will protect or defend something no matter what, even if it means risking death. Often followed by verbs like 守る or 護る.
この秘密は命に代えても守る。
I will protect this secret even at the cost of my life.
命に代えても家族を護る覚悟だ。
I am prepared to protect my family with my life.
命がけ is a noun or na-adjective meaning 'risking one's life' and can be used more broadly (e.g., 命がけの仕事). 命に代えても is a set adverbial phrase emphasizing the extreme cost, typically used with protective actions.
A fixed phrase composed of 命 (life), に (particle), 代えて (te-form of 代える, 'to substitute'), and も ('even'). Literally 'even substituting one's life', it has become a set expression meaning 'even at the cost of one's life'.