->''"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 ''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.

[[folder:Live action TV]]
* The Bro Code from ''Series/HowIMetYourMother''.
* [[Series/DoctorWho "Never cruel or cowardly. Never give up, never give in."]]

[[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.
* 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.


* ''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.

[[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.