Chandi Di Vaar is a philosphical, spiritual and heroic composition written by Guru Gobind Singh at Anandpur Sahib. It is fifth Bani of Dasam Granth. It is also called Vaar Sri Bhagauti Ji Ki (In some birs, the title is Vaar Durga ki). The first stanza of Chandi di Var forms the introductory part of the Ardas, the Sikh prayer. Guru Sahib used the Ballad to explain the priciples of Gurmat .
The Ballad relates a contest between a Gurmukh (a Gurmat individual who walks on god's path, following the command of God) and a Manmukh (one who does not believe in god and chooses to follow himself or other Manmukh humans). This ballad points out that whenever there is a Battle of Spiritual Discussion, between Gurmukhs and Manmukhs that the Gurmukhs always win. Like Nanak, who went to "Gorakhmata" and had Sidh Gosti (learning through dialogue) with the Sidhas (yogis). The yogis learned the error of their thinking and reliance on manmukh rituals from the Guru and gained valuable knowledge ("Matt"). This place then came to be known as "Nanak Mata" and became a major centre of the Udasi sect. Nanak acted as Chandi and Sidhas acted as Deamons, who were not clear of truth like Dhumarlochan.
So Guru Gobind Singh picked characters of Brahmgyan, which were already well known and used the legends to give a new Punjabi explanation to the Battle of Gurmat and Manmat.
Note: Chandi/Durga is a terminology of Brahmgyan which was used in past by many poets but Guru Gobind Singh explored real defination of Chandi i.e formless, eternal, accountless, garbless etc. Sikhs do not worship Durga, Chandi or Bhagwati as Idols or as Human, as interpreted by Hindus and Anti Dasam Elements, neither did Guru Sahib, reiterating Chandi does not refer to the Hindu deity and neither does Bhagauti refer to any Hindu Devi or Deity. From the beginning Guru Sahibh was clear that he worshiped, only the one true Creator. Even he cleared that Durga/Chandi born through god.
O Lord! By creating Durga, Thou hast caused the destruction of demons.