Paul Cartledge comments on when Thucydides wrote his History
The standard current view is that Thucydides did what he says he did – started writing up, not just taking notes, from the late 430s on, i.e. probably before war actually broke out in spring 431. But it was only after his exile in 424 that he could (i) see things more from the Spartan side than he’d been able to up to that point and so (ii) reconsider what he’d written so far, which might also have encouraged some rewriting, esp. of a set piece like the Mytilene Debate in Book 3.
However: a famous passage in Book 2 – the obituary notice of Pericles in ch. 65 – must have been at least reworked in or after 404, in the light of Athens’s eventual defeat, since it not only refers to the final defeat but actually explains the defeat in part in light of the death of Pericles (as long ago as 429!) and Athens’ failure to find a worthy successor to him as Leader.
However that is not the only passage that either was reworked or was written up substantially for the first time in or after 404, in the wake of or in the light of Athens’s defeat. The best scholarly discussion of all such passages, and of the ‘composition problem’ in general, is to be found in an Appendix by Andrewes at the end of the 5th volume of the Commentary by A.W. Gomme, A. Andrewes and K. Dover (Oxford 1981). This has not been superseded, I think, though there is a new Commentary, by S. Hornblower, in 3 vols (1991-2008). The older ‘analyst’ position, which tried to identify ‘layers’ of composition, has now been abandoned, but it remains a question when precisely any particular passage was written or written up, as opposed to when it was ‘thought’.
At any rate, when he died, he was only in the middle of the summer of 411, though we know he lived at least 7 years after that, and Book 8 has several marks of incompleteness, which suggests that as the war went on, so Thucydides fell more and more behind the actual events in his writing of them up.