The Messenger of Allah ﷺ, the truthful and trusted, told us, "The creation of each one of you is gathered in his mother's womb for forty days, then he becomes a clinging clot for the same period, then a lump of flesh for the same period. Then Allah sends the angel to him, who is commanded with four matters. He is told, 'Write down his deeds, his lifespan, his provision, and whether he will be wretched or blessed.' By the One in whose hand is my soul, one of you may perform the deeds of the people of Paradise until there is only an arm's length between him and it, then what was written overtakes him, so he performs the deeds of the people of the Fire and enters it. And one of you may perform the deeds of the people of the Fire until there is only an arm's length between him and it, then what was written overtakes him, so he performs the deeds of the people of Paradise and enters it."
حدثنا علي بن محمد حدثنا وكيع ومحمد بن فضيل وأبو معاوية ح و حدثنا علي بن ميمون الرقي حدثنا أبو معاوية ومحمد بن عبيد عن الأعمش عن زيد بن وهب قال
حدثنا رسول الله ﷺ وهو الصادق المصدوق أنه يجمع خلق أحدكم في بطن أمه أربعين يوما ثم يكون علقة مثل ذلك ثم يكون مضغة مثل ذلك ثم يبعث الله إليه الملك فيؤمر بأربع كلمات فيقول اكتب عمله وأجله ورزقه وشقي أم سعيد فوالذي نفسي بيده إن أحدكم ليعمل بعمل أهل الجنة حتى ما يكون بينه وبينها إلا ذراع فيسبق عليه الكتاب فيعمل بعمل أهل النار فيدخلها وإن أحدكم ليعمل بعمل أهل النار حتى ما يكون بينه وبينها إلا ذراع فيسبق عليه الكتاب فيعمل بعمل أهل الجنة فيدخلها
Bukhari narrated it in the chapter on divine decree, hadith no. 6594, and others also narrated it, and Muslim narrated it in the chapter on divine decree, in the section on how a human being is created, etc., hadith no. 2643, from the hadith of Amash, through this chain. Muslim also narrated it from the hadith of Abu Muawiya and Waki, through this chain.