Zayd bin Wahb reported,

The Messenger of Allah ﷺ, the truthful and trusted, told us, "Each one of you has his creation 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 an angel who is commanded with four matters. He is told to write down his deeds, his provision, his lifespan, and whether he will be wretched or happy. Then the soul is breathed into him.A man among you may perform the deeds of the people of Paradise until there is only a forearm's length between him and Paradise, but then what was written overtakes him, so he acts with the deeds of the people of the Fire and enters it. And another may perform the deeds of the people of the Fire until there is only a forearm's length between him and the Fire, but then what was written overtakes him, so he acts with the deeds of the people of Paradise and enters it."

Bukhari 3208

Sahih

حدثنا الحسن بن الربيع حدثنا أبو الأحوص عن الأعمش

عن زيد بن وهب قال عبد الله

حدثنا رسول الله ﷺ وهو الصادق المصدوق قال إن أحدكم يجمع خلقه في بطن أمه أربعين يوما ثم يكون علقة مثل ذلك ثم يكون مضغة مثل ذلك ثم يبعث الله ملكا فيؤمر بأربع كلمات ويقال له اكتب عمله ورزقه وأجله وشقي أو سعيد ثم ينفخ فيه الروح فإن الرجل منكم ليعمل حتى ما يكون بينه وبين الجنة إلا ذراع فيسبق عليه كتابه فيعمل بعمل أهل النار ويعمل حتى ما يكون بينه وبين النار إلا ذراع فيسبق عليه الكتاب فيعمل بعمل أهل الجنة

البخاري 3208صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Beginning of creation
Chapter
Angels
Numbering
Darussalam 3208
Bukhari 3208