Chinese Mythology

The Chinese City God: The Magistrate of the Dead, and the Men Who Got the Job

城隍
Chénghuáng
deity · Folk religion & Daoism, made a state cult by the Ming

The Chinese city god, Chenghuang 城隍 (Chénghuáng, roughly "chung-hwahng"), is not one god but a post: the spiritual magistrate of a single walled city, who guards its living and is the first judge of its dead. Every city had its own, and the post was usually held by a named man, an upright official or a local hero appointed after his death. His temple is a courthouse with clerks, bailiffs and an abacus for settling the account of a life.

An oversized antique Chinese abacus leaning upright on a worn red lacquer cabinet, beside a blank wooden tablet, a bamboo holder of wooden lots and a bronze censer with incense smoke.
The city god's court keeps accounts. Temples hang an outsized abacus where every visitor can see it, and the story told about it is always the same: at night it moves by itself, adding up a life.

A post, not a person

The Chinese city god is one of the few gods you could, in principle, apply for. Chenghuang, his title, means "wall and moat," the two earthworks that made a Chinese city a city, and the phrase is old enough to turn up in the Book of Changes, where a line about bad fortune reads "the wall falls back into the moat." The god is named after the fortifications. He is what you get when a city's defenses acquire a mind.

He is also not one god. Every walled city had its own, the way every walled city had its own magistrate, and the two were meant to mirror each other: the magistrate governed the living by day, the city god governed the dead and watched the living by night. The Ming founder made the parallel official in 1369, handing city gods noble titles graded to the rank of the place they guarded, and the earth god's page tells that story from the point of view of the god who was left out of it. Taiwan's temples still keep the ladder. Taiwan Panorama, reporting on city god temples in 1992, sets it out from the top: the Great Emperor of the Eastern Peak, then the city gods of the capital, the province, the prefecture and the county, then the god of the neighborhood, then the earth god of the street, and at the bottom the stove god of each household. It is a civil service chart, and the city god sits roughly where a mayor would.

And because it is a post, somebody has to hold it. That is the thing that makes the city god different from almost every other figure on this site. Ask who the city god of a particular place is and you will often be given a name, a date of death and a reason for the appointment: an honest official, a commander who died holding the walls, a man the emperor wronged. Ask a Ming bureaucrat and he will tell you, with some irritation, that people were making it up. Both answers are on record.

So you've come: inside a city god temple

Walk into the Taiwan Prefectural City God Temple in Tainan, a government temple traditionally dated to 1669, and the first thing above you is a plaque with three huge characters on it. They mean, roughly, "So, you've come." Taiwan's Bureau of Cultural Heritage, which lists the building as a national monument, reads it the way everyone does: a reminder of the god's authority, and of the day every visitor will arrive here for good. Turn around to leave and over the door hangs the second famous object, an abacus far too big for any shop, put there, the heritage record says, to reckon right and wrong.

The rest of the building is a courthouse, and it is meant to feel like one. Taiwan Panorama's reporter described the hall at dusk: instruments of punishment on the walls, a civil judge who reviews good and evil and a military judge who carries out the beatings, Ox-Head and Horse-Face holding prisoners, and the two Impermanences, the white one with rolling eyes and lolling tongue and the black one holding an arrest warrant, the constables who go out on the god's patrols to hunt down wrongdoers. The abacus, the story goes, moves by itself at night. A historian quoted in the piece, He Peifu of National Cheng Kung University, made the practical point: in an age when the county magistrate could not be everywhere, a temple designed to frighten the guilty did a good deal of his work for him.

It did some of it literally. Taiwan Panorama records the custom of magistrates under the Qing and the Japanese who, stuck on a case with no culprit, went to sleep in the city god's temple hoping for a dream, and of officials who dragged an unconfessing suspect before the god to swear. The heritage record adds that a newly arrived Qing official reported to the city god's temple before he took up his own office. In 1992 the magazine found election candidates arriving with a chicken and a cleaver to swear their promises before him, beheading the chicken to show what should happen to them if they lie.

The happiest crowd in the building, though, is students. The city god's court is staffed by twenty-four departments, each with its own desk and its own officer, and in exam season two of those desks disappear under photocopies of admission tickets. Tainan's two city god temples printed a standard red form for the purpose, the magazine reported, with boxes for the candidate's name, the exam, the date, the venue and the seat number, so the god knows exactly where to look. In 2023, the Liberty Times reported, the temple brought the 300-kilogram abacus out into the courtyard so that candidates could touch the beads for luck.

Here is the twist. Most of those tickets are on the wrong desk. The busiest department is the one whose name sounds like "passing the exams," and He Peifu pointed out in Taiwan Panorama that it was nothing of the kind: it is the department of merit evaluation, the office that graded the performance of serving officials, a sort of human-resources review for the bureaucracy. The department that actually handles education is a different desk. After he said so in the newspapers, the magazine reports, some students moved their forms. Most of them, unwilling to take any chances, put a copy on both.

Each city god also has his own birthday, because each city god was a different man. Taipei's Xiahai temple celebrates on the thirteenth day of the fifth lunar month with a festival so crowded that the saying goes "on the thirteenth of the fifth month, people come to watch people"; the same temple is home to the matchmaker god Yue Lao. Hsinchu's celebrates on the fifteenth of the seventh month, in the middle of Ghost Month, which for a judge of the dead is exactly the right week.

Shanghai's three city gods

The city god temple most visitors meet is Shanghai's, in the old walled town beside Yu Garden, and its bazaar is so famous that the surrounding shopping district is often called by the temple's name. Most of the people buying soup dumplings outside have no idea that the temple has three city gods, each a real man, appointed in three different dynasties.

The first, according to the Daoist reference database daoinfo.org, is Huo Guang, the Han dynasty regent who died in 68 BCE, whose shrine stood on the site before the city god moved in. The second is Qin Yubo, a scholar who had served the Yuan. When the Ming founder summoned him, the Qing writer Chen Qiyuan records, he refused with an answer that is close to an insult: to serve the Yuan for twenty years and then abandon it would be disloyal, and to accept office before his mother's mourning was over would be unfilial, "and what use is a man who is neither loyal nor filial?" In Chen Qiyuan's telling he never took office and died a private man, and the emperor who could not employ him alive made him the city god of Shanghai county.

The third is the one that should startle a Western reader. Chen Huacheng was the Qing commander of the Jiangnan coast, and in the fifth month of 1842, the Draft History of Qing records, he died when the Wusong forts at the mouth of the Huangpu fell to attack. The attackers were the British, in the last summer of the First Opium War, and they went on to occupy Shanghai and quarter troops in this same temple. Later, the city installed the man who died fighting them as one of its gods. The temple reopened for worship in 1994, and all three are back.

The magistrate and his shadow

The point of the city god is the parallel, and it was meant to be exact. In 1370 the Ming court ordered his temples rebuilt to the height and breadth of the main hall of a government office, so that the god's court and the magistrate's would look the same. Laid side by side, the two offices line up like this:

The county magistrateThe city god
JurisdictionOne walled city and its countyThe same city, and its dead
RankGraded in the civil serviceGraded to match: titled duke, marquis or earl by the city's level in 1369
BuildingA yamen, the government officeA temple built to the yamen's dimensions by order of 1370
StaffClerks, judges, runners and constablesTwenty-four departments, a civil and a military judge, Ox-Head and Horse-Face, the two Impermanences
What he judgesDisputes and crimes of the livingThe conduct of a life, first, before the soul goes on

The last row is where he meets King Yama. In folk belief, Taiwan Panorama explains, the dead are examined first at the city god's court and only then passed up to Yama and the ten kings, the way a county case went up to a higher court. The city god is the local magistrate of the underworld. Yama is the appeals bench.

Men who got the job

The cleanest case of a man becoming a city god is Zhou Xin, and it comes with a death sentence. Zhou was the provincial inspector of Zhejiang under the Yongle emperor, famous for catching corrupt officials, and in about 1413 he tried to prosecute an agent of Ji Gang, head of the emperor's secret police. Ji Gang accused him instead. The History of the Ming records the end. Brought before the emperor, Zhou protested that he had only done what the law required, and the emperor had him executed. At the place of execution Zhou shouted the line that made him: "Alive I was an upright official; dead I shall be an upright ghost!"

The emperor came to regret it and said so, and then, the history says, he seemed to see a man in a red robe standing in the sunlight who told him: "Your servant Zhou Xin is now a god, and deals with corrupt and greedy officials for Your Majesty." Notice that the History of the Ming says "a god" and stops there. The appointment comes from the local record: the Qiantang county gazetteer, quoted in the Qing Gazetteer of Zhejiang under the city god temple of Hangzhou, notes that in the Yongle reign "the late inspector of Zhejiang, Zhou Xin, was first appointed city god." The empire's most honest official, executed by mistake, was given the one job where he could keep doing the work.

The Ming court was not always so pleased with the practice. In 1369, when the Ministry of Rites wrote up its recommendations on the city god, it complained that since the Song some places had gone so far as to "force a fit," each pointing to one man and making him the god's name. The fuller text of that memorial, preserved in Sun Chengze's seventeenth-century Tianfu Guangji, lists who: a string of cities from Zhenjiang to Wuhu claimed Ji Xin, the Han general (or, oddly, Long Ju, who fought for the other side), and a string of cities in Jiangxi claimed Guan Ying, one of the Han founder's commanders. Ji Xin's claim is the best story. In 204 BCE, with Liu Bang trapped in the city of Xingyang, Ji Xin dressed as his king and rode out of the east gate to surrender, while the real king escaped by the west, and the enemy burned him alive for it. A man who died impersonating his lord made an obvious candidate for a god who impersonates a magistrate. He was claimed so widely that a late-Ming Daoist novel, Zhouzao Ji, has the local earth god explain to a visitor that there is not a city in the empire, nor in the lands of the barbarians, whose city god is not surnamed Ji. The visitor asks why this one looks grander than usual, and the earth god, who knows his ladder, explains that a province's city god outranks a prefecture's, and a prefecture's outranks a county's.

Sometimes you can almost watch a man being promoted. Su Jian was the commander at Yong, modern Nanning, when an army from Jiaozhi, in what is now northern Vietnam, besieged it in 1076. After forty-two days the walls fell, and he killed his family and burned himself in his residence rather than be taken. The History of Song says that when the same army later marched on Guizhou, its soldiers saw a great host coming from the north and cried that "Su of the Imperial City" was coming for revenge, Imperial City being his court title, and they turned back. Seven hundred years later, Zhao Yi retold the episode in his notebook and had the soldiers cry "City God Su has come!" The two titles are the same two syllables in reverse order, huangcheng and chenghuang, and an official title had quietly become a divine one. It may have been a slip of memory. It is also exactly how the job gets filled.

An exam in the next world

The most famous city god appointment in Chinese literature is the first story in Pu Songling's Strange Tales from a Chinese Studio, written in the late seventeenth century, and Pu says it happened in his own family, to his elder sister's husband's grandfather, a scholar named Song Tao.

Song is ill in bed when a clerk arrives with a summons and a horse with a white blaze and tells him he is wanted for an examination. He points out, reasonably, that the examiner has not arrived in town. The clerk just hurries him along. He rides to a city like a royal capital, where a dozen officials sit in a great hall, and the only one he recognizes is Guan Yu. The question floats down on a slip of paper, eight words: "One man, two men; with intent, without intent." Song's essay contains the sentence that wins: good done with intent, though good, is not rewarded; evil done without intent, though evil, is not punished. The gods pass it around in delight, and he is told: Henan lacks a city god, and he is fit for the post.

Then comes the most Chinese moment in the story. Song weeps, accepts the honor, and asks for a deferment, because his mother is seventy and has no one else to look after her. The board checks her lifespan in a register. She has nine years left. Guan Yu suggests that another candidate act in the post until then, and Song is sent home on leave. He wakes in his coffin three days after he died. Nine years later his mother dies, and when the funeral is over he washes, goes into his room, and dies too; that day his in-laws, across town, see him arrive with a grand escort, climb into their hall, bow once and leave, and only learn afterward that he is dead. The story treats becoming a city god exactly the way the Chinese world treated becoming a magistrate: an exam, an appointment, a posting, and a leave of absence for filial duty, all handled by a board.

The first city god was under siege

Nobody knows who the first city god was, and the Ming ministry admitted as much: "the origin of the city god's sacrifice cannot be traced." What can be traced is the first one in a dynastic history, and he arrives in a crisis. In the 550s the Northern Qi general Murong Yan held the river city of Yingcheng against a southern fleet, which had sealed the river with a boom of reeds several miles long. The Book of Northern Qi records that the city already had a shrine "commonly called the city god," where everyone prayed when they had need, and the garrison prayed there. A gale rose and broke the boom. The enemy rebuilt it with iron chains. They prayed again, and the wind broke it again, three times over. The city decided it was the god's work, which is the kind of conclusion a besieged city is entitled to.

Two centuries later the relationship had become a negotiation. In 759 the Tang calligrapher Li Yangbing was magistrate of Jinyun, in the south, during a drought, and he wrote down what happened in a short record that still survives. The city god, he notes, was not in the state's register of official sacrifices at all; he was a southern custom. Li went to the temple in person and made the god an offer: "If it does not rain in five days, I will burn your temple." It rained. The county moved the temple to the top of the hill as a reward. One magistrate addressed another as a colleague, set a deadline, named the penalty, and paid up when the work was done.

The year the statues went into the river

The Ming founder, Zhu Yuanzhang, liked the city god more than any emperor before him and trusted him less. In 1369 he made the gods noblemen. In 1370 he took the titles back and issued a set of instructions that read like an order to a renovation crew. Every temple was to clear out its other gods. Each was to be rebuilt to the height and breadth of the main hall of a government office. The god was to be represented by a wooden tablet with his title on it, like a magistrate's nameboard, and the clay statues were to be smashed and carried off into the water, the History of the Ming says, and the mud taken to plaster the walls, which were then painted with clouds and mountains. The god was to be an office, not a face.

It did not hold. The statues came back, and so did the names. In Tainan even the departments have statues again, the merit officer as a gentle scholar with a book in his hand. In Shanghai there are three of him, with names. The state wanted a post with nobody in it, and the people who prayed there wanted to know who was listening. What they got is the god you meet at Tainan's door, under that plaque. He is somebody. And he has been expecting you.

In the classics

The passages behind the story, in the standard published translations. Open any one for the original text.

“Top six: the wall falls back into the moat. Do not use troops. Proclaim your orders from your own city. Persisting brings regret. ”
Original text

上六:城復于隍,勿用師,自邑告命,貞吝。

Book of Changes (周易), hexagram Tai, top line, where the name comes from · trans. Jade Almanac, from the original (Zhou dynasty, first millennium BCE)
“In the city there was already a shrine, commonly called the shrine of the city god, where officials and commoners alike prayed whenever they had need. So, following the soldiers' wishes, they went together to pray for help from the unseen world. In a moment a gale sprang up, great waves surged, and the reed boom was swept apart. Ren Yue joined it again with iron chains and guarded it even more closely. Murong Yan prayed again with them; wind and waves rose in the night and broke it once more, and this happened three times. The people of the city rejoiced, and called it the work of the god. ”
Original text

城中先有神祠一所,俗號城隍神,公私每有祈禱。於是順士卒之心,乃相率祈請,冀獲冥佑。須臾,衝風欻起,驚濤湧激,漂斷荻洪。約復以鐵鎖連治,防禦彌切。儼還共祈請,風浪夜驚,復以斷絕,如此者再三。城人大喜,以為神功。

Book of Northern Qi (北齊書), chapter 20, biography of Murong Yan, the first city god in a dynastic history, at the siege of Yingcheng · trans. Jade Almanac, from the original (compiled 636, for events of the 550s)
“The city god is not in the register of official sacrifices, but the people of Wu and Yue have him, and by their custom they pray to him in flood, drought and epidemic. In the second year of Qianyuan of the Tang, in the seventh month, no rain fell. On the sixteenth of the eighth month Li Yangbing, magistrate of Jinyun, went in person to pray to the god, and made this agreement with him: "If it does not rain in five days, I will burn your temple." When the day came there was a great rain, and the whole county reported that it had enough. ”
Original text

城隍神祀典無之,吳越有之,風俗水旱疾疫,必褥焉。有唐乾元二年秋七月不雨,八月既望,縉雲縣令李陽冰躬祈於神。與神約曰:「五日不雨,將焚其廟。」及期大雨,合境告足。

Li Yangbing, Record of the City God of Jinyun County (縉雲縣城隍神記), a magistrate gives the god five days · trans. Jade Almanac, from the original (759)
“Since the Song his shrines have spread across the empire, some granted temple plaques, some given noble titles, and some places have gone so far as to force a fit, each pointing to one man and making him the god's name. … In the third year an edict removed the titles, and they were called simply the city god of such a prefecture, department or county. Each temple was also ordered to clear out its other gods. A pattern for the temples was fixed: their height and breadth to match the main hall of a government office. Wooden tablets were made for the god, the clay statues were smashed and carried off into the water, and their mud was taken to plaster the walls, which were painted with clouds and mountains. ”
Original text

宋以來其祠遍天下,或錫廟額,或頒封爵,至或遷就傅會,各指一人以爲神之姓名。…三年,詔去封號,止稱其府州縣城隍之神。又令各廟屏去他神。定廟制,高廣視官署廳堂。造木爲主,毀塑像舁置水中,取其泥塗壁,繪以雲山。

History of the Ming (明史), Treatise on Rites 3, the officials' complaint about named gods, and the order of 1370 · trans. Jade Almanac, from the original (compiled 1739, for the Hongwu reforms of 1369 and 1370)
“At his execution he cried out: "Alive I was an upright official; dead I shall be an upright ghost!" And they killed him. Some days later the emperor regretted it and asked his attendants, "Where was Zhou Xin from?" "Nanhai," they answered. The emperor sighed: "Beyond the mountains there was a man like this, and I killed him wrongly!" Afterward, it is said, the emperor seemed to see a man in a red robe standing in the sun, who said: "Your servant Zhou Xin is now a god, and deals with corrupt and greedy officials for Your Majesty." ”
Original text

臨刑大呼曰:「生為直臣,死當作直鬼!」竟殺之。他日,帝悔,問侍臣曰:「周新何許人?」對曰:「南海。」帝嘆曰:「嶺外乃有此人,枉殺之矣!」後帝若見人緋衣立日中,曰「臣周新已為神,為陛下治奸貪吏」雲。

History of the Ming (明史), chapter 161, biography of Zhou Xin, the upright official who became a god · trans. Jade Almanac, from the original (compiled 1739, for events of c. 1413)
“After Su Jian's death, the Jiaozhi army planned to raid Guizhou. After a few days' march their men saw a great host coming from the north and cried out: "Su of the Imperial City is leading troops to take revenge!" They took fright and turned back. The people of Yong raised a shrine to Su Jian, and in the Yuanyou years it was granted the name "Cherishing Loyalty." ”
Original text

緘沒後,交人謀寇桂州,行數舍,其眾見大兵從北來,呼曰:「蘇皇城領兵來報怨。」懼而引歸。邕人為緘立祠,元祐中賜額「懷忠」。

History of Song (宋史), chapter 446, biography of Su Jian, the dead commander the enemy saw coming · trans. Jade Almanac, from the original (compiled 1345, for events of 1076)
“On each desk there were brush and paper. Presently the question came floating down, and they saw it was eight words: "One man, two men; with intent, without intent." When the two essays were done they were handed up to the hall, and his contained this: "Good done with intent, though good, is not rewarded; evil done without intent, though evil, is not punished." The gods passed it round and could not praise it enough. They called him up and told him: "Henan lacks a city god. You are fit for the post." ”
Original text

几上各有筆札,俄題紙飛下,視之,八字云:「一人二人,有心無心。」二公文成,呈殿上,公文中有云:「有心為善,雖善不賞;無心為惡,雖惡不罰。」諸神傳讚不已,召公上,諭曰:「河南缺一城隍,君稱其職。」

Pu Songling, Strange Tales from a Chinese Studio (聊齋志異), 'Examination for the Post of City God', the first story in the collection · trans. Jade Almanac, from the original (late 17th century)

As seen in

Strange Tales from a Chinese Studio (Liaozhai Zhiyi)

novel · late 17th century

The collection opens with him. In its first story a sick scholar is summoned to sit an exam in the next world and is appointed city god of a county in Henan, then granted nine years' leave to look after his mother., as the city god of Henan (Song Tao).

Pu Songling says the candidate was his own elder sister's husband's grandfather.

Sanbao Taijian Xiyang Ji (The Eunuch Sanbao's Voyage to the Western Ocean)

novel · 1597

A city god argues his seniority by claiming to have served the Han founder, who made him the city god of all under heaven: the folk belief that every city god is Ji Xin, played for comedy..

Late-Ming fantasy based on Zheng He's voyages; the same joke turns up in the Daoist novel Zhouzao Ji, where the local earth god explains it.

Questions people ask

What is the Chinese city god?

The city god, Chenghuang, is the god who holds office over one walled city: he protects it, answers its prayers for rain and justice, and in folk belief is the first judge of everyone who dies there. He is a post rather than a single god, so every city has its own, ranked like the human officials of the same place, and the post is usually held by a named man appointed after death, such as Zhou Xin, the Ming inspector who became Zhejiang's city god. The name means "wall and moat."

Was the city god a real person?

Usually, yes, though which person depends on the city. Zhou Xin, executed in about 1413, was made Zhejiang's city god according to the Qiantang county gazetteer; Qin Yubo, who refused to serve the Ming founder, became Shanghai's; the Han general Ji Xin was claimed by so many cities that a late-Ming novel jokes every city god is surnamed Ji. The Ming court itself disliked the practice and complained in 1369 that places were forcing a man's name onto the god, but the names stuck.

What is the City God Temple in Shanghai, and who is worshipped there?

It is the temple of Shanghai's own city god, beside Yu Garden in the old walled town, and unusually it has three. Huo Guang, a Han dynasty regent, was the original god of the site. Qin Yubo, a local scholar who refused to serve the Ming founder, was appointed Shanghai's city god after his death. Chen Huacheng, the Qing commander killed defending the Wusong forts against the British in 1842, was added later. The temple reopened for worship in 1994 and the bazaar around it took its name.

Is the city god the same as King Yama?

No. The city god is the local magistrate of the dead, and King Yama runs one of the ten courts above him. In folk belief a soul is examined first at the city god's court, then sent on to the courts of the underworld, exactly as a county magistrate's case could be passed up to a higher court. Taiwan Panorama's 1992 report on city god temples puts the chain of command this way, with the Great Emperor of the Eastern Peak at the top and the city gods of capital, province, prefecture and county below him.

What do people pray to the city god for?

Justice first, and then whatever a magistrate can help with. People bring him disputes and wrongs nobody else will judge, swear oaths in front of him, and in Taiwan students leave photocopies of their exam admission tickets on the desks of his departments in exam season. Historically magistrates also slept in his temple hoping to dream the answer to an unsolved case, and new officials reported to him before taking up their post, because he was the government of the same city on the other side.

Related figures

Sources & further reading

By Julian 祝君瑜, retold from the classics, with the original passages cited, updated 2026-10-14

Stay in the loop.

Chinese mythology, the zodiac, and the meaning behind names and symbols, rooted in the classics and read back to you. No spam. Unsubscribe anytime.