That all depends on exactly what popped into my head. Let's say it's a pretty obvious idea that's almost fully formed, like "let's wrap a web form around OpenSSL so the support techs can make certificate requests". That comes together as a couple of blocks in my head.
One block is "have a basic FORM as the UI" - basic HTML, no big deal, easily done. The second block is "have something to handle the incoming POST data" - libraries I had already written, so again, no big deal.
The third block was "somehow pass it to OpenSSL and get back the data". This is where all of the unknowns lurked. I had to actually play with it to see if it had a reasonable way to be controlled by another program. It turned out that it could be done without too much trouble, and with that known, the third block was considered possible.
Finally, the fourth block would be to take the results and render them on the page returned by the POST handler. That's just a bit of HTML and other CGI magic - easy enough.
When the idea first comes to me, 1, 2, and 4 are fully-formed in my head, and 3 needs elaboration. A few minutes of poking on 3 convinces me it's possible, and thus with everything seeming reasonable, I start in on it.
Total time elapsed from "hey, we need this" to "hey you, try this thing I just wrote" was about 25 minutes. I only know this because it happened with a nicely timestamped chat log, and I worked backwards to figure it out.
That's not quite an answer to "how long until first line of code", but it does give you a window: under 30 minutes, if it's a situation like this.
As for the tools, back then: C, pico/nano, home-brewed CGI helper libraries, Linux, Apache.
These days, it's the same, only with (a specific subset of) C++ in place of C. I can elaborate on which bits if you really care. Use whatever language works for you.
Workflow is basically this: open two xterms or similar. Open an editor in the top one, write code. Open bottom one, use it to "make && ./prog". Open other windows as necessary for research or experimentation (like fiddling with the OpenSSL stdin hookup, reading man pages, etc).
The whole workspace (fluxbox) is nothing but terminals. Browsers and other stuff go off to another workspace. My chat window stays on another screen/system, and is sometimes hidden when uninterrupted cycles are needed for a short burst.
Hope this helps.