Why didn’t he just unveil their true intentions in the beginning so that what happened after his demise would be prevented?
There are a few points that need to be made in answer to your question:
1- After making his call to Islam open in the third year of his prophethood, the prophet (pbuh) had announced the caliphate and succession of Ali (as) to him on different and many occasions and had also introduced his enemies to the people. At the same time, the circumstances of the time weren’t in a way that would allow him to have a harsher encounter with them.
2- The most important objective that both the prophet (pbuh) and the imam pursued was the protection of Islam and the progeny of the prophet (pbuh), even if it meant for Imam Ali (as) not to become khalifah after the prophet (pbuh).3- If the prophet (pbuh) was to have a harsh encounter in the final days of his life with the enemies of the imam and those who had plans for after the prophet’s (pbuh) demise, there were great possibilities that they would retaliate similarly, doing irreparable damage to Islam.
After the prophet (pbuh), Ali (as) was the only one bearing all moral and knowledge related virtues, fighting like a destructive tornado against the infidels in battles, no one being able to stand against his courage, strength and sword. The advent of Islam and the lifetime of the prophet (pbuh) have seen many great accomplishments and merit by Ali (as) in which we will point to a few. The prophet (pbuh) would repeatedly speak of the imam’s (as) virtues and worthiness, saying: “Ali never makes a mistake or error” and “Ali is with the truth and the truth is with Ali.”
In many cases, he had warned of disobeying Ali (as), saying: “Anyone from my family or anyone else that holds the hate of Ali in his heart has left my religion.”
Nevertheless, despite all the commands and advice of the prophet (pbuh), a group of Muslims had plans for governing the Muslim nation after the prophet’s (pbuh) demise. The prophet (pbuh) was totally aware of these plots, but since they hadn’t done anything wrong during the prophet’s (pbuh) lifetime, he couldn’t punish them and retaliate for something they hadn’t done yet, thus, he tried to prevent what was to happen later by doing certain things such as: telling the people on his final Hajj in a place called Ghadir Khum, where people from all over the Muslim world were present that: “O Muslims! Know that Allah (swt) has appointed Ali as your master after me and no one can disobey Allah’s (swt) command. Whosoever rejects Ali’s caliphate, has disobeyed Allah (swt)…”
In the final days of his life, the prophet (pbuh) tried to send off those he knew were against the imamate of Ali (as) along with the army of Usamah outside of Medinah, so that the imam wouldn’t face any substantial problems in the first days of his imamate. Nevertheless, they figured out what was going on and refused to leave with the army. This resulted in the delay of its dispatch until the prophet (pbuh) passed away and those who were against the imam reached what they wanted.
When the prophet (pbuh) saw that a group had returned from Usamah’s army and had disobeyed him, and it looked like they had certain plans, he ordered: “Bring me a pen and paper so that I write something that won't allow you to go astray after me.” One of those present quickly said: “Deep pain has overtaken the prophet, Allah’s book, the Quran, suffices us. He (the prophet (pbuh)) is hallucinating out of pain.” According to some sources of our Sunni brothers, this person was none other than Umar ibn Al-Khattab!
Anyway, this group of Muslims strived and reached its goal; they were thirsty for power and ranks and wanted to fulfill this late wish of theirs. They would consult the imam on military and fiqhi matters off and on, and would accept his views to the extent that once, Abu Bakr went up the pulpit and told the people to take back their bey’ah from him (Abu Bakr) so that Ali would be their leader because as he said there: “I am not the best amongst you (but Ali is).”
Another group of people who were only Muslims in name and on the outside, and didn’t believe in the prophet (pbuh) nor Islam, were waiting for the right chance to exterminate Islam. These people had tried to murder the prophet (pbuh) several times, once when he was returning from Ghadir Khum and another time during the return from the battle of Tabuk.
Therefore, despite the circumstances and different groups of people amongst the Muslims, the prophet (pbuh) had directly spoken of Imam Ali's (as) succession to him time and time again and done all he could to make it happen after him.
The conclusion that must be made here is that if there ever was anything the prophet (pbuh) had to let the Muslim nation know pertaining to the caliphate and succession after him, he did. Also, if he didn’t do anything else more than he did, the reason is because Islam itself would be endangered. Therefore, he did what he did and didn’t go any further so that Islam and his progeny would remain unharmed so that the final imam would be able to emerge and achieve the goal of all prophets and establish a divine worldwide government.
 Ibn Kathir, Al-Bidayah wal-Nihayah, vol. 2, pg. 316.
 See: Jafar Subhani, Furughe Abadiyyat, vol. 2, pp. 461 and 475; Tarikh Dameshq, vol. 42, pp. 448-449; Mustadrak Hakem, vol. 4, pg.93, hadith 4604.
 Abdul-Fattah Abdul-Maqsud (translated by Seyyid Mahdi Jafari), Al-Imam Ali ibn Abi Taleb (as), vol. 3, pg. 94.
 See: Furughe Abadiyyat, pg. 471.
 Bukhari, vol.1, pg. 22 and vol. 2, pg. 414; Sahih Muslim, Wasiyyah section, chapter 5. For further information: Question 1527 (website: 1692) Not Allowing the Prophet (pbuh) to Write His Will.
 See: Al-Imam Ali ibn Abi-Taleb, vol. 1, pg. 282.
 See: Furughe Abadiyyat, vol. 2, pp. 390 and 404.