Sleeping in your kippah

Q: Is there an obligation to wear a kippah while sleeping?
A: No, there is no obligation. The Shelah – the book "Sheni Luchot Ha-Brit" by Rabbi Yeshayahu Horowitz – mentions this as a proper custom, but not as an obligation. The Shulchan Aruch (Orach Chaim 2:6) wrote that we should not walk four amot (6 feet) without a kippah, so we do not even sit without a kippah. Sleeping with a kippah, however, is an act of piety mentioned by the Shelah.