Abdullah bin Masud reported,

The Messenger of Allah ﷺ, the truthful and trustworthy, told us, "The creation of each one of you is gathered in his mother's womb for forty days and forty nights. Then he becomes a clot of blood for a similar period, then a lump of flesh for a similar period. Then an angel is sent to him who is permitted four words, and he writes down his provision, his lifespan, his deeds, and whether he will be wretched or blessed. Then the soul is breathed into him.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 is 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 is written overtakes him, so he performs the deeds of the people of Paradise and enters it."

Azami 540

Sahih

عن عبد الله بن مسعود يقول

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

الأعظمي 540صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Faith
Chapter
Belief in the angels
Section
Allah has assigned an angel to the womb who records the deeds of the human
Numbering
Jami al-Kamil 540 (2nd edition)
Azami 540