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 clot. My Lord, a lump of flesh.' Then, when Allah wills to complete its creation, the angel asks, 'My Lord, male or female? Wretched or blessed? What is its provision? What is its lifespan?' All of this is written while the child is still in its mother's womb."

Bukhari 6595

Sahih

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

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

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

البخاري 6595صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Decree
Chapter
Decree
Numbering
Darussalam 6595
Bukhari 6595