Much of war strategy was keeping tabs on the troops of others. Pursuit or retreat/evasion could be a response to near contact. Cat and mouse kind of ,with some leaders seeming to avoid other/enemy troops too much. (Lincoln had a heck of a time sometimes getting much (or any) , offensive action out of certain leaders despite their knowing who was where.)
Defensive lines / digging in and or building breastworks stopped an outfit pushed too hard sometimes ,or wanting to make a defense at a particular location.. Now lines are established regardless of colors. Yes skirmishers or scouts or signal corps or cavalry could be adjacent or deployed , but part of strategy was keeping tabs on who was where and when/where to slug it out.
But coordination by knowing who was where was not always successful...
Chancellorsville. At night. Jackson. What happened?
Mosby's Rangers likely were out of contact more often than they were in contact/communication of whereabouts.
Obviously had their /a manner of entering a picketed perimeter /i.d.ing themselves.
Many leaders were in prior wars. Even fought together.
With West Point educations in common too, an informal formality could give some structure in terms of more formal lines of fighting. Lines often shuffled and crossed of course , but artillery positions and who held the in a major engagement left little question as to who's Army was where.
Previous and current scouting/recon kept tabs on particular leaders movements. Usually.
Cloths mattered , but as far as telling who was on who's side out of uniform....(or for those lacking uniform) One wants to say it's by who's camp or troops they are with.
But...Even if they're in your Army's uniform ,do you trust some one you don't know approaching your position out of the blue should pass?
Now West Point or your leaders procedure is in effect. Or.......