Pakistan never wanted anything to do with the American war on the Taliban. An ideological congruence existed between the Taliban and powerful elements in Pakistan. An Islamist regime gave Pakistan strategic depth to its east against India. Afghan Islamists had been valuable allies in the war against the Soviets. Pashtun values have a powerful appeal for some kinds of people, even if they aren’t Pashtuns.
On the other hand, after 9/11, Americans were hot under the collar. Richard Armitage flew into Pakistan and made Pervez Musharraf an offer he couldn’t refuse. But neither Armitage nor Musharraf supposed that the Americans would still be in Afghanistan 17 years later. They were going to invade the country, kill Osama bin Laden and his merry men, and leave. Yet, here we still are, with no clear purpose except to avoid defeat. In the meantime, Pakistan’s policy has turned back to its original pole-star. Moreover, it has sought alternatives to being bullied by the Americans.
Pakistan sees India as its essential enemy. Pakistan blames India for the dismemberment of greater Pakistan in the successful secession of East Pakistan/Bangladesh. The Pakis believe that India has been supporting a secessionist movement in Baluchistan. Paki leaders have, for a long time, suspected that India would exploit conditions in Afghanistan as a way to put pressure on Pakistan. In particular, Afghanistan has long argued that the existing Afghan-Pakistan border needs to be revised. To this end, Pakistan has pursued closer relations with both China and Iran. Since 2017, Pakistan has been trying to patch up its relationship with Russia.
So long as the United States remains in Afghanistan, it is subject to pressure from Pakistan. The chief supply routes to American forces there run through Pakistan. To this end, the Obama administration and the early Trump administration tried to rein-in India in Afghanistan. They hoped to conciliate Pakistan and win its support against the Taliban. At the same time, the United States has poured in financial and military aid, while soft-pedalling concerns about Pakistan’s nuclear weapons. On the other hand, American troops and American drones have attacked Taliban forces in their Pakistani safe-havens. This has enraged Pakistanis. For example, in 2011, anti-American protests flashed across Pakistan. These temporarily shut down supply routes to American forces in Afghanistan.
That approach has not worked. In August 2017, the Trump administration called on India to do more in the fight in Afghanistan. This guaranteed a bad reaction from Pakistan.
During the Clinton administration, the Taliban sheltered Al Qaeda from a combination of ideological congruence and Pashtun values. The United States hesitated to attack Al Qaeda from a combination of prudence (not wanting to accidentally set off an Indo-Pakistan nuclear war) and incredulity (that a tiny movement could actually declare war on the United States, that the U.S. could kill the people responsible, and that Bill Clinton—a “dope-smoking draft dodger”–could be president). While the Paki conditions still apply, none of the American ones do. Get out.
 Yarioslav Trofimov, “”Pakistan’s Fears Fuel Afghan War,” WSJ, 25 August, 2017
 There is a lot of self-delusion in this view.