->''"I will not bring dishonour on my sacred arms nor will I abandon my comrade wherever I shall be stationed. I will defend the rights of gods and men and will not leave my country smaller, when I die, but greater and better, so far as I am able by myself and with the help of all. I will respect the rulers of the time duly and the existing ordinances duly and all others which may be established in the future. Furthermore, if anyone seeks to destroy the ordinances I will oppose him so far as I am able by myself and with the help of all. I will honor the cults of my fathers. Witnesses to this shall be the gods Agraulus, Hestia, Enyo, Enyalius, Ares, Athena the Warrior, Zeus, Thallo, Auxo, Hegemone, Heracles, and the boundaries of my native land, wheat, barley, vines, olive-trees, fig-trees..."''
-->-- '''[[IGaveMyWord Oath of]] [[AncientGreece Athenian soldiers]]'''

In order to have [[CharacterAlignment Lawful characters]], you first need to have a law. Most works provide that law in the form of The Code of Honour.

The Code is basically any code of honor or conduct that governs a certain group of people. Codes can be written down or oral tradition, they can be short or long, or practical or philosophical; the gist of the trope is that it has the more lawful characters of the cast mulling over which course of action would be "true to The Code".

[[TheOrder Orders]] and {{Ancient Tradition}}s are very likely to possess one of these. The ObstructiveCodeOfConduct is the most important (or just first) article of The Code. TheCommandments are a very brief Code presented in the form of an enumerated list. The BigBookOfWar is a written-down Code that pertains specifically to war. HonorBeforeReason is what happens when someone insists on following The Code even when this is obviously a really stupid thing to do.

See also, HeroicVow, which sometimes coincides.



* Justified in ''Fanfic/{{Jericho}}''. The titular [[FirstPersonSmartass Jeri]][[SociopathicHero cho]] has a very simple one, with only two specific entries about rules he must not break. Jericho explains that they exist to keep him from becoming an irredeemable monster, since Jericho ''is'' a [[TheSociopath sociopath]]. The code is:
** ''"Harm not children. Commit not rape."''
** However, [[spoiler:the Code/Kodex only gets elaborated upon ''after'' Jericho accidentally breaks it when he kills a child. And then willingly kills several more children. And their parents. And ends up murdering every single member of the small town of Sleepy Oaks. Because they're trying to murder him after enervation drives them all homicidally mad, giving Jericho no choice. After breaking the Code, for the first time ever does Jericho [[OOCIsSeriousBusiness break down and lose his sense of optimistically dark humor]], becoming a StepfordSmiler as he tries to hide his sins from his companions.]]

* The Jedi Code in ''Franchise/StarWars''. Depending on the era and individual, the Sith code can also function as one.
* The "Code of the West" is sometimes mentioned in TheWestern genre.
* The Pirate Code of ''Franchise/PiratesOfTheCaribbean'' is more like a set of guidelines rather than actual rules, but it still works.
* The Arthurian code of chivalry, as referenced in ''Film/{{Dragonheart}}''.

* In ''Literature/ABrothersPrice'', there seems to exist a code of honour, although it is never described in detail. Princess Trini, who was unwilling to marry in the first place, invokes her "duty", when her husband is in danger. "It is a wife's duty to protect her husband" - and she will do so, and risk her life for it. Whether she ''loves'' him isn't important.
* The Code that the barbarian heroes (and their opposite numbers, Dark Lords) live by in ''Literature/{{Discworld}}''.
** Also, the Igors in ''Literature/{{Discworld}}'' have a Code which requires such things as "The Marther is always right." and "Don't ask [big] questions." At one point in ''Discworld/ThiefOfTime'', an Igor has to answer a question he cannot due to the Code. He simply says "I would be unable to say that." They must also not betray the Master but at the same time the Code doesn't forbid them from leaving right before the villagers come with torches and pitchforks.
* ''Literature/TheStormlightArchive'':
** The Alethi Codes of War are an ancient set of rules that the local ProudWarriorRace gave up centuries ago as part of their devolution into {{Blood Knight}}s. Dalinar is the only one who still holds to them, and the other highprinces scoff at the idea, insisting that no one ever ''actually'' followed them, they just claimed to so that they could pretend to be honorable. The really sad thing is that any modern real-world army would find the Codes perfectly reasonable, and in many cases less restrictive than real military doctrine: Stay in uniform while in a war zone, don't drink while on duty, don't duel unnecessarily in case important officers get injured, don't ask your men to do something you wouldn't do yourself, and don't abandon allies on the battlefield or seek to profit from their loss. It shows how much the Alethi have fallen that they refuse to even consider the wisdom in any of that.
** The Knights Radiant had the Immortal Words, five oaths they lived by. The first Ideal ("Life before Death, Strength before Weakness, Journey before Destination") was the same for all ten Orders, but the other four were different. They derived these codes from a book called ''The Way of Kings'', written by a ruler who had achieved peace throughout his kingdom.
* In ''Franchise/TheWitcher'' series, Geralt [[spoiler:pretends he]] has one of these and will often bring it up when he refuses a job or stays neutral in any given conflict. [[spoiler:There actually is a code but all it really covers is not sharing Witcher secrets and lore and preserving the secrecy of the mutagens that allow them to do their jobs. So Geralt is just bullshitting people when he quotes the Witcher Code when he doesn't want to do something.]]
* The Warrior Code in the ''Literature/WarriorCats'' series. It's eventually deconstructed in the ''Power of Three'' arc when [[spoiler:Hollyleaf, who had used the code to determine morality, realizes that the code is imperfect and goes on a murderous rampage.]] Then it gets reconstructed in ''[=SkyClan=]'s Destiny'' and ''The Forgotten Warrior'', [[spoiler:when the characters realize that the code is a guideline that can be changed, and when Hollyleaf uses it to atone.]]
* In ''Literature/TheDresdenFiles'' TheFairFolk ''live'' by this. All their actions, both benign and malign, fall under this. Any debt incurred ''must'' be repaid in kind. Any injury ''must'' have an appropriate response. To claim a Fae has violated this is a grave insult. Another dangerous action is ''giving'' them a gift because they do not like being forced into being a debtor. The prospect of reneging on a debt owed to a mortal, because if the mortal is dead the debt cannot be repaid, is enough to make a powerful Fae assassin halt and listen to the request for repayment and then act on it. If the mortal was still targeted once the repayment happened, the assassin would finish the job then.
* The Shadowhunters' Law from ''Literature/TheMortalInstruments'', which provides a moral framework for what they do, but which is often very restrictive. Both the [[NeutralGood heroes]] and [[NeutralEvil villains]] have a distinct tendency to try to circumvent it, even while accepting it in principle.
* In ''Literature/MoDaoZuShi'', no other sect matches the Lan sect for scope: they carve all their rules on the giant Wall of Discipline at the entrance of the Cloud Recesses. In his time studying there, Wei Wuxian noted that there were three thousand-plus rules crammed onto the wall. In the thirteen years since he [[FirstEpisodeResurrection died]], a thousand more were added...

[[folder:Live action TV]]
* The Bro Code from ''Series/HowIMetYourMother''.
* [[Series/DoctorWho "Never cruel or cowardly. Never give up, never give in."]]
* As revealed in ''Series/StarTrekDeepSpaceNine'', the Ferengi Alliance has a code of honor known as the "Rules of Acquisition", which outlines how to live a profitable life.

[[folder:Professional wrestling]]
* The Code Of Honor was/is the defining trait of Wrestling/RingOfHonor. It used to be a five point law that could earn one severe penalties if they violated it, put in place to cut back on {{t|ryingtocatchmefightingdirty}}he [[EasilyDistractedReferee usual]] [[GlassJawReferee antics]] [[RageQuit that]] go on in professional wrestling. For two years it seemed to be working, with even most of the {{heel}}s subscribing to it at least partially. But then its obvious flaw became apparent; if most of the roster decides to violate it, are you going to suspend them all? Having strayed from its super indie roots, finding replacements in time for the next show would prove nigh impossible, so Gabe Sapolsky did away with the code. After he left the company it was brought back, although simplified to what amounted to "play nice" as there were no longer penalties for violators.
* Wrestling/SamoaJoe tried to end the career of Wrestling/ChristopherDaniels in Wrestling/{{TNA}}, Wrestling/AJStyles accused Joe of violating the unwritten code of honor that comes with being a part of the X-Division, a code Joe said he did not care about in response. This was a [[CharacterizationMarchesOn great divergence]] from Joe's [[ProudWarriorRaceGuy usual gimmick]], where he refused to break ROH's code even when Christopher Daniels paid him to. He also kept upholding an honor code in The Pure Wrestling Association.[[/folder]]

[[folder:Tabletop Games]]
* ''TabletopGame/{{GURPS}}'' has various Codes of Honour as disadvantages. While many of them are connected to specific organisations, there's also things like the "Pirates' Code of Honour" and "Gentlemen's Code of Honour"
* The Oath and the Measure of the Solamnic Knights in the ''TabletopGame/DungeonsAndDragons'' Literature/{{Dragonlance}} setting.
* ''TabletopGame/ForgottenRealms'' has too many specific organizations. Even [[ChurchMilitant paladin orders]] of the same god don't have ''exactly'' the same charter: they were founded by different leaders for different goals. Of those published, there's The Code of the [[HeroSecretService Harpers]] (they [[http://index.rpg.net/display-entry.phtml?mainid=9425 got]] a separate {{sourcebook}}).
* The Paladin's Code from ''TabletopGame/DungeonsAndDragons'' is intended to be a non-denominational version, and the paladin must adhere to it or lose his abilities. Unfortunately, sticking to the letter of the code will result in a LawfulStupid character. They're not even allowed to render ''aid'' to chaotic characters.
** ... in some editions. 3E downgraded it to not allowing aid if said aid would be used for chaotic purposes, and it became even more flexible in 4E and 5E.
* The Aslan ''Fteir'' code in ''TabletopGame/{{Traveller}}''.
* There are many Codes of Conduct found in ''TabletopGame/RocketAge'', from the oaths taken by Maduri warriors to the ethics practised by reporters and private detectives. All are covered by the Code of Conduct bad trait.
* The dogs of ''TabletopGame/{{Pugmire}}'' believe in the Code of Man, which contains edicts such as "[[WeHelpTheHelpless protect those who are true]]," "[[UndyingLoyalty obey a worthy master]]" and "[[AdventurerArchaeologist fetch that which has been left behind]]." Since this is a somewhat idealistic game, all player characters are expected to pick at least some of them to adhere to, though they are free to disregard others as being "[[NoTrueScotsman not the important parts of the Code]]."
** The ''Monarchies of Mau'' spin-off, which covers cats in the setting, reveals the cats have their own code of honor, the Precepts of Mau. Contrasting the dog approach of one big code that dogs can find some parts not important, there are only four common precepts[[note]]"Always trust your instincts. Always pounce upon the minions of the Unseen. Always reward loyalty. Always respect an honest duel."[[/note]], but cat noble houses have their own additional Precepts (such as "Always push boundaries.").
* ''TabletopGame/Warhammer40K'':
** Khornate warriors vary from vaguely honorable fighters (very rare) to bloodthirsty maniacs who'll kill anything that moves including allies (the vast majority). However, the one thing they have in common is that Khorne demands the skulls of warriors (enemies or your own), but doing something like proclaiming yourself a great warrior after valiantly decapitating defenseless victims is a very good way to get the Blood God pissed at you specifically.
** Part of the reason the Tau are viewed with great suspicion by the Imperium is that they ''don't'' hold HonorBeforeReason- where Imperial history is filled with glorious last stands that might have been avoided in retrospect with a little more mental flexibility, the Tau's view is that a commander who let the situation degrade that badly was clearly incompetent in the first place. They'l also agree to leave conflicts if it's too much effort for not enough reward to win, something the Imperium can't imagine itself doing.

* ''Toys/{{Bionicle}}'' has the Toa Code, which is basically ThouShallNotKill.

[[folder:Video Games]]
* The code of the Asari Justicars in ''VideoGame/MassEffect2''.
* The titular ''Franchise/AssassinsCreed'' is a sort of anti-Code that still manages to be a Code: "The wisdom of our creed is revealed in these words: '[[TheAntiNihilist Nothing is true. Everything is permitted]].'" Naturally, there isn't much debate over what fits with a Code like that, only how it should be applied. Their was originally a whole slew of other rules (no poison, a number of ritual requirements like removing a finger to earn hidden blade privileges, absolute loyalty to superiors, etc.) but these were mostly abandoned over the centuries and each protagonist follows the warrior code appropriate to their culture.

[[folder:Web Original]]
* In ''Roleplay/TheGamersAlliance'', some thieves follow specific rules of honour known as the Code of Thieves. The Code specifies what thieves can and can't do. Over the years many thieves have abandoned the Code as they see it as antiquated, but others have successfully integrated it into their guilds and their way of life.

[[folder:Western Animation]]
* Da Rules in ''WesternAnimation/TheFairlyOddParents''.
* The Code of Thundera in ''WesternAnimation/ThunderCats'': "Justice, Truth, Honor, and Loyalty."
* The Unwritten Kids Code of Honor in ''WesternAnimation/{{Recess}}''
* The Code of The Schoolyard mentioned in an early episode of ''WesternAnimanimation/{{TheSimpsons}}''. After Bart is beaten up, he won't tell a teacher because that would violate the code.
* Two episodes of ''WesternAnimation/DefendersOfTheEarth'' reference this trope:
** "A Demon in His Pocket" reveals that the Defenders have a Code of Honour which forbids them from fighting unnecessarily. So when Kshin is targeted by the school bullies, he feels unable to fight back, leading to him disobeying a direct order not to touch Mandrake's sorcery books and summoning the titular demon.
** In "Return of the Skyband", the Phantom tells the other Defenders about an incident where his grandfather encountered an all-female band of SkyPirates, but was unable to fight them because of a Code of Honour which forbids those who assume the Phantom title from harming women.
* In ''WesternAnimation/BeastWars'', Predicons do have a complex code of honor they pay lip service to to some degree. What made Dinobot switch sides in the first episode wasn't that Megatron was wrong, but rather when he challenged Megatron's authority on that, Megatron had another Predicon eliminate Dinobot, rather than face him in one on one combat. What endeered him to the Maximals in general and Optimus in particular was that Optimus was willing to accept Dinobot's challenge to leadership and face him in single combat and accept that if he lost, he would be killed by Dinobot, but revealed that the stipulation of death to the loser was not returned to Dinobot (Optimus chose to spare his life and still allow him on his team.). We'd see in later episodes Dinobot was shown evidence to suggest his initial challenge of Megatron was ill informed, and switch back, but his established loyalty with the Maximals was in constant conflict when this happened.
** WordOfGod holds that among the Predicons, Trechary was not a dishonorable act cowardly act (This version of Megatron has at most two loyal followers, neither at the same time) and in fact, Megatron values it. The catch here is that treachery was used as a test of good leadership. A good leader, would be able to stop treachery, either through inspiring loyalty or by preventing treacherous underlings from a successful challenge. Meanwhile, subotdinantes could achieve leadership by successful coups and were expected to challenge authority by betraying leadership if they felt leadership was poor, however, they should anticipate that their leader would be able to counter their machiations.
** Dinobot's closest friend on the Maximals was Rattrap, who seemed to VitriolicBestBuds do to their own personal codes coming into conflict. Ratrrap was devout to the Maximal cause but not to Maximal Codes of Honor. Conversely, Dinobot was not devout to the Predicon Cause but was devout to Predicon Codes of Honor. Dinobot was willing to make a HeelFaceTurn because Megatron had crossed a line. Rattrap was willing to make a FaceHeelTurn because it would give the Maximals an edge if he joined the Predicons for a while. So natrually, they had no trust of each other. Rattrap would always be suspicious because Dinobot lived by an idealogy that was payed lip service to by so many of his loyal members, so obviously Dinobot was just a spy and not an ethically troubled individual. Meanwhile, Dinobot saw in Rattrap an individual who payed lip service to an moral idealology, but only so much as it justified his dishonoralbe actions, essentially, what he betrayed Megatron over.

[[folder:Real Life]]
* The [[http://en.wikipedia.org/wiki/Bushido bushido code]] of the samurai class.
* The [[http://en.wikipedia.org/wiki/Knight#Chivalric_code chivalric code]] of medieval knights.
* TheMafia code of [[http://en.wikipedia.org/wiki/Omerta Omertà]].
* The [[http://en.wikipedia.org/wiki/Hippocratic_oath Hippocratic Oath]] for doctors. Making this trope OlderThanFeudalism.
* Lawyers, being lawyers, know that [[AmoralAttorney some in their profession]] will want to, erm, [[RulesLawyer lawyer]] their way around any Code, have come up with very complicated Codes that either leave little room for wiggling or limit how useful to the lawyer or damaging to others the wiggling can be. The American [[http://en.wikipedia.org/wiki/American_Bar_Association_Model_Rules_of_Professional_Conduct Model Rules of Professional Conduct]] (applied in some form in all states except California, which has slightly different rules) are a good example. (Incidentally, this code contains Rule Number 1 for lawyers: "[[StealingFromTheTill Touch your client's money and you're done]].")
* Most professional bodies will similarly have their own codes of conduct/good practice.