Politics, of course, was also on her mind. Barack Obama was laying the groundwork for his candidacy in mid-January with a campaign that would emphasize his opposition to the Iraq War and her vote in favor of it — a vote that still shadows her in this year’s Democratic primaries. Obama was setting off on a fund-raising drive that would net $25 million in three months, sending tremors through Clinton’s political camp and establishing him as a formidable rival. Although she disagreed with Keane about Iraq, Clinton asked him to become a formal adviser. “As much as I respect you,” he replied, “I can’t do that.” Keane’s wife had health problems that had moved up his retirement from the Army, and he did not, as a policy, endorse candidates. Sometime during 2008 — he doesn’t remember exactly when — Clinton told him she had erred in doubting the wisdom of the surge. “She said, ‘You were right, this really did work,’ ” Keane recalls. “On issues of national security,” he says, “I thought she was always intellectually honest with me.”

He and Clinton continued to talk, even after Obama was elected and she became secretary of state. More often than not, they found themselves in sync. Keane, like Clinton, favored more robust intervention in Syria than Obama did. In April 2015, the week before she announced her candidacy, Clinton asked him for a briefing on military options for dealing with the fighters of the Islamic State. Bringing along three young female analysts from the Institute for the Study of War, Keane gave her a 2-hour-20-minute presentation. Among other steps, he advocated imposing a no-fly zone over parts of Syria that would neutralize the air power of the Syrian president, Bashar al-Assad, with a goal of forcing him into a political settlement with opposition groups. Six months later, Clinton publicly adopted this position, further distancing herself from Obama.

“I’m convinced this president, no matter what the circumstances, will never put any boots on the ground to do anything, even when it’s compelling,” Keane told me. He was sitting in the library at his home in McLean, Va., which is lined with books on military history and strategy. His critique of Obama was hardly new or original, but much of it mirrors the thinking of Clinton and her policy advisers. “One of the problems the president has, which weakens his diplomatic efforts, is that leaders don’t believe he would use military power. That’s an issue that would separate the president from Hillary Clinton rather dramatically. She would look at military force as another realistic option, but only where there is no other option.”

Befriending Keane wasn’t just about cultivating a single adviser. It gave Clinton instant entree to his informal network of active-duty and retired generals. The most interesting by far was David Petraeus, a cerebral commander who shared Clinton’s jet-fueled ambition and whose life stories would mix heady success with humbling setbacks. Both would be accused of mishandling classified information — Clinton because of her use of a private server and email address to conduct sensitive government business, a decision that erupted into a political scandal; Petraeus because he had given a diary containing classified information to his biographer and mistress (he was eventually charged with a misdemeanor for mishandling classified information).

On Clinton’s first trip to Iraq in November 2003, Petraeus, then a two-star general commanding the 101st Airborne Division, flew from his field headquarters in Mosul to the relative safety of Kirkuk to brief her congressional delegation. “She was full of questions,” he recalls. “It was the kind of gesture that means a lot to a battlefield commander.” On subsequent trips, as he rose in rank, Petraeus walked her through his plans to train and equip Iraqi Army troops, a forerunner of the counterinsurgency strategy in Afghanistan. It worked to their mutual benefit: Petraeus was building ties to a prominent Democratic voice in the Senate; Clinton was burnishing her image as a friend of the troops. “She did it the old-fashioned way,” he says. “She did it by pursuing relationships.” When Petraeus was sent back to Iraq as the top commander in early 2007, he gave every member of the Senate Armed Services Committee a copy of the U.S. Army/Marine Corps Counterinsurgency Field Manual, which he edited during a tour at Fort Leavenworth. Clinton read hers from cover to cover.