First, definitely consult a lawyer and your contract. In the US contract law pretty much says if you signed it, you agreed to it, then it holds, unless the law overrides it. For example, you could sign a contract that says you are now an indentured servant, but that violates the law, so would be unenforceable (at least in the US since 1917). However if it says the equivalent of “any code you write on your personal time is our property” you basically agreed to that being the case and you’d have to consult a lawyer in your state before making a determination if that contract would hold up in court. The best assumption prior to that would be to assume it is valid.

In addition, the FTC recently banned non competes country wide, which went into effect in September 2024. There have been a number of challenges to the ruling that have yet to work through the legal system, so it’s best to consult your states laws for the time being.

But outside of that, if a company in the US is telling you that your software that you can prove you developed on your personal time on your personal property is somehow theirs, and you are certain you never signed such a non-compete or an assignment agreement that covers work on your personal time; then find a new company to work at. They are basically bullying you. If your employee contract is so ambiguous regarding copyright assignment of software written on your own personal time and assets as to not be certain, find a new company as well, as they are probably incompetent. (You’d probably be safe however, as Contra proferentem in the US is a rule that states an ambiguous contract term should be construed against the drafter of the contract)

In fact, in the US, the author always owns the copyright. So in fact the company has to put in place an agreement that outlines that your code copyright is transferred to them. If you pay someone to write software, without such an agreement, the author will still actually hold the copyright. The company can use “work for hire” but since that means they have to prove that they hired you specifically for what your wrote, that it was written in the “scope of employment”; most employers who know what they are doing will have you sign an assignment agreement. Without an assignment agreement; if you write something they didn’t hire you to write and you didn’t agree to assign the copyright to them, you own it.

In fact, if a company also wants to patent something that you’ve invented or been part of inventing, they need to get you to file a patent assignment with the USPTO. This may or may not be outlined in your employment contract, but the assignment still needs to be made. You could refuse, most likely at the cost of your employment, however the patent rights would still remain with you the inventor. Not even work for hire would transfer patent or trademark rights.

All that said, it should be obvious, however it’s probably best pointed out.. if you copy any code that is owned by the company (code written by another employee or that you transferred ownership of to the employer) then you’re committing copyright infringement and can be held liable. So you better be sure your code is 100% yours.