Anas bin Malik reported,

The Prophet ﷺ said, "Allah has assigned an angel to the womb. The angel says, 'My Lord, a drop of fluid. My Lord, a clinging clot. My Lord, a lump of flesh.' Then when Allah wishes to complete its creation, the angel asks, 'My Lord, male or female? My Lord, wretched or blessed? What is its provision? What is its lifespan?' All of this is then written while the child is still in its mother's womb."

Bukhari 3333

Sahih

حدثنا أبو النعمان حدثنا حماد بن زيد عن عبيد الله بن أبي بكر بن أنس

عن أنس بن مالك رضي الله عنه

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

البخاري 3333صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Hadiths of the prophets
Chapter
Creation of Adam, peace be upon him, and his descendants
Numbering
Darussalam 3333
Bukhari 3333