They trace their roots to the immediate aftermath of the Sept. 11, 2001, attacks, when the C.I.A. began assembling a patchwork alliance of warlord-led fighting groups to topple the Taliban and pursue Qaeda fighters.

After the fall of the Taliban and the establishment of a new Afghan government, the C.I.A.’s shadowy paramilitary arm, known as Ground Branch, began transforming the fighting groups. Some developed into large, well-trained and equipped militias that initially worked outside the auspices of the Afghan government. The militias were used for sensitive and covert missions, including pursuing terrorist leaders across the border into Pakistan’s lawless frontier territory.

In more recent years, the agency’s hold over militant groups and other regional counterterrorism forces and strike teams has waned some, former officials said. Many of the militias now fall under the command of Afghanistan’s own intelligence service, the National Directorate of Security. But there is little doubt they are still advised, and often directed, by the C.I.A.

The Taliban’s disdain for the C.I.A.’s Afghan counterpart has been apparent in recent months. In July, a bomb targeting the Afghan covert service killed eight members and six civilians, and wounded hundreds more. In January, Taliban fighters infiltrated an Afghan intelligence base in Wardak Province, killing dozens in one of the deadliest attacks on the service during the nearly 18-year war.

Fighting in Afghanistan has increased since peace discussions began as both sides try to strengthen their positions. Taliban fighters mounted two attacks over the weekend, including one in the northern city of Kunduz that killed the top police spokesman and wounded the police chief, according to local officials.

In a Fox News interview last week, President Trump alluded to keeping American forces, and perhaps the C.I.A., in Afghanistan after any deal with the Taliban is reached. “We are reducing that presence very substantially and we’re going to always have a presence and we’re going to have high intelligence,” he said.