(covers information from several alternate timelines)
This page contains information regarding Star Trek: Discovery, and thus may contain spoilers.
A commander in chief or chief in command (abbreviated C-in-C or CNC) was the supreme commander of an entire military or other type of service organization. If the person occupying this position was within the command hierarchy, they were the senior flag officer and by definition had the highest service rank possible.
Starfleet's chief in command was a position held by the senior fleet admiral, who took orders only from the President of the United Federation of Planets. (Star Trek VI: The Undiscovered Country) The Federation President, meanwhile, was considered to be the commander-in-chief of all Federation forces. (DS9: "Homefront")
In 2293, the Starfleet CNC was an admiral named Bill. That year, he attended a classified briefing at Starfleet Headquarters covering the destruction of the Klingon moon Praxis, the long-term stability of the Klingon Empire, and the Federation's subsequent diplomatic overtures. He later also attended the conference at which the Khitomer Accords were negotiated. (Star Trek VI: The Undiscovered Country)
Near the end of the 24th century, in 2399, the position was held by Fleet Admiral Kirsten Clancy. That year, she took a meeting with former Starfleet Admiral Jean-Luc Picard at which he alerted her to his belief that a team of Tal Shiar agents were operating on Earth itself and had assassinated a woman named Dahj Asha – whom he believed to be a Synthetic lifeform. Picard requested to be reinstated in Starfleet and given a ship and crew to investigate Asha's origins and locate other endangered Synths. Fleet Admiral Clancy angrily denied Picard's request, but subsequently ordered Commodore Oh, Chief of Starfleet Security, to investigate Picard's claims. Commodore Oh, secretly a Zhat Vash mole, disregarded Fleet Admiral Clancy's orders. (PIC: "Maps and Legends") When Picard later presented her with corroborating evidence from aboard the civilian transport La Sirena, Fleet Admiral Clancy agreed to send a squad of starships to support Picard and protect Soji Asha and La Sirena from the Zhat Vash. (PIC: "Broken Pieces")
On Earth, the President of the United States also served as the commander in chief of the armed forces of the United States, a role Abraham Lincoln fulfilled "during the four bloodiest years" of American history. (TOS: "The Savage Curtain")
The C-in-C of Starfleet named "Bill" in Star Trek VI was played by Leon Russom, and was never identified by his full name. (The novelization of Star Trek VI: The Undiscovered Country established his last name as Smillie.) In the script, however, he is labeled as the "Commander in Chief", while the the end credits labeled him as "Chief in Command". His uniform was notably different to that of other flag officers by having two stripes of gold piping around the tunic flap instead of just one (as the other admirals and commodores wore), three gold soutaches on his pants stripe (as opposed to one for commodores and admirals and two for fleet admirals) and a much larger fleet admiral insignia on his sleeve.
Fleet Admiral Morrow, who was identified as "Commander, Starfleet" in Star Trek III: The Search for Spock, might have been the commander in chief of Starfleet. The novelization of Star Trek III: The Search for Spock establishes that he was and the novelization of Star Trek IV: The Voyage Home establishes that Cartwright had succeeded him during the time Kirk and crew were on Vulcan.
In a later production, DS9: "Paradise Lost", the Federation President, Jaresh-Inyo, identifies himself as Vice Admiral Leyton's "commander in chief." This could mean that the president has the right to consider himself "commander in chief of the Federation", or its services, even though the post of "commander in chief of Starfleet" was a separate position within the subordinate organization. It could also mean that the Federation had a similar structure to the current United States with civilian overview by the president serving as commander in chief, and theater-wide commanders also known as commander in chief. In "Paradise Lost", Leyton, whose title is Chief of Starfleet Operations, does not seem to have any superior other than the president, so his position seems equivalent to the earlier commander in chief. It should be noted that when Admiral Kirk held the position of Chief of Starfleet Operations, he did have a superior, Admiral Nogura.
The possibility also exists that a person who has risen to the position of commander in chief of Starfleet might also be allowed to run for and be elected to the position of Federation president, holding both offices simultaneously. However, the enormously difficult division of labor and potential conflicts of interest which would result seem to make such a scenario unlikely. Moreover, according to Leyton's accusation and his own admission, President Jaresh-Inyo was not particularly adept at or enamored of military affairs, a fact that subverts the possibility of him holding both the offices of president and Starfleet commander in chief simultaneously.