Walid bin Ubada bin Samit reported,

I heard the Messenger of Allah ﷺ say, "The first thing Allah created was the Pen. He said to it, 'Write,' and so it recorded everything that will exist for all eternity."The hadith contains a story. He said this is a hasan sahih gharib hadith, and there is a narration on this topic from Ibn Abbas.

Tirmidhi 3319

Sahih

حدثنا يحيى بن موسى حدثنا أبو داود الطيالسي حدثنا عبد الواحد بن سليم قال قدمت مكة فلقيت عطاء بن أبي رباح فقلت له يا أبا محمد إن أناسا عندنا يقولون في القدر فقال عطاء لقيت

الوليد بن عبادة بن الصامت فقال حدثني أبي قال

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

الترمذي 3319صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Tafsir of the Quran
Chapter
Nun
Numbering
Darussalam 3319
Tirmidhi 3319