It's a common practice to place copyright notices, various legal disclaimers and sometimes even full license agreements in each source file of an open-source project. Is this really necessary for a (1) open-source project and (2) closed-source project? What are you trying to achieve or prevent by putting these notices in source files?

I understand it's a legal question and I doubt we can get a fully competent answer here at programmers.SO (it's for programmers, isn't it?) What would also be interesting to hear is, when you put legal stuff in your source files, is it because "everyone does it" or you got legal advice? What was the reasoning?


5 Answers 5


Is this really necessary

No. It's not legally required. (I am not a lawyer, but I've seen this stated by one.)

If you've got a project where individual files might be taken out of context, it may be sensible - but it only requires a couple of lines, to say something like:

This file is part of <project> which is released under <license>.
See file <filename> or go to <url> for full license details.

For anything else, you can simply put a LICENSE text file in the project root, and any relevant details/credits/etc in the README file - it's still copyrighted (automatically), so it's just a question of being clear license-wise in the readme file.

  • 2
    +1 for not putting the whole license boilerplate. I just use one line: Copyright YYYY First Last. Subject to the XYZ license.
    – mk12
    Aug 18, 2012 at 21:40
  • 1
    A lot of companies like to have a copyright line because they want to do "license management". In other words: check for something GPL'ish that was copied from the internet. Basically they scan the source code for a copyright line - which is really just the first line that contains "Copyright" / "(c)". So that line should contain the copyright holder (the author or company) and a hint if it is free software or not. Therefore @mk12 is about right on what a minimum should look like. Because truth is -> any second or third line will never be known anywhere else than in the source code. May 18, 2017 at 18:10
  • It would be nice if for <license> you include the version number. LGPL 2.1 was a nice protective shield for the open source developer. GPL 3.0 is a virus that attempts to consume all.
    – user922020
    Jun 20, 2019 at 18:13
  • 1
    Quick tangent: The point of GPL licenses is to protect the user of the software, not the developer. If you want "protection" as a developer, use MIT (disclaimer of warranty). GPL "infects" other parts of a system to combat a work-around which was used to violate the software freedom of the user, by firewalling sections of GPL'ed code from the rest of the system. If you don't care about your users' software freedom in the first place, then (L)GPL is the wrong choice.
    – hraban
    Feb 21 at 5:14

You could, conceivably simply put your copyright notice that mentions a LICENSE file, however there is no guarantee that once released, your code will remain atomic. In fact, it is quite likely that bits and pieces of it will be remixed in at least several other projects.

This is why it is important to at least have the following in every source file:

/* Copyright (C) 1883 Thomas Edison - All Rights Reserved
 * You may use, distribute and modify this code under the
 * terms of the XYZ license, which unfortunately won't be
 * written for another century.
 * You should have received a copy of the XYZ license with
 * this file. If not, please write to: , or visit :

You accomplish two things by doing this:

  • Your copyright is asserted no matter how your code disintegrates and scatters in the future.
  • You make the terms of using, distributing and modifying it quite clear, even if someone happened to receive only a small part of a library that you wrote.

A lot of people also include their e-mail address under the copyright, which is helpful for receiving patches in the future. I received a patch last month for code that I wrote five years ago and had long forgotten about. Of course, that means maintaining an e-mail address and putting up with a bit of SPAM.

If ever you actually need to enforce your license, it is critical that the other party can't say that the terms were ambiguous or missing, all kidding aside.

Plus, it's fun to watch how bits and pieces of your code find their way into other bits and pieces of code over time. Most people play fair and respect copyright and license terms.

  • 2
    "the terms of the XYZ license, which unfortunately won't be written for another century." It's been 130 years and counting. :P
    – Joe Z.
    Feb 1, 2013 at 15:47
  • A lot of companies like to have a copyright line because they want to do "license management". In other words: check for something GPL'ish that was copied from the internet. Basically they scan the source code for a copyright line - which is really just the first line that contains "Copyright" / "(c)". The example says that it is not free software because it is "All Rights Reserved" - which implies that there must be some license sheet in a third place, may be a LICENSE.TXT file or real paper. Because of that implication you do not need a boilerplate license text. May 18, 2017 at 18:14
  • 1
    Having the copyright header in the file doesn't mean that it won't be lost when bits and pieces are remixed in other projects. People can copy parts of files, or even just remove the copyright header.
    – Timmmm
    Nov 22, 2023 at 12:16

Just wanted to note Open Source != No Copyright.

Open Source relies on someone claiming copyright then adopting a specific legal document (Like the GPL) to give others rights to that code.

So whatever you decided is suitable for closed source code is also suitable for open source code.

  • 1
    Altho there is more chance a single file will be taken elsewhere from an open source project than a closed source one, so maybe copyright notices in the heads of files make more sense in an open source project ...
    – James
    Jan 6, 2011 at 9:17
  • 3
    A license doesn't "give away that copyright". It gives permissions to use and/or modify and/or redistribute. Nov 17, 2015 at 18:45
  • 1
    @GlennRanders-Pehrson Good point, edited.
    – James
    Nov 19, 2015 at 13:59

For any open-source project

You are defining the conditions under which the code is to be used and redistributed (or not, depending on those conditions).

At the very least, a license can answer questions such as:

  • Appropriation: Can someone take the code and evolve it into a different project? A good example of such a phenomenon is Google Chrome, which is based upon the open-source Chromium project.
    • Do they need to give you credit, seek permission, etc...
  • Commercial Use: Can your code be used commercially, such as within Photoshop as a third-party DLL? If so do different conditions apply?
  • Redistribution: Do any uses of your code have to be in software with a similar/identical license? Licenses such as the GPL which require this are called viral licenses (and I don't know if that's a negative term, or just a statement of fact).

Etc. That's by no means a comprehensive list, it's just to give you an idea of the questions a license would state clearly.

  • 4
    I think I understand that, but why should legal notices be put in each source file? Or if they shouldn't then why do people do it?
    – mojuba
    Nov 17, 2010 at 17:40
  • 1
    Sounds like a safe way of ensuring the license isn't lost if it's separated from the source code. Nov 17, 2010 at 17:53

Another reason to put a copyright on your code is that it lets others know who wrote it. I like to be able to see where code came from and how long it has been around. It is interesting and useful to see how code has been used in other projects. So even though legally you may not need to put your copyright on something, please add it for informational reasons. --a thornton

  • 3
    This doesn't answer the question. The question was not whether to put a copyright notice, but whether to put the whole license text in every source file.
    – Brandin
    Nov 21, 2016 at 15:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.