Hayes Valley thought it had banned chain stores. Since 2004, the newly redeveloped shopping district, once shadowed by freeways and now dotted with boutiques, has barred the arrival of chains with more than 11 outlets.

That 11-store limit provides room for corporate giants such as Gap Inc. and well-funded startups including Warby Parker, Allbirds and Madison Reed to wiggle through. Now, even Trader Joe’s is slated to come to the neighborhood, having received a special exemption from the ban.

Why are they working hard to get into Hayes Valley, and how are they getting into a neighborhood that ostensibly bans what is officially known as “formula retail”?

Trader Joe’s took advantage of local politicians’ hunger for a grocery store, gaining Supervisor Vallie Brown’s support for a one-off exemption, which the full Board of Supervisors approved Tuesday.

“I’m definitely a supporter of what the neighborhood wants,” Brown said, adding that the chain store ban has made Hayes Valley distinctive. “But they’ve also wanted an affordable grocery store.”

Gap Inc. is another recent corporate infiltrator. It got around the chain-store policy by setting up a subsidiary, Hill City, that operates separately from its well-known Gap brand. The 500-square-foot store, which carries menswear, is the first location for Hill City — which means it’s well under the limit of 11 stores. Even though Hill City is owned by a chain, it’s not considered one under city rules.

When considering what is a chain, San Francisco takes into account whether standard looks apply to merchandise, facades, color schemes, signage, worker dress and decor. Stores with multiple locations and a recognizable “look” — like a Walgreens, Safeway or Macy’s — will constitute a chain.

“The rules apply to tangible things like color scheme, the physicality of a store, the sameness of it,” said Daniel Sider, director of executive programs at the city’s Planning Department. “The ownership or stock structure of a business, that’s not something the code contemplates.”

Other chains have found different loopholes.

Gant Rugger, a Swedish clothing store with many locations, opened in Hayes Valley in 2013. It was able to slip through because the zoning code did not address international chains. The store closed this year.

“After Gant came in, we closed that loophole by making amendments to the code,” Brown said. “Now there’s (Hill City). Everyone figures out a way around it.”

An amendment to the code in 2014 addressed international chains. Yet another clothing chain, Canada’s Kit and Ace, opened in the neighborhood in 2015. It was strongly opposed by the Hayes Valley Neighborhood Association, but the retailer went to the Planning Commission for approval and gained the go-ahead to open a store. It abruptly closed two years later.

San Francisco enacted its ban on chain stores in 2004 through a series of laws and a ballot measure. Hayes Valley, Chinatown and North Beach have a broad ban on chain stores, while some other neighborhoods observe a partial ban (Upper Fillmore, Taraval Street and the Mission District, for example, do not allow chain restaurants). The Board of Supervisors approves local zoning rules.

Proponents say banning chains preserves a shopping district’s character by favoring small, local businesses. They say rents stay lower, too, if chain stores, which may have deeper pockets, stay out. Opponents point to the host of empty storefronts in San Francisco and say chains could help fill them.

Asking rents in Hayes Valley, on the main retail corridor, range from $75 to $150 a square foot. That’s typical for a neighborhood shopping district and much lower than Union Square, home of many high-end chain retailers, where rents are $150 to $650 a square foot, according to Cushman & Wakefield, a commercial real estate firm.

For Hayes Valley, the chain-store ban has been a help, said Gail Baugh, president emeritus of the Hayes Valley Neighborhood Association.

“It’s the reason Hayes Valley is what it is today — a great shopping district with unique stores,” she said.

But Ramiz Yousef, whose family owns Nabila’s Naturals, a local grocery store that’s been in Hayes Valley for 24 years, is disheartened to learn about Trader Joe’s impending arrival.

“I can’t compete with Trader Joe’s,” Yousef said. “I’m shocked that city officials are catering to big corporations like them. This defeats the whole purpose of the ban.” He said he’s proud of how Hayes Valley has evolved with one-of-a-kind stores; back when he opened, he said, it was a “dangerous place.”

The neighborhood used to be blighted and seedy. Part of its retail corridor stood under the shade of the Central Freeway, built in the late 1960s, where drug deals, prostitution and crime were rampant, according to former longtime resident Madeline Behrens-Brigham, who lived in Hayes Valley for 30 years and ran a collectibles store, Modernology, in the early 1990s.

“We seemed to attract independent folks who couldn’t afford rents in other neighborhoods,” said Behrens-Brigham, who retired to Santa Rosa.

Things changed after the freeway was torn down after severe damage from the Loma Prieta earthquake in 1989.

As the street became more pedestrian-friendly, the neighborhood quickly became a shopping destination with distinctive stores and trendy restaurants. Being near the performing arts venues of Civic Center helped. Longtime residents tend to be working-class immigrant families and elders who usually live in subsidized housing, while many newer residents are younger tech workers drawn to jobs at companies that have moved to Mid-Market, according to the neighborhood association.

Now, lots of high-end stores want space in Hayes Valley. Only 3% of its stores are empty, according to CoStar, a real estate data firm. In comparison, North Beach has a vacancy rate of almost 20%.

And so retailers are trying to elbow their way in, regardless of the ban.

Stores that sell mostly online but are branching into physical stores are using Hayes Valley as an early testing ground, before they get too big for the 11-store limit. New York eyeglass company Warby Parker, San Francisco shoe company Allbirds and salon operator Madison Reed opened outposts in Hayes Valley well before that point. Warby Parker now has more than 100 locations, Allbirds has more than 11, and Madison Reed plans to expand nationally with 600 salons. As long as they start out in Hayes Valley, though, they are grandfathered in.

The nonstop arrival of chain stores, or soon-to-be chain stores, has left some in the community questioning whether the ban is serving its intended purpose — keeping large companies out and small businesses in.

“Who’s advocating for small businesses these days?” Yousef asked. “When you bring in a Trader Joe’s, what’s to stop other chains from coming in? And why are we picking which chains to let in and which ones to turn down?”

Lloyd Silverstein, who runs the neighborhood association’s merchant group, said that the ban increasingly seemed unenforceable, and it’s time to look at other options — such as keeping the ban on Hayes but lifting it for streets branching off the main drag. Silverstein owns Optical Underground, an eyeglass business that’s been in his family for almost a century.

“While I think it’s a noble cause, the ban we have now doesn’t work because there’s too many ways around it,” he said.

Shwanika Narayan is a San Francisco Chronicle staff writer. Email: shwanika.narayan@sfchronicle.com Twitter: @shwanika