"Exactly who is a foe depends on the invisible character's perceptions."
...
This also depends on what is meant by "foe". Does this mean currently having hostile intent, or the potential for it?
As a DM, this is the interpretation that I would go with. However, I think that it is not in accordance with RAW, which is why I posed the question in the first place - I am a player in this campaign and I want to use the Invisibility/Detect Thoughts combo myself, so I wanted to make sure it is a valid tactic. I will also discuss it with the DM, of course.I would personally rule that a foe in this case is defined by the caster's action rather than caster's perception or the target's intentions, because traditionally the limitation of Invisibility has been that it should end whenever you do something aggressive. Detect Thoughts is not directly aggressive, hence I wouldn't end the invisibility effect. Should the caster have an ability to inflict some damage via Detect Thoughts, then in that case I would consider that an aggression and end Invisibility.
...that enemies exist beyond the door.
And at casting time, he didn't know. Therefore, it was not an attack when initiated, and Invisibility is not removed.Right there. The caster, upon determining thinking things are on the other side of the door, labelled those things "enemies". So did he cast the spell into an area where it effected enemies? Yes.
And at casting time, he didn't know. Therefore, it was not an attack when initiated, and Invisibility is not removed.
My point is that the result doesn't matter. Only the caster's perceptions at casting time matter. Casting time is when the action is taken; therefore, only at casting time can the action be labelled an "attack."What about a paladin using Detect Evil, then? If he gets a result, that is almost certainly an enemy, as a paladins detect evil is almost the same as detect enemy?
My question is a bit silly, but also kind of fun theoretically. Its about semantics, really.
It doesn't matter when it was initiated. Invisibility states "For purposes of this spell, an attack includes any spell targeting a foe or whose area or effect includes a foe". Therefore, if you use a spell, any spell, that includes an enemy in the area or the effect of the spell, you just effectively made an attack and cancelled the Invisibility. Even if you didn't know it would happen beforehand, it did. It doesn't matter when it was cast, because the effects persists beyond casting time. This is a pretty black and white issue. Either an enemy was in the area of the spell, or there was not one. Either or.And at casting time, he didn't know. Therefore, it was not an attack when initiated, and Invisibility is not removed.

(Dungeons & Dragons)
Rulebook featuring "high magic" options, including a host of new spells.