From the British Psychological Society's Research Digest:
Studying the ways people talk to themselves in their own minds is incredibly tricky because as soon as you ask them about it, you're likely interfering with the process you want to investigate. As William James said, some forms of introspective analysis are like "… trying to turn up the gas quickly enough to see how the darkness looks."
For many years Russell Hurlbert and his colleagues have used a technique that they believe offers the best way to study what they call "pristine" inner speaking, unaltered by outside interference. They provide participants with a beeper that goes off randomly several times a day, and ask them to record in precise terms their mental activity that was happening just before the beeps. Early in the process, this "descriptive experience sampling" (DES) approach also involves cooperative interviews between the participants and a trained researcher, so that the participant can learn to identify true instances of inner speaking from other mental phenomena.
The science of how we talk to ourselves in our heads