Sayyiduna Ibn Abbas (may Allah be pleased with them both) said concerning the saying of Allah Almighty: "And when those who disbelieved plotted against you to imprison you" [Surah al-Anfal: 30]: Quraysh held counsel one night in Makkah. Some of them said: Bind him (meaning the Prophet (peace and blessings be upon him)) with ropes and imprison him. Some said: Kill him. And some said: Expel him (from the city). Allah Almighty informed His Prophet (peace and blessings be upon him) of this plot, so that night Sayyiduna Ali (may Allah be pleased with him) slept in the bed of the Prophet (peace and blessings be upon him), and the Messenger of Allah (peace and blessings be upon him) went out until he reached the cave. The polytheists spent the night watching Sayyiduna Ali (may Allah be pleased with him), thinking he was the Prophet (peace and blessings be upon him). When morning came they rushed at him, but when they saw Sayyiduna Ali (may Allah be pleased with him), Allah Almighty foiled their scheme. They asked: Where is your companion? Sayyiduna Ali (may Allah be pleased with him) said: I do not know. So they followed his (peace and blessings be upon him) tracks, and when they reached the mountain the trail became unclear to them. They climbed the mountain and passed by the cave, and saw a spider's web spun across its entrance. He (peace and blessings be upon him) stayed in that cave for three days.
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 12103