What caused the war in Afghanistan?
I assume that you are asking about the conflict that we are currently in in Afghanistan. If so, the immediate cause of the conflict was the 9/11 terrorist attacks.
The 9/11 attacks were carried out the by Al-Qaeda terrorist group which was given safe haven in Afghanistan by the Taliban government that ruled the country at the time. Al-Qaeda had training camps in Afghanistan and was being allowed to stay there safely. The US and other countries invaded Afghanistan to topple the Taliban government and to try to destroy or capture as much of Al-Qaeda as possible.
If you want to take it a step back, you can say that the war in Afghanistan was caused in part by the Soviet invasion of that country in 1979. The US and others supported the "mujahideen" Muslim fighters who resisted the Soviets. It was, in part, out of these mujahideen that the Taliban arose.
But the immediate cause of this war was the 9/11 attacks and the desire of the US and others to prevent Al-Qaeda from continuing to have a safe haven in Afghanistan.