Custom trait and command encoder in an extension?

I’m creating a custom trait using the Decorator class in an extension, to be used only on new counters from the extension, and having a problem where the trait gets replaced by a blank Marker trait when I close and reload the extension. I can see some forum posts from 2012 where people were having a similar problem in a module and suggesting to create a custom command encoder, but is this possible in an extension as opposed to a module?
Would I be better off writing the desired action into a toolbar button that searches the map for all of the particular counter type, rather than trying to put it in a custom trait attached to the counter?

As an experiment, can you try your custom trait in a module, rather than an extension? That would determine if it’s a problem with extensions or something about your trait…

Thanks @jrwatts, I think from reading further that the issue also occurs in a module, because the command defined in the trait is not recognised by the default command encoder (unless you write a custom one to include it). I ended up getting the behaviour I wanted by combining a named command with a hotkey and a trigger action.