I am mostly referring to composers writing complex music, for example, classic composers. In particular, I am referring to change of harmony, and change of key. Let's take for example a fugue for Bach, where the harmony is changing almost for every beat and there are very frequent modulations. How much are this modulations and change of chords "conscious" and how much they just follow the strongest melody line and naturally come out of them, thanks to the compose ear? When Bach or Mozart go to (let's say) I to [IV of IV] and [V of IV], when he is using a Napolean chord and so on... do they actually know they are doing that while composing? Do they actually want to do that? Or are they just chasing a sound that, from our analysis, resulted in being that?
It is obvious that at least some of them are at least partially aware of this. Mozart's letters to his father show his awareness on what modulation to use for obtaining a specific effect. However, I wonder: is this always the case? Is it possible that Mozart was just "reading" what he naturally felt right? Meaning: maybe he was not aware that he had to do that modulation for obtaining that effect, but he tried it and it worked and then analysed it for referring to his father.
And, this is only Mozart. We barely have any letter from Beethoven that talks about the structural harmony of his music (maybe no letter at all about this?).
I am referring not only to great classical composers but also to modern composers. They don't need to be classical, but of course I am interested in cases with complex harmony and modulations, so pop songs, for example, won't do.
I appreciate both personal experiences as composers or more detailed account from the literature of the past/present.
EDIT: I am still mostly unsatisfied with the answers, and I think that my question needs clarification. When composing music, does a composer go like: "Uhm, here I should put the V chord in second inversion as is the thing that follows best the II chord" (I am making this up) or like "ah! This sounds very good in this position" [and only after that maybe analysing from a harmonic point of view]. Which one would they mostly use?
EDIT2: This question is put on hold because "answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise". I think is unjustified. I am asking about the mental process of composers while they compose (referring to the most famous composers in order to assume their proficiency). Literature on this topic does not exist, apparently, but it could, either through the huge amount of letters that composer wrote during their lifetime, or through personal experience of living composers. I think is important to know whether this literature exists or not. If every composer uses a different composition style, then it would be good to know. From the answers, it seems that there is no consent about that. Some people believe that of course they are totally aware of the harmony, someone else says that they may be, maybe no. Some of this answers are unjustified and based on personal opinion. However, is totally possible to obtain an answer that is indeed based on facts: e.g. a big literature review on the letters of the great composers (or the first-hand experience of the less famous one), showing that things go mostly on one side or the other. Someone was writing a big answer on this. Why prevent potential factual answers?
In order to avoid opinion based answer I would thus specify: If you answer, please specify if what you say is based on your personal experience as a composer or on some other documents.