Khalili was born in Kabul Province, and came from the same village as Habibullah Kalakani. He wrote exclusively in Persian and is sometimes associated with Tajik nationalist ideology. He belonged to the Pashtun Safi tribe of Kohistan (modern Parwan). His father, Mirzā Muhammad Hussein Khān, was King Habibullah Khan's finance minister and owned mansions in Kabul and Jalalabad, but was later dismissed and hanged by Habibullah Khan's son and successor, Amanullah Khan. His mother was the daughter of Abdul Qādir Khān, a regional Safi tribal leader. She died when Khalili was seven.