The Rambam rules that when Israel wages an optional war, they must first offer peace; if the enemy accepts the Noachide framework and servitude, they are not killed. This is one of the key legal sources for the peace-offer framework in war.
אֵין עוֹשִׂין מִלְחָמָה עִם אָדָם בָּעוֹלָם עַד שֶׁקּוֹרְאִין לוֹ שָׁלוֹם. אֶחָד מִלְחֶמֶת הָרְשׁוּת וְאֶחָד מִלְחֶמֶת מִצְוָה. שֶׁנֶּאֱמַר (דברים כ, י) "כִּי תִקְרַב אֶל עִיר לְהִלָּחֵם עָלֶיהָ וְקָרָאתָ אֵלֶיהָ לְשָׁלוֹם". אִם הִשְׁלִימוּ וְקִבְּלוּ שֶׁבַע מִצְוֹת שֶׁנִּצְטַוּוּ בְּנֵי נֹחַ עֲלֵיהֶן אֵין הוֹרְגִין מֵהֶן נְשָׁמָה וַהֲרֵי הֵן לְמַס. שֶׁנֶּאֱמַר (דברים כ, יא) "יִהְיוּ לְךָ לָמַס וַעֲבָדוּךָ". קִבְּלוּ עֲלֵיהֶן הַמַּס וְלֹא קִבְּלוּ הָעַבְדוּת אוֹ שֶׁקִּבְּלוּ הָעַבְדוּת וְלֹא קִבְּלוּ הַמַּס. אֵין שׁוֹמְעִין לָהֶם עַד שֶׁיְּקַבְּלוּ שְׁנֵיהֶם. וְהָעַבְדוּת שֶׁיְּקַבְּלוּ הוּא שֶׁיִּהְיוּ נִבְזִים וּשְׁפָלִים לְמַטָּה וְלֹא יָרִימוּ רֹאשׁ בְּיִשְׂרָאֵל אֶלָּא יִהְיוּ כְּבוּשִׁים תַּחַת יָדָם. וְלֹא יִתְמַנּוּ עַל יִשְׂרָאֵל לְשׁוּם דָּבָר שֶׁבָּעוֹלָם. וְהַמַּס שֶׁיְּקַבְּלוּ שֶׁיִּהְיוּ מוּכָנִים לַעֲבוֹדַת הַמֶּלֶךְ בְּגוּפָם וּמָמוֹנָם. כְּגוֹן בִּנְיַן הַחוֹמוֹת. וְחֹזֶק הַמְּצוּדוֹת. וּבִנְיַן אַרְמוֹן הַמֶּלֶךְ וְכַיּוֹצֵא בּוֹ. שֶׁנֶּאֱמַר (מלכים א ט, טו) "וְזֶה דְבַר הַמַּס אֲשֶׁר הֶעֱלָה הַמֶּלֶךְ שְׁלֹמֹה לִבְנוֹת אֶת בֵּית ה' וְאֶת בֵּיתוֹ וְאֶת הַמִּלּוֹא וְאֵת חוֹמַת יְרוּשָׁלָםִ" (מלכים א ט, יט) "וְאֵת כָּל עָרֵי הַמִּסְכְּנוֹת אֲשֶׁר הָיוּ לִשְׁלֹמֹה" (מלכים א ט, כ) "כָּל הָעָם הַנּוֹתָר מִן הָאֱמֹרִי" (מלכים א ט, כא) "וַיַּעֲלֵם שְׁלֹמֹה לְמַס עֹבֵד עַד הַיּוֹם הַזֶּה" (מלכים א ט, כב) "וּמִבְּנֵי יִשְׂרָאֵל לֹא נָתַן שְׁלֹמֹה עָבֶד כִּי הֵם אַנְשֵׁי הַמִּלְחָמָה וַעֲבָדָיו וְשָׂרָיו וְשָׁלִישָׁיו וְשָׂרֵי רִכְבּוֹ וּפָרָשָׁיו": וְאִם לֹא הִשְׁלִימוּ אוֹ שֶׁהִשְׁלִימוּ וְלֹא קִבְּלוּ שֶׁבַע מִצְוֹת. עוֹשִׂין עִמָּהֶם מִלְחָמָה וְהוֹרְגִין כָּל הַזְּכָרִים הַגְּדוֹלִים. וּבוֹזְזִין כָּל מָמוֹנָם וְטַפָּם. וְאֵין הוֹרְגִין אִשָּׁה וְלֹא קָטָן שֶׁנֶּאֱמַר (דברים כ, יד) "וְהַנָּשִׁים וְהַטָּף" זֶה טַף שֶׁל זְכָרִים. בַּמֶּה דְּבָרִים אֲמוּרִים בְּמִלְחֶמֶת הָרְשׁוּת שֶׁהוּא עִם שְׁאָר הָאֻמּוֹת. אֲבָל שִׁבְעָה עֲמָמִין וַעֲמָלֵק שֶׁלֹּא הִשְׁלִימוּ אֵין מַנִּיחִין מֵהֶם נְשָׁמָה שֶׁנֶּאֱמַר (דברים כ, טו) "כֵּן תַּעֲשֶׂה לְכָל" וְגוֹ' (דברים כ, טז) "רַק מֵעָרֵי הָעַמִּים" (דברים כ, טז) "לֹא תְחַיֶּה כָּל נְשָׁמָה". וְכֵן הוּא אוֹמֵר בַּעֲמָלֵק (דברים כה, יט) "תִּמְחֶה אֶת זֵכֶר עֲמָלֵק". וּמִנַּיִן שֶׁאֵינוֹ מְדַבֵּר אֶלָּא בְּאֵלּוּ שֶׁלֹּא הִשְׁלִימוּ שֶׁנֶּאֱמַר (יהושע יא, יט) "לֹא הָיְתָה עִיר אֲשֶׁר הִשְׁלִימָה אֶל בְּנֵי יִשְׂרָאֵל בִּלְתִּי הַחִוִּי ישְׁבֵי גִבְעוֹן אֶת הַכּל לָקְחוּ בַמִּלְחָמָה" (יהושע יא, כ) "כִּי מֵאֵת ה' הָיְתָה לְחַזֵּק אֶת לִבָּם לִקְרַאת הַמִּלְחָמָה אֶת יִשְׂרָאֵל לְמַעַן הַחֲרִימָם". מִכְלַל שֶׁשָּׁלְחוּ לָהֶם לְשָׁלוֹם וְלֹא קִבְּלוּ: שְׁלֹשָׁה כְּתָבִים שָׁלַח יְהוֹשֻׁעַ עַד שֶׁלֹּא נִכְנַס לָאָרֶץ. הָרִאשׁוֹן שָׁלַח לָהֶם מִי שֶׁרוֹצֶה לִבְרֹחַ יִבְרַח. וְחָזַר וְשָׁלַח מִי שֶׁרוֹצֶה לְהַשְׁלִים יַשְׁלִים. וְחָזַר וְשָׁלַח מִי שֶׁרוֹצֶה לַעֲשׂוֹת מִלְחָמָה יַעֲשֶׂה. אִם כֵּן מִפְּנֵי מָה הֶעֱרִימוּ יוֹשְׁבֵי גִּבְעוֹן. לְפִי שֶׁשָּׁלַח לָהֶם בַּכְּלָל וְלֹא קִבְּלוּ. וְלֹא יָדְעוּ מִשְׁפַּט יִשְׂרָאֵל וְדִמּוּ שֶׁשּׁוּב אֵין פּוֹתְחִין לָהֶם לְשָׁלוֹם. וְלָמָּה קָשָׁה הַדָּבָר לַנְּשִׂיאִים וְרָאוּ שֶׁרָאוּי לְהַכּוֹתָם לְפִי חֶרֶב לוּלֵי הַשְּׁבוּעָה. מִפְּנֵי שֶׁכָּרְתוּ לָהֶם בְּרִית וַהֲרֵי הוּא אוֹמֵר (דברים ז, ב) "לֹא תִכְרֹת לָהֶם בְּרִית" אֶלָּא הָיָה דִּינָם שֶׁיִּהְיוּ לְמַס עֲבָדִים. וְהוֹאִיל וּבְטָעוּת נִשְׁבְּעוּ לָהֶן בְּדִין הָיָה שֶׁיֵּהָרְגוּ עַל שֶׁהִטְעוּם לוּלֵי חִלּוּל הַשֵּׁם:
War, neither a milchemet hareshut or a milchemet mitzvah, should not be waged against anyone until they are offered the opportunity of peace as Deuteronomy 20:10 states: 'When you approach a city to wage war against it, you should propose a peaceful settlement.' If the enemy accepts the offer of peace and commits itself to the fulfillment of the seven mitzvot that were commanded to Noah's descendents, none of them should be killed. Rather, they should be subjugated as ibid.:11 states: 'They shall be your subjects and serve you.' If they agree to tribute, but do not accept subjugation or if they accept subjugation, but do not agree to tribute, their offer should not be heeded. They must accept both. The subjugation they must accept consists of being on a lower level, scorned and humble. They must never raise their heads against Israel, but must remain subjugated under their rule. They may never be appointed over a Jew in any matter whatsoever. The tribute they must accept consists of being prepared to support the king's service with their money and with their persons; for example, the building of walls, strengthening the fortresses, building the king's palace, and the like as I Kings 9:15-22) relates: "This is the tribute which Solomon raised to build the House of God, his own palace, the Milo, the wall of Jerusalem,... and all the store-cities which Solomon had... All the people that remained from the Amorites... upon them did Solomon lay a tribute of bondservice until this day." In contrast, Solomon did not make bondsmen out of the children of Israel. They were men of war, his personal servants, his princes, his captains, the officers of his chariots, and his horsemen. If they do not agree to a peaceful settlement, or if they agree to a peaceful settlement, but refuse to accept the seven mitzvot, war should be waged against them. All males past majority should be killed. Their money and their children should be taken as spoil, but neither women or children should be killed, as Deuteronomy 20:14 states: 'But the women and the children... take as spoil." 'The children' refer to males below the age of majority. The above applies to a milchemet hareshut fought with other nations. However, if either the seven nations or Amalek refuse to accept a peaceful settlement, not one soul of them may be left alive as ibid. 20:15-16 states: 'Do this to all the cities that ... are not the cities of these nations. However, from the cities of these nations,... do not leave a soul alive.' Similarly, in regard to Amalek, Deuteronomy 25:19 states: 'Obliterate the memory of Amalek.' How do we know that these commands are only referring to those who did not accept a peaceful settlement? Joshua 11:19-20 states: 'There was no city which accepted a peaceful settlement with the children of Israel except the Chivites who lived in Gibeon. All the rest, they conquered in battle. This was inspired by God, Who strengthened their hearts to engage in battle against Israel so that they would be destroyed.' From these statements, we can infer that a peaceful settlement was offered, but they did not accept it. Joshua sent three letters to the Canaanites before entering the promised land: At first, he sent them: 'Whoever desires to flee, should flee.' Afterwards, he sent a second message: 'Whoever desires to accept a peaceful settlement, should make peace.' Then, he sent again: 'Whoever desires war, should do battle.' If so, why did the inhabitants of Gibeon employ a ruse? Because originally, when he sent the message to them as part of all the Canaanite nations, they did not accept. They were not aware of the laws of Israel and thought that they would never be offered a peaceful settlement again. Why was the matter difficult for the princes of Israel to accept to the point that they desired to slay the Gibeonites by the sword were it not for the oath they had taken? Because they made a covenant with them and Deuteronomy 7:2 states 'Do not make a covenant with them.' Rather, the laws governing their status would have prescribed that they be subjugated as servants. Since the oath was given to them under false pretenses, it would have been just to slay them for misleading them, were it not for the dishonor to God's name which would have been caused.