Kong Wei (孔緯) (died 1 October 895Academia Sinica Chinese-Western Calendar Converter.Zizhi Tongjian, vol. 260.), courtesy name Huawen (化文), formally the Duke of Lu (魯公), was an official of the late Tang dynasty, serving as a chancellor during the reigns of Emperor Xizong and Emperor Xizong's younger brother Emperor Zhaozong.

Background and early career Kong Wei's family was descended from the Spring and Autumn period philosopher Kong Qiu (Confucius).New Book of Tang, vol. 75. His great-granduncle Kong Chaofu () was a well-known official during the reign of Emperor Dezong, and his great-grandfather Kong Cenfu () and grandfather Kong Kui () also both served as imperial officials.Old Book of Tang, vol. 179.New Book of Tang, vol. 163. His father Kong Wenru ()Both Kong Wei's biographies in the Old Book of Tang and the New Book of Tang referred to his father as Kong Zunru (孔遵孺), but the table of the chancellors' family trees in the New Book of Tang referred to his father as Kong Wenru. As it is undisputed that his uncles all had the character of "Wen" in their names, it appears that the name of Kong Wenru is correct. Compare Old Book of Tang, vol. 179 and New Book of Tang, vol. 163 with New Book of Tang, vol. 75. served as a county secretary general, but died early. Kong Wei had at least two younger brothers, Kong Jiang () and Kong Jian ().

As Kong Wenru died early, Kong Wei was raised by his uncles Kong Wenyu () and Kong Wenye (). As both Kong Wenyu and Kong Wenye served as regional governors, Kong Wei followed them to their assignments, and due to the friendships that Kong Wenyu and Kong Wenye had, Kong Wei became well known among the imperial officials. He passed the imperial examinations in the Jinshi class in 859, during the reign of Emperor Xuānzong, and therefore served as a copyeditor (校書郎, Xiaoshu Lang) at the Palace Library. When the former chancellor Cui Shenyou served as the military governor (jiedushi) of Dongchuan Circuit (東川, headquartered in modern Mianyang, Sichuan), he invited Kong to serve on his staff.As Cui Shenyou served as the military governor of Dongchuan from 858 to early in the Xiantong era (860-874) of Emperor Xuānzong's son Emperor Yizong, Kong's service under him must be in 859 or early 860s. See Old Book of Tang, vol. 177. Kong later served on the staff of another former chancellor, Cui Xuan, when Cui Xuan served as the military governor of Huainan Circuit (淮南, headquartered in modern Yangzhou, Jiangsu).Cui Xuan served as the military governor of Huainan from 855 to sometime early in the Xiantong era, so the time when Kong served under him is not clear. See Old Book of Tang, 163. He then served under Cui Shenyou again at Hua Prefecture (華州, in modern Weinan, Shaanxi) and then Hezhong Circuit (河中, headquartered in modern Yuncheng, Shanxi).As the dates when Cui Shenyou served at those posts are unclear, the dates of Kong's service under him are also unclear. See Old Book of Tang, vol. 177. Under the recommendation of the chancellor Yang Shou, Kong was made the sheriff of Chang'an County, one of the two counties making up the Tang dynasty capital Chang'an, and also served as a researcher at Hongwen Pavilion ().As Yang Shou served as chancellor from 863 to 866, this recommendation must have occurred during that period. See Old Book of Tang, vol. 177. Later, Wang Duo, who was then the deputy chief imperial censor, recommended Kong to be an imperial censor with the title Jiancha Yushi (), and Kong was then made Libu Yuanwailang (), a low-level official at the ministry of rites (禮部, Lǐbu).As Wang Duo's biography did not give dates for his term as deputy chief imperial censor, the date of this recommendation is unclear. See New Book of Tang, vol. 185. The chancellor Xu Shang then recommended that he be made a scholar at Jixian Hall () as well as Kaogong Yuanwailang (), a low-level official at the minister of civil service affairs (吏部, Lìbu, note different tone than the ministry of rites).As Xu Shang served as chancellor from 865 to 869, this recommendation must have occurred during that period. See New Book of Tang, vol. 113.

Kong later left government service when his mother died, to observe a mourning period. He then returned to the imperial government as Yousi Yuanwailang (), a low-level official under one of the secretaries general of the executive bureau (尚書省, Shangshu Sheng). As the chancellor Zhao Yin was impressed by his writing ability, Zhao recommended him to be an imperial scholar (翰林學士, Hanlin Xueshi), as well as Kaogong Langzhong (), a supervisory official at the minister of civil service affairs; he was also put in charge of drafting edicts.As Zhao Yin served as chancellor from 872 to 873, this recommendation must have occurred during that period. See Old Book of Tang, vol. 178. Later, he was made Zhongshu Sheren (), a mid-level official at the legislative bureau (中書省, Zhongshu Sheng), as well as deputy minister of census (戶部侍郎, Hubu Shilang). In the middle of the Qianfu era (874–879) of Emperor Xuānzong's grandson Emperor Xizong, he was relieved of his post as imperial scholar, and made the deputy chief imperial censor (御史中丞, Yushi Zhongcheng). It was said that because Kong had integrity and hated wickedness, during his service at the office of the imperial censors, the office became more cleanly run. Later, when he served successively as the deputy minister of census, then deputy minister of defense (兵部侍郎, Bingbu Shilang), then deputy minister of civil service affairs (吏部侍郎, Lìbu Shilang), he would refuse special requests by powerful individuals. This offended those who made requests of him, and he was given the largely powerless post of minister of worship (太常卿, Taichang Qing).

In late 880, the major agrarian rebel Huang Chao attacked Chang'an, and Emperor Xizong fled to Chengdu.Zizhi Tongjian, vol. 254. Kong followed Emperor Xizong there, and was made the minister of justice (刑部尚書, Xingbu Shangshu) and acting director of finances. However, as the chancellor Xiao Gou, who was a colleague of Kong's while both served as imperial scholars, disliked Kong, he accused Kong of mismanagement, and had Kong given the entirely honorary post of advisor to the Crown Prince (as there was no crown prince at the time). In 885, Kong followed Emperor Xizong back to Chang'an after Huang's defeat.Zizhi Tongjian, vol. 256.

Late that year, the powerful eunuch Tian Lingzi provoked the warlord Wang Chongrong the military governor of Hezhong by ordering Wang transferred, and Wang and his ally Li Keyong the military governor of Hedong Circuit (河東, headquartered in modern Taiyuan, Shanxi) reacted by engaging forces under Tian and Tian's allies Zhu Mei the military governor of Jingnan Circuit (靜難, headquartered in modern Xianyang, Shaanxi) and Li Changfu the military governor of Fengxiang Circuit (鳳翔, headquartered in modern Baoji, Shaanxi). Wang Chongrong's and Li Keyong's forces defeated Tian's, Zhu's, and Li Changfu's forces, and approached Chang'an. As a result, Tian escorted Emperor Xizong to flee to Fengxiang, and then to Xingyuan (興元, in modern Hanzhong, Shaanxi). The imperial officials largely followed Emperor Xizong to Fengxiang, but when he suddenly fled to Xingyuan, few followed (because they were not aware that he had fled further), with Kong and Du Rangneng being among the few who did. Emperor Xizong then commissioned Kong as the chief imperial censor (御史大夫, Yushi Daifu) and ordered him to return to Chang'an and Fengxiang to order the imperial officials to report to Xingyuan. However, when Kong arrived at Fengxiang, the imperial officials — including the chancellors Xiao and Pei Che, who by this point were thoroughly disgusted with Tian's control over the emperor, refused to meet Kong, and even the imperial censors — Kong's subordinates — were finding excuses to refuse to follow him. In anger, Kong stated, "My wife is ill and about to die, and I have left her. If you, gentlemen, are going to care about yourselves this much, this is farewell!" He then met Li Changfu and asked Li Changfu to give him an escort. Li Changfu, impressed, agreed, and had soldiers escort him to Xingyuan.

First chancellorship After Kong Wei's arrival in Xingyuan, Emperor Xizong made both him and Du Rangneng deputy ministers of defense, as well as chancellors, with the designation Tong Zhongshu Menxia Pingzhangshi (). After Emperor Xizong subsequently was able to return to Chang'an after Zhu Mei was killed by his own officer Wang Xingyu (who was promised that if he did so, he could succeed Zhu as military governor of Jingnan), Kong was given the additional post of Zuo Pushe (左僕射, one of the heads of the executive bureau), and was given an iron certificate, guaranteeing that he would not be put to death.

After Emperor Xizong died in 888 and was succeeded by his younger brother Emperor Zhaozong,Zizhi Tongjian, vol. 257. Kong continued to serve as chancellor, and was further created the Duke of Lu. Around the new year 889, when Emperor Zhaozong was set make sacrifices to heaven, the powerful eunuchs (including Yang Fugong, who was instrumental in Emperor Zhaozong's ascension) wanted to participate in the ceremony. Kong opposed, on account that this was against tradition. Emperor Zhaozong, however, still allowed eunuchs to do so, under Kong's subsequently compromise proposal that the eunuchs be required to wear the uniforms for the non-eunuch office titles that they held, rather than the eunuch titles that they held.Zizhi Tongjian, vol. 258.

Still, Kong and fellow chancellor Zhang Jun were repeatedly advising Emperor Zhaozong to try to reduce Yang's influence, and Emperor Zhaozong was receptive. Kong went as far as publicly denouncing Yang for plotting treason (for gathering a large group of army officers around himself as adoptive sons, as well as maintaining a private army). Kong also tried to stand against the influence of the warlord Zhu Quanzhong, the military governor of Xuanwu Circuit (宣武, headquartered in modern Kaifeng, Henan), and when Zhu requested the post of director of salt and iron monopolies for himself, Kong refused, stating to Zhu's emissary, "If Lord Zhu wants this post, he would need to use force to obtain it." Zhu thus withdrew the request.