Those who do not return should "pretend to work elsewhere", he tweeted.
Mr Musk is not the only boss to tell his workers to come back to the workplace, and in many cases some have decided to leave their jobs rather than return to a five-day week in the office.
The online recruitment platform LinkedIn has found that a third of companies in the UK are planning to cut back on flexible working in the coming months.
But nearly two-thirds of workers say they are more productive in a hybrid or remote work environment.
Other research also suggests there is a divide opening up between those who lead companies and those who work for them on the issue.
Microsoft polled more than 20,000 workers across 11 countries. It found that 85% of leaders say the shift to hybrid work has made it challenging to have confidence that employees are being productive, but 73% of employees say they need a better reason to go back than just company expectations.
"It's just a better way to run a business," says Jeff Maggioncalda, the chief executive of the US-based online learning platform Coursera whose more than 1,000 employees all work "remote first", meaning they choose if they work in the office or at home.
"Before the pandemic I was an old-fashioned CEO," he says.
"I was a 'go to work every day' person and we used to allow some people to work from home on Wednesdays and honestly, I despised that policy. I thought, you know, if you're not coming in you're not getting the work done."
But during the pandemic he was amazed to see that it was possible to get the work done and keep flexibility but it required a new way of managing.
"It starts with recruitment," he says. One of the things he now does is welcome new hires to the company personally and tell them about the business so that, whether they're working from home or the office, "the purpose of the company is aligned with the purpose of their life".
The firm also now focuses more on results than on activities, he says.
"A manager staying on top of whether the results are being produced, rather than on whether someone's coming into the office - that's the key switch that managers need to make."
He adds that offering more flexible working has allowed Coursera to get more women into leadership positions and into roles in technology.
Technology isn't the only sector where women are more likely to choose a company that allows them to work remotely.
Grace Lordan from the London School of Economics spoke to 100 workers in the financial sector and found that overwhelmingly women were far more likely to want to work remotely for a significant section of their week.
"Women obviously still do more of the share of the house responsibilities and caring responsibilities," she says. "They have always valued autonomous working much more than men."
She says that people with disabilities are also more likely to value remote working, as well as those from ethnic minorities.
In general, she says, both employers and employees have to listen and compromise.
"We're in the UK, productivity is at an all-time low. You have people... saying to you, 'we are more productive with a remote first type set-up.' Why not trust them and see what happens as part of a great experiment?"
For generations people went to the office without even questioning whether it was necessary. The pandemic delivered a need to change quickly to a different way of working.
In industries where the competition to attract workers is greater than ever, employers are finding that offering remote work is a cost-effective way of improving their offer.
But if, as many predict, we enter a protracted recession and competition for talent weakens, companies may find it easier to demand a return to the office.