When a person creates a new work that is a derivative of an existing copyrighted work, the author of the new work gets a copyright on its original content (not on content copied from the base work). However, creating a derivative work is one of the protected rights of copyright (in US law, this is in 17 USC 106), so the author of the new work must have permission, or else has committed copyright infringement.
As a practical matter, a derivative work created purely for personal use is highly unlikely to be the subject of an infringement suit, but if the derivative work is distributed, and particularly if it is offered for public sale, such a suit is much more plausible.
When a consultant creates a copyrightable work on behalf of a client, the consultant will own the copyright of this work unless consultant and client agree otherwise. This agreement should be in the consulting contrast. The contract may specify that the client will own the work, or that the consultant will own it but grant the client a license, permanent or temporary, exclusive or non-exclusive. If the client owns the copyright, the contract could grant the consultant permission to create derivative works based on the work done for the client. The terms may be whatever consultant and client agree to, except that neither may contract away their fair-use or fair-dealing rights, nor may the author contract away the future termination rights (under US law) on any license or grant.
If the intent is that the consultant is to be allowed to reuse the software on other projects, the simplest arrangement might be to have the consultant keep the copyright, granting a permanent but non-exclusive license to the client. Or there might be an exclusive license to the original version, but with a provision that this does not exclude significantly different derivative versions. However, if the client wants to own the copyright, the contract could grant the consultant the right to prepare, distribute, and sell derivative works based on it. It would also be possible for consultant and client to co-own the copyright, in which case each would be required to account to the other for profits made from the work -- probably not what is wanted.
In general, as long as the agreement spells out what the rights of developer and client will be, it will be followed and be binding as written unless it is against some specific statute or public policy, which seems unlikely for any reasonable agreement in this sort of matter.