Many people contemplate divorce, but are still living in the same household with their minor children. The question then becomes - how is custody handled?
De Facto Agreement
One way to resolve the issue is for the parties to agree on which parent may have custody, and then allow him/her to move out with the children while the case is pending. It's best that each party have a lawyer and an interim stipulation be drawn up to this effect.
What if there's no agreement?
If there's no agreement, then neither parent should move out just yet. Instead, if there's either domestic violence present or same is imminent, then an application for exclusive occupancy and temporary custody should be filed. If that's not the case, then you will then just need to go through the process of a contested custody case. You should both have lawyers who have good experience handling such cases. Generally the Court will also assign an Attorney to represent the children - and generally will order (though not always) a forensic psychological evaluation on the custody issue.