He researched an extensive history of the Jews of Tripoli that served as a resource for later historians such as Abraham Hayyim Adadi, Mordechai Ha-Cohen, and Nahum Slouschz, and also composed piyyutim (liturgical poems) and kinnot (elegies).
[1] Khalfon also served as an advisor to Ali Pasha of the Karamanli dynasty, which directly ruled Tripoli, regarding taxation of the Jewish community.
[1] Khalfon produced a history of the Jews of Tripoli from ancient times until his own day, culling government archives, rabbinical court documents, and genizah records.
[1][2][5] His Hebrew-language work, called by others Seder HaDorot (Hebrew: סדר הדורות, "Book of Generations"), was an important source for Abraham Hayyim Adadi's historical writings about Tripoli minhagim (customs) in the mid-nineteenth century.
[2][8] Nahum Slouschz also quotes Khalfon in his 1927 history of the Jews of North Africa, such as Khalfon's description of the origins of the Tripoli Jewish community: "Among the older people I found a tradition, handed down to them by their ancestors, that at the time of the destruction of Jerusalem, one of the generals of Titus, Phanagorus, King of the Arabs, led a number of captive Jews into the mountains, two days distant from Tripoli, and there handed them over to the Arabs.
His elegy for his murdered son, David, and his piyyut, Mi Kamokha (Hebrew: מי כמוך, "Who is like You"), both stemmed from the reign of terror perpetrated by Ali Burghul against the Jews of Tripoli from July 30, 1793, to January 20, 1795.
[13][14] Ali Burghul imposed heavy taxes and engaged in many acts of robbery and blackmail against the population, and gave his soldiers free rein to terrorize the residents, particularly Jews.