Last updated
Why Every Open Source Project Needs a Code of Conduct
A Code of Conduct (CoC) sets clear expectations for behavior in your project's community — issues, pull requests, discussions, and events. It signals that your project is welcoming to contributors from all backgrounds and gives maintainers a documented basis for handling violations. GitHub, GitLab, and most major open source foundations recommend including one.
The most widely adopted template is the Contributor Covenant, used by over 40,000 open source projects including Linux, Rails, Angular, and Vue.js.
Contributor Covenant v2.1 Structure
- Our Pledge: Commitment to a harassment-free experience for everyone.
- Our Standards: Examples of positive behavior (welcoming language, constructive feedback) and unacceptable behavior (harassment, trolling, personal attacks).
- Enforcement Responsibilities: Maintainers' right and duty to remove, edit, or reject contributions that violate the CoC.
- Scope: Applies to all project spaces and public representation of the project.
- Enforcement: How to report violations and what happens next.
- Attribution: Credit to the Contributor Covenant.
Adding a CoC to Your Repository
# GitHub automatically detects CODE_OF_CONDUCT.md
# Place it in the root, docs/, or .github/ directory
# Download the Contributor Covenant
curl -o CODE_OF_CONDUCT.md https://www.contributor-covenant.org/version/2/1/code_of_conduct/code_of_conduct.md
# Replace the contact placeholder
sed -i 's/\[INSERT CONTACT METHOD\]/conduct@yourproject.org/' CODE_OF_CONDUCT.md
Enforcement Best Practices
A CoC is only effective if violations are actually addressed. Define a clear enforcement process: who receives reports (ideally a dedicated email, not a personal address), how quickly you respond (24–72 hours is standard), and what the escalating consequences are (warning, temporary ban, permanent ban). Document this in a separate ENFORCEMENT.md or in the CoC itself.