He said, "The Messenger of Allah ﷺ, the truthful and trustworthy, told us, 'Each one of you has his creation gathered in his mother's womb for forty days. Then he becomes a clinging clot for a similar period. Then he becomes a lump of flesh for a similar period. Then Allah sends an angel who is commanded with four matters. He is told, Write down his deeds, his provision, his lifespan, and whether he will be wretched or happy. Then the soul is breathed into him...'" The hadith continues.
قال حدثنا رسول الله ﷺ، وهو الصادق المصدوق، قال: إن أحدكم يجمع خلقه في بطن أمه أربعين يوما، ثم يكون علقة مثل ذلك، ثم يكون مضغة مثل ذلك، ثم يبعث الله ملكا، فيؤمر بأربع كلمات، ويقال له: اكتب عمله ورزقه وأجله وشقي أو سعيد، ثم ينفخ فيه الروح… الحديث.
Bukhari related it in the Chapter on Divine Decree (6594), and Muslim in the Chapter on Divine Decree (2643), both through Amash, from Zayd bin Wahb, from Abdullah bin Masud, who said, and then mentioned it, and the wording given here is that of Bukhari.