The late Clive Cussler did this a lot. At first he just described the character, or gave his “CC” initials, but eventually he outright named himself. His character always came out of nowhere – a sort of * Cussler ex machinus* – and gave whoever that novel’s hero was some crucial piece of help or information he needed. Or at least a chance to rest and eat. Then he disappeared from the story as effortlessly as he entered, avoiding whatever Bad Guys were chasing the hero. One time Cussler even brought his wife in. These were pretty clearly sheer indulgence. You could cut the pisodes out altogether, finding some other way for the hero to find that particular McGuffin if need be, and the story wouldn’t be changed.
Philip Jose Farmer did almost the same thing. In two of his series he introduced characters who shared his PJF initials. In his World of Tiers series it was Paul Janus Finnegan, and in his RiverWorld series it was Peter Jairus Frigate. In The Lavalite World, part of the World of Tiers series, he implies that Finnegan is the great grandson of Phileas Fogg, the hero of Jules Verne’s Around the World in Eighty Days. That’s interesting, because Fogg’s initials are “PF”, as in Philip Farmer. I wonder if Farmer thought of himself as Fogg when he wrote The Other Log of Phileas Fogg. Sort of an extreme example of Mary Sue.
I couldn’t think of any more examples, but the Wikipedia page on “Author Surrogate” gives the examples of
– Steve Gerber and Chris Claremont both introducing themselves in Man Thing, saving the universe.
– Grant Morrison put himself in Animal Man as the omnipotent author.
– Gabriel Garcia Marquez – a Nobel laureate, no less! – put himself in at the end of One Hundred Years of Solitude
In fact, come to think of it, Stan Lee and Jack Kirby used to put themselves in some early issues of Fantastic Four[. I think the last time they did it was in FF Annual #3 when they got turned away from the wedding of Reed Richards and Susan Storm. Sort of a precursor to all of Stan Lee’s MCU cameos.
I’m sure Dopers can come up with other cases. I’m not looking for shout-outs to other characters or real people in worlds, or mere cameos. I’m looking for cases where the author or director placed themselves, as themselves, in their work for a short "speaking role.*
*It’s not really the same thing, but Danny deVito created a character that he could play as a confidante of Jimmy Hoffa in the movie Hoffa, that he directed. Spike Lee did the same with himself in the movie X. But in neither case was the character supposed to be the actual director