Elon Musk, X’s owner, has clashed with California’s leaders and has said the social media platform would move its headquarters to Texas.

X, the social media company owned by Elon Musk, plans to shut its San Francisco office “over the next few weeks,” according to an internal email obtained by The New York Times.

In the email, which X’s chief executive, Linda Yaccarino, sent to employees on Monday, the company said workers would move to existing offices in San Jose, Calif. X will also open an engineering-focused office in Palo Alto, Calif., which it will share with xAI, the artificial intelligence outfit owned by Mr. Musk, the email said.

“This is an important decision that impacts many of you, but it is the right one for our company in the long term,” Ms. Yaccarino wrote to employees.

Mr. Musk said last month that he would move the company’s headquarters to Texas, after California passed a law that bans school districts from requiring teachers to notify parents if their children change their gender identification. Mr. Musk, who has had a tempestuous relationship with the state, said that such legislation would “force families and companies to leave California to protect their children.”

X, previously known as Twitter, was founded in San Francisco in 2006. It moved its headquarters to the city’s Mid-Market neighborhood in 2012 after striking a deal with local legislators for a payroll tax break. Twitter became a symbol of the city’s tech industry, as companies like Uber also moved into the neighborhood.

Since Mr. Musk bought Twitter in 2022, the company has skipped rent payments to Shorenstein, the real estate company that owns X’s office building at 1355 Market Street. X also tried to cut costs by turning some of the space into bedrooms for traveling employees.

Mr. Musk, an X representative and Shorenstein did not respond to requests for comment.