13th February 1755, Dutch East India Company, Paku Buwono III alliance and Prince Mangkubumi reached agreement to cease the war between themselves by Treaty of Gianti. Half of Mataram Empire in the Central Java was given to Mangkubumi, half kept by Paku Buwono. Later Mangkubumi changed his hame to Sultan Hamengkubuwono I.
When Amangkurat IV, the grandfather of Sultan was the ruler of Mataram, he often meditated in a nearby forest, called Garjitawati. Legend told that one day, when a gardener was gathering grass for his cattle in the forest, he looked for some water because it was so hot. He found a small pond and when he was going to drink some water from it, a dragon came out of the underwater, but it was so friendly to him.
The dragon said that if Sultan wanted to build his palace, it was supposed to be located in that forest. Then it disappeared.
Then Sultan started to build the palace in the forest. He demanded strong and old woods and the forest where those woods lied was said to be home of genies and spirits. His lumberjacks couldn't find anything to eat and the only things they could have were some rice and water for three days, or sometimes they couldn't have anything.
Then Sultan ordered that the main pole in the palace's hall had to be built from special wood, which would give strong impression. One night, a servant who was sleeping in the forest heard loud and deep voice. The voice introduced itself as Kyai Jegod. The servant saw that Kyai Jegod was an old, tall, and massive tree. He said that he would voluntarily let himself
be cut to make the main pole, so that he could stay inside it forever.
The servant told it to Sultan and Sultan let Kyai Jegod stay inside it forever, while Kyai Jegod
became the protector of the palace since then.