A hadith placed at the opening of several classical collections, including the first entry of Sahih al Bukhari itself, states that actions are judged by intentions, and that each person will have only what he intended, a report Islamic ethics treats as foundational precisely because it makes ikhlas the hinge on which every other outward act of worship or virtue turns: the same charitable gift, the same prayer, the same act of patience discussed elsewhere in this account, is transformed in its spiritual value entirely by whether it is directed toward God alone or carries some fraction of intention aimed at human regard. Ghazali frames ikhlas as riya's direct and named opposite in his structure of the Ihya, treating the two as a single axis running from complete sincerity to complete ostentation with most actual human intention falling somewhere along it rather than at either pole, which is why his practical counsel treats self examination of intention, muhasaba, as a continuous discipline rather than a single achieved state a person reaches and retains automatically thereafter.
The short Quranic chapter Surat al Ikhlas, on the oneness of God, shares its name with the virtue through the same root sense of purity from admixture, God's essence undivided by partners in the chapter's theological sense and a worshipper's intention undivided by ulterior motive in the ethical sense, a linguistic kinship classical commentators note without treating the chapter itself as primarily about the ethical virtue.