Huzaifa bin Usayd reported,

The Prophet ﷺ said, "The angel comes to the drop of fluid after it settles in the womb for forty or forty-five nights and asks, 'My Lord, wretched or blessed?' So both are written down. Then he asks, 'My Lord, male or female?' So both are written down. His deeds, his impact, his lifespan, and his provision are also written. Then the pages are folded up, and nothing is added to them nor taken away."

Azami 1003

Sahih

عن حذيفة بن أسيد

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

الأعظمي 1003صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Faith
Chapter
Belief in the divine decree and predestination
Section
How the human is created in his mother's womb and the recording of his provision, lifespan, deeds, misery, and happiness
Numbering
Jami al-Kamil 1003 (2nd edition)
Azami 1003