But maybe the easiest would be to start your one person contracting company with either a high hourly rate that you can sell to clients who understand your productivity. Or you can bill by job and have clients not care about hours worked. This would let you work whatever you want.
I think the most common config I’ve seen for programmers is to work in 8x5 jobs that only require an hour or two of literal programming. And if lucky, have flexibility within that period to maybe have a few bursts of deep work and then slack time.