Elon Musk says he'll step down from President Donald Trump's advisory councils if he decides to withdraw from the Paris climate agreement.

The CEO of both Tesla (TSLA) and SpaceX tweeted Wednesday that he's done everything possible to lobby the president to keep the U.S. in the treaty.

"Don't know which way Paris will go, but I've done all I can to advise directly to POTUS, through others in WH & via councils, that we remain," Musk said.

Asked via Twitter what he'll do if Trump decides to leave, Musk responded that he would "have no choice but to depart [the] councils in that case."

Don't know which way Paris will go, but I've done all I can to advise directly to POTUS, through others in WH & via councils, that we remain — Elon Musk (@elonmusk) May 31, 2017

Will have no choice but to depart councils in that case — Elon Musk (@elonmusk) May 31, 2017

Musk is currently one of 18 business leaders who serve on Trump's business advisory council, formally known as the Strategic and Policy Forum. He is also part of the president's manufacturing jobs initiative, and has met with POTUS to discuss the need to boost infrastructure spending.

Trump is expected to announce later this week that he intends to pull out of the landmark Paris agreement. The U.S. signed the accord in 2015, committing to reducing carbon emissions by 26% to 28% within a decade.

Tesla is one of hundreds of companies that has asked Trump not to withdraw.

Musk has said he's raised climate issues with the White House before, but that despite these efforts, he's come under fire for his willingness to engage with the Trump administration. In April, a Silicon Valley investor took out full-page ads in the Sunday editions of the Washington Post and New York Times that called on Musk to "dump Trump."

Related: Elon Musk says he's 'doing good' on Trump's advisory council

This isn't the first time Musk has publicly opposed the Trump administration. Musk came out strongly against the president's executive order on immigration, which temporarily banned travel from seven Muslim-majority countries. Musk said in February that he would remain on Trump's advisory councils even though he publicly opposed the ban.

"Advisory councils simply provide advice and attending does not mean that I agree with actions by the Administration," Musk said on Twitter at the time.

Uber CEO Travis Kalanick, meanwhile, decided to step down to protest the ban.

Silicon Valley has had a complicated relationship with the Trump White House in its early months. Tech giants like Tesla, Google (GOOG) and Apple (AAPL) have had to balance their desire to try to influence policy with their longstanding support for immigration and green energy.