During a period of wandering, David was forced into hiding to escape King Saul. The primary approach among commentators is that this composition was written in response to the actions of spies and informers, such as Doeg and the people of Ziph. These individuals slandered David and deliberately exposed his secret locations.
The informers went directly to Saul, reporting that David was hiding in their territory. This betrayal triggered an intense and close pursuit. Acting on the information, Saul and his army completely surrounded the mountain where David and his followers had taken refuge with the goal of capturing them. Faced with this immediate threat, David and his men had to escape from the forces in a desperate, hurried flight.