I know someone who pursued this route in her career. She found that the most control she could exercise along these lines was as a consultant, where she accepted tasks and then had control over when and how to work in order to complete the tasks. (Eventually, she advanced enough in her career to where in order to be challenged she had to accept work that used a higher percentage of her time.)
The other option I know of is that some companies will pay you to write code piecemeal instead of having a contract. The model is something like: you have a short period of time to finish this project while meeting a standard of quality. If you don't meet the standard of quality or finish in the specified time, you get paid nothing.
Oh, also small companies and start ups sometimes have part-time roles, although in some cases they want people who are willing to transition to full-time if the business grows.
A few warnings about this:
- These career options usually are less stable than normal jobs. You are likely to spend a larger percentage of your time between opportunities.
- Assuming you are in the USA, in a lot of cases, these would come without health care. You would need to make other arrangements there.
- As mentioned in another answer, having hard constraints like this without having a lot of experience or a track record can make it hard to find people willing to make arrangements for you. The person I mentioned first did not start her career working as a contractor part-time. IIRC, it was 8-10 years into her career that she decided to make the change. Edit: developing specialized skills within the industry would also make it easier to set terms on how you would like to work.