The Messenger of Allah ﷺ used to teach us the prayer of seeking guidance (istikharah) just as he would teach us a surah of the Quran. He would say to us, "When any of you intends to undertake a matter, let him pray two rakahs other than the obligatory prayer, then say,'O Allah, I seek Your guidance through Your knowledge, and I seek Your power through Your might, and I ask You from Your immense bounty. For You are able and I am not, You know and I do not, and You are the Knower of the unseen. O Allah, if You know that this matter,' naming the specific matter he intends, 'is good for me in my religion, my livelihood, my afterlife, and the outcome of my affair, then decree it for me, make it easy for me, and bless me in it. O Allah, if You know it to be bad for me,' the same as the first, 'then turn me away from it and turn it away from me, and decree for me what is good wherever it may be, then make me content with it.'"Or he said, "in the immediate and distant outcomes of my affair."Ibn Muslim and Ibn Isa narrated it from Muhammad bin Munkadir from Jabir.
حدثنا عبد الله بن مسلمة القعنبي وعبد الرحمن بن مقاتل خال القعنبي ومحمد بن عيسى المعنى واحد قالوا حدثنا عبد الرحمن بن أبي الموال حدثني محمد بن المنكدر أنه سمع
كان رسول الله ﷺ يعلمنا الاستخارة كما يعلمنا السورة من القرآن يقول لنا إذا هم أحدكم بالأمر فليركع ركعتين من غير الفريضة وليقل اللهم إني أستخيرك بعلمك وأستقدرك بقدرتك وأسألك من فضلك العظيم فإنك تقدر ولا أقدر وتعلم ولا أعلم وأنت علام الغيوب اللهم إن كنت تعلم أن هذا الأمر يسميه بعينه الذي يريد خير لي في ديني ومعاشي ومعادي وعاقبة أمري فاقدره لي ويسره لي وبارك لي فيه اللهم وإن كنت تعلمه شرا لي مثل الأول فاصرفني عنه واصرفه عني واقدر لي الخير حيث كان ثم رضني به أو قال في عاجل أمري وآجله قال ابن مسلمة وابن عيسى عن محمد بن المنكدر عن جابر
Bukhari narrated it in Tahajjud, chapter on what has been reported about voluntary prayers being offered two units at a time, no. 1162, from the hadith of Abdul-Rahman bin Abu Mawal through this route.