Every year, before autumn gives way to winter in San Francisco, the crews tasked with the unrelentingly dirty business of inspecting and maintaining the city’s nearly 1,000 miles of sewer pipes set to work.

To help ensure the city’s aged sewer system can withstand the annual deluge of water brought on by seasonal rains, crews from the San Francisco Public Utilities Commission descend beneath the city’s streets, searching for evidence of damage and defects.

In San Francisco’s Tenderloin district one recent morning, a PUC crew hoisted a manhole cover on Ellis Street, opening up a passage into a portion of the city’s sewer system, first built in 1866.

The rounded brick walls of the muggy, 3-foot-high, pitch-black tunnel were thick with sopping-wet grime. They seemed to breathe in places where clusters of cockroaches huddled together. A small stream of sewer water sluiced down a channel running the length of the pipe, carrying all manner of soggy debris to a treatment plant, where it is cleaned and sent into the bay. By winter, the pipe will be impassible, awash in as much as 12 feet of sewer water.

Unlike any other coastal city in California, San Francisco uses a combined sewer system, collecting, transporting and treating both wastewater and rain runoff with the same set of pipes. Using combined systems was common practice for urban sewers built before the turn of the 20th century, said PUC General Manager Harlan Kelly Jr., when wastewater and rainfall both were typically dumped into nearby bodies of water.

For all its grubby duties, in recent years San Francisco’s sewer system has become the vanguard of the city’s efforts to mitigate the effects of climate change over the next 80 years. The PUC is in the midst of a huge, decades-long overhaul of the infrastructure that makes up the city’s sewer system, an upgrade city officials hope will prevent catastrophic flooding for generations to come.

Chief among the utility agency’s long-term goals for the $6.9 billion project are improving San Francisco’s ability to cope with sea-level rise and withstand the growing number of increasingly intense rainstorms meteorologists anticipate will buffet much of the country in coming years. The recent hurricanes that devastated Texas, Florida and Puerto Rico this year serve as stark reminders of the kind of climate events San Francisco needs to prepare itself for, Kelly said.

“Everything we’re looking at is with an eye to climate change,” he said. “You can’t fight Mother Nature. You have to adapt.”

The city treats an average of 60 million gallons of water on dry days and 575 million gallons a day when it rains, said Karen Kubick, the PUC’s program director for the sewer improvement initiative. But because the city’s sewers capture rainwater and wastewater together, they can more easily be overwhelmed in times of sustained, heavy rainfall.

There is already a persistent risk, Kubick said, that the city’s water-management system could be swamped by a combination of heavy storms and king tides, when sea levels rise 12 inches higher than normal.

“If sea levels rise as anticipated, and we were to have a king tide, and a major storm walloped us, our system could be overwhelmed,” Kubick said. “Our system wasn’t designed to handle these types of extreme events.”

The PUC’s improvement program will be rolled out in phases through 2032. The improvements themselves — everything from replacing outdated sewer pipes to raising critical electrical systems in treatment plants in anticipation of the higher sea waters — are designed to respond to how San Francisco’s climate could look in the year 2100. Given current conditions, by that time, climate models predict, ocean levels could have risen between 36 and 66 inches, Kubick said.

“With a long-term view on planning, things will work out a whole lot better because you’re not making decisions in a crisis,” said Richard Luthy, a professor of civil and environmental engineering at Stanford.

But as the sea rises and as storms may dump more and more water on the city, San Francisco is already contending with an urgent need to improve the ways it rids itself of storm water.

“If we do end up with larger or more intense storms, that’s going to make it harder for the PUC to manage all of that water coming into the system,” said David Sedlak, a UC Berkeley civil and environmental engineering professor and co-director of the Berkeley Water Center.

Through 2032, the PUC intends to spend $444 million on a variety of projects to manage storm water throughout the city, including installing rain gardens designed to capture rainfall and divert it into the ground, keeping it from flowing into the sewer system.

The PUC also expects to break ground next year on the two single-largest sewer improvement projects. Both are tied to the city’s Southeast Treatment Plant, the 65-year-old workhorse of San Francisco’s sewer system in the Bayview-Hunters Point area, treating about 80 percent of the city’s sewage.

In January, the PUC is planning to start construction on a new, $359 million “headworks” facility — where the sewage treatment process begins. According to the PUC, the current headworks facility can’t adequately filter the debris and sand out of the sewer water passing through it, and it’s having trouble controlling odors. Next summer, the PUC will also begin construction on a new, $1.27 billion facility for treating solid waste.

To help pay for the sewer-system upgrades, the PUC has sought low-interest loans from federal and state sources, but ratepayers will foot the bill for the bulk of the projects’ expense. Chris Colwick, a PUC spokesman, said that the sewer-improvement program will represent a large portion of the agency’s request to raise utility rates next year.

“We are currently assessing the needs and cost of this much-needed upgrade, which will be a key part of our proposed rates package that will become effective, after a thorough public review process, on July 1, 2018,” Colwick said in an email.

But the long-term benefits of upgrading and modernizing the city’s sewer infrastructure will vastly outweigh the costs, Sedlak said. “We already have programs to slowly replace pipes as they wear out so we don’t get leaks. But the kinds of capital improvement projects like what San Francisco is doing come along once in a generation.

“With climate change, it would be foolish to build what we built in the middle of the 20th century.”

Dominic Fracassa is a San Francisco Chronicle staff writer. Email: dfracassa@sfchronicle.com Twitter: @dominicfracassa