Regarding this, Hazrat ‘Ali (radhiyallahu ‘anhu) would recite the following poetry:
وقيت بنفسي خير من وطئ الثرى ومن طاف بالبيت العتيق وبالحجر
رسول إلٰه خاف أن يمكروا به فنجاه ذو الطول الإلٰه من المكر
وبات رسول الله في الغار آمنا موقى وفي حفظ الإلٰه وفي ستر
وبتّ أراعيهم وما يتهمونني وقد وطنت نفسي على القتل والأسر
I offered my life to protect the life of the best person to ever set foot on the surface of the earth, and the best person who performed tawaaf of the Ka’bah and the Hajr-e-Aswad
(This is none other than) the Rasul of Allah (sallallahu ‘alaihi wasallam), who feared the plot of his enemies against him. So Allah, the One who is the source of all grace, saved him from their evil plot
The Rasul of Allah (sallallahu ‘alaihi wasallam) spent the night in the cave safe and secure, enjoying the divine protection of Allah Ta‘ala and concealment
I spent the night observing the disbelievers while they did not expect the person (in the home of Rasulullah (sallallahu ‘alaihi wasallam)) to be me (sleeping in his place), and I had prepared myself to either suffer death or capture.
(Sharhuz Zurqaani 2/96)