Anas bin Malik reported,

The Prophet ﷺ said, "Allah عز وجل has assigned an angel to the womb, who says, 'My Lord, a drop of fluid. My Lord, a clot. My Lord, a lump of flesh.' Then, when Allah wishes to complete its creation, the angel asks, 'Male or female? Wretched or blessed? What is the provision? What is the appointed term?' All of this is then written while the child is still in its mother's womb."

Azami 542

Sahih

عن أنس بن مالك

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

الأعظمي 542صحيح
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 542 (2nd edition)
Azami 542