The commission was part of a $768 billion annual defence package passed by the Senate 89-10 after similarly overwhelming approval last week by the House of Representatives.
US President Joe Biden, who pulled out US troops in August to end America's longest war, is expected to sign the National Defence Authorisation Act.
The Commission on Afghanistan will include 16 members appointed by the two major parties and was given a deadline to issue an initial report within a year of its first meeting and a final report within three years.
"The commission shall conduct a comprehensive assessment of the war in Afghanistan and make recommendations to inform future operations with tactical and strategic lessons learnt, including the impact of troop increases and decreases and date-certain deadlines," the legislation said.
Former president Barack Obama poured tens of thousands of troops into Afghanistan after taking office in 2009 but later withdrew most of them.
The administration of his successor Donald Trump negotiated a deal with the Taliban that set a May 2021 deadline for US troops to leave.
The commission will also look at George W Bush's launch of the war as well as US policy on Afghanistan before 2001, when the September 11 attacks triggered the US invasion that overthrew the earlier Taliban regime.
The bill also boosts US defence spending from last year by $28bn, most of the increase not requested by the Biden administration.
It includes a 2.7 per cent pay raise for both military servicemembers and civilian workers at the Defence Department.
Amid intense polarisation in Washington, the bill sidestepped several issues including calls to impose sanctions over the Nord Stream 2 pipeline between Russia and Germany and to repeal the 2002 authorisation of the invasion of Iraq.