In 2001, there were over 5,000 al Qaeda men in Afghanistan. Today that force has dwindled to less than a hundred, most of them hiding out in remote mountain valleys near the Pakistani border. This is Nuristan, in the foothills of the Hindu Kush mountains and lacking much in the way of roads, people, or visibility from the air. The area does have lots of forests and places to hide. Nuristan also serves as a convenient corridor for terrorists coming to or from Pakistan. This is how the few remaining al Qaeda men stay in touch and occasionally find work.
Many more (over a thousand) al Qaeda are across the border in Pakistan. The reasons for this disparity are many. First, it's easier to operate in Pakistan because many areas of the Pakistani tribal territories are free of government security forces. It has been that way for centuries. Across the border NATO and Afghan forces are free to go anywhere in Afghanistan to seek out al Qaeda. Another reason is racism. Arabs, who are dominant in al Qaeda, despise Afghans (and non-Arabs in general for that matter).
There have always been ethnic tensions within al Qaeda, and since September 11, 2001, more members of the group have been turning on each other because of that. One of al Qaeda’s weaknesses is that it is dominated by Arabs. This often causes resentment when the non-Arabs find themselves left out of decision making, or on the short end, when it comes to distribution of resources. This was first seen in Afghanistan, where the al Qaeda Arabs made themselves very unpopular several years before September 11, 2001. Those bad feelings then spread to Pakistan. There, hundreds of al Qaeda members hiding out in tribal areas along the Afghan border split along ethnic lines. The Arab al Qaeda, who still had access to a lot of cash, made themselves very unpopular with the al Qaeda members from Central Asia. The Central Asians, particularly Islamic radicals from Uzbekistan, always felt this was their turf and that the Arab al Qaeda should recognize that, and not throw their weight, and money, around in a disrespectful (to the Uzbeks) manner. Apparently some of the al Qaeda leaders captured in Pakistan over the last few years were the result of non-Arab al Qaeda giving up information they could have kept to themselves.
The Arab attitude problem in Afghanistan first showed up in the 1980s, when the Gulf Arabs contributed billions of dollars to the Afghan effort to fight the Russians in Afghanistan. The Arabs who showed up with this cash viewed the Afghans as a bunch of uneducated hicks and the Afghans picked up on this. It’s true that many of the senior Arab al Qaeda were well educated, much better than the average Afghan, but they would have been wise to keep any feelings of superiority to themselves. But they didn’t, and while there appear to have been attempts to act more diplomatically after al Qaeda survivors were driven into Pakistan in late 2001, this didn’t last.
After 2001, the basic problem for al Qaeda was self-preservation. The Pakistani army and intelligence forces came down hard on al Qaeda after the terrorists declared war on the Pakistani government in 2002. The al Qaeda led terrorists killed hundreds of Pakistanis and made several assassination attempts on the Pakistani president. When the Pakistani army showed up in the tribal territories in 2004, many of the tribes were no longer willing to host the terrorists. The army had never come into the tribal territories before and the tribes knew the soldiers were there now because of the al Qaeda threat to the government. The tribes could understand that and knew that the army meant business.
The army was also willing to negotiate and eventually get out of the territories if the al Qaeda members were handed over. Some tribes, or tribesmen, refused to do this. But there were fewer hiding places now, and the Arabs used their greater cash resources to save themselves, at the expense of Central Asian terrorists. Whatever bad feelings that existed between the Arabs and Central Asians before, now became much worse. This led to captured Central Asians giving up information on where Arab al Qaeda might be. This, combined with information obtained from tribesmen and other captured terrorists, led to the round-up of dozens of key al Qaeda leaders in the last few years.
The foreign al Qaeda members were unpopular in both Afghanistan and Pakistan, but the hatred was much more intense in Afghanistan because of the al Qaeda 55th brigade. This goes back to the late 1990s, when the Taliban used the 55th brigade of al Qaeda gunmen to keep unruly tribes in line. Most of the al Qaeda enforcers were Arabs, who did not hide their disdain for the "primitive" Afghans. This has not been forgotten. Moreover, Arabs stand out more in Afghanistan, where most Afghans are European or Central Asian in appearance (the majority of Afghans belong to ethnic groups related to the ones that overran Europe thousands of years ago). Afghans have been quick to turn in suspicious Arabs, or any suspected terrorist activities. So you have very few al Qaeda in Afghanistan and few of them are Arabs. Most of them appear to have lost the bad habits that annoyed Afghans so much and some have married local women. This makes it even more difficult to get them because now they are protected by their tribal in-laws.