Vesting is a better term to use.
The code (edition) that applies to a permit is the code in effect on the day the permit is applied for.
Let's assume for discussion purposes that the building you're speaking of was built lawfully with a permit to which some code edition applied.
That code edition applies to that permit for the life of the permit.
The building is vested to that standard for the life of the building with very few exceptions (i.e. an ordinance requiring smoke detectors in all residential occupancies).
So now let's assume you want to add on to that building - let's say we're adding on an in-laws suite.
All new work must meet new code (let's use GFCI as the example). The new restroom will have GFCI. Generally speaking, you don't have to go through the original part of the building and change that out to GFCI.
But in doing this project, you're adding load to the project. Let's assume you need a service change to handle the larger load. The new service must meet new code (the code edition on the date you applied for the permit to build the addition).
But everything else in the old part of the building is vested to that old code edition.
So in summary, all new work must meet current code and any impact on existing work must be addressed. When new work has no impact on old work, that old work is still vested. Exceptions might be change in occupancy classification or expansion of 50% area or dollar value, depending on where the project is located.