There's really no way around the possibility that whatever you've written down in your constitution will be ignored in the heat of the moment, or become degraded over time.
But you don't need to put the military under the direct command of the civilian president like US does, if parliament can take military action against the civilian president and civilian action against the military leader then they have ways to deal with both.
American president is too powerful to deal with since he controls both the civilian and the military side.
This is the one argument left for monarchy; that the military in the UK (and technically Australia) swear loyatly to the monarch, not the Prime Minister. In the event of an obviously-lunatic elected official ordering the troops into civilian areas to "pacify" civilian populations, the monarch could (in theory) countermand that order.
The monarch being Commander in Chief is ceremonial. Everything is done on the advice of the Prime Minister and their cabinet.
The chance of the monarch overriding said request is less than 1%.
Even then, parliament is sovereign. Whilst the logistics are complicated due to how things are introduced to the house, if parliament says no to a prime ministers decision, it overrides anything the prime minister who has no absolute power like a president does.
Monarchists can't have it both ways, though. Making him a ceremonial CiC isn't going to provide you with much of a bulwark against abuse of power by parliament. Or he isn't ceremonial and he could become a threat himself.
Personally I love the idea that the codes for nukes are surgically implanted in a volunteer, and in order to issue the order to fire the nukes, the CIC must personally carve the codes from that person's chest with a knife, killing them in the process. Or the variant on that idea, that the codes are implanted in their own forearm, and to order the nukes they must cut the codes from out of their own flesh.
We could do the same for all military deployment orders.
The government, unilaterally, against the country's prevalent feelings towards this illegal war of aggression, permitted USA to use British bases, and if I'm not mistaken, without as much as the parliament vote.
American president is too powerful to deal with since he controls both the civilian and the military side.