In the Buffy the Vampire Slayer episode Doppelgangland there is an evil Vampire-Willow doppelgänger, who comes on to the real Willow.
Willow: (appalled) It's horrible! That's me as a vampire? I'm so evil and... skanky. (aside to Buffy, worried) And I think I'm kinda gay.
Buffy: (reassuringly) Willow, just remember, a vampire's personality has nothing to do with the person it was.
Angel: (without thinking) Well, actually... (gets a look from Buffy) That's a good point.
That made me wonder, when the decision was made, that Willow would be gay. While watching the series already knowing that that's what eventually will happen, I noticed dozens of those little "hints". But some of those probably came before the decision was made (when the above dialogue occurred she is still with Oz and has a little affair with Xander).
By which episode (or season) did the scriptwriters know of Willows orientation, and were able to actually foreshadow her coming out?