DEV Community

niuniu
niuniu

Posted on

I Calculated the Real Electricity Cost of My AI Coding Sessions. It's More Than My Coffee.

Last month I got curious about a throwaway comment someone made on Hacker News: "My AI coding session burns more power than the average Nigerian gets all day." It had 89 upvotes and 84 comments. People were arguing about whether AI coding is an environmental disaster or just the cost of progress.

So I decided to actually measure it.

The Experiment

I tracked my AI coding usage for 2 weeks using three different setups:

  1. GitHub Copilot (cloud-based, $10/mo)
  2. Claude Code (API calls, ~$0.02-0.10 per session)
  3. Local LLM with Ollama (running on my RTX 4070)

For each, I measured: token count, session duration, and estimated power consumption.

The Numbers

Setup Tokens/session Est. Power (Wh) Daily Cost (USD) Monthly Energy
GitHub Copilot ~15,000 ~50-100 Wh* $0.33 ~3 kWh
Claude Code ~50,000 ~200-400 Wh* $1.50 ~12 kWh
Local Ollama ~20,000 ~300-500 Wh $0.05 ~15 kWh
MonkeyCode (local) ~25,000 ~350-550 Wh $0.06 ~16 kWh

*Estimated including data center cooling, networking, etc.

Wait — local uses MORE electricity? Yes. A data center running thousands of GPUs is more efficient per-query than your home GPU running one model. The difference is who pays the bill and where the carbon comes from.

What Surprised Me

1. It's not the inference — it's the context.

The biggest power draw isn't generating code. It's sending your entire file context (sometimes 50,000+ tokens) to the API every single request. Your codebase is the real energy hog.

2. Autocomplete is sneaky.

GitHub Copilot makes ~50-100 API calls per hour just for ghost text suggestions. Each one is small, but they add up to more power than a single Claude Code conversation.

3. Local models are getting efficient.

Running MonkeyCode with a quantized Qwen 2.5 model, I got surprisingly good results at 4-bit quantization — using about 60% less power than the full-precision version.

The Carbon Math

Let's put this in perspective:

My AI coding (2 weeks):
- Cloud AI: ~18 kWh → ~7.2 kg CO₂ (US grid average)
- Local AI: ~22 kWh → ~8.8 kg CO₂

Equivalent to:
- Driving a car 28 km
- Charging a phone 1,100 times
- Running a light bulb for 240 hours
Enter fullscreen mode Exit fullscreen mode

Is that a lot? Compared to a transatlantic flight (1,600 kg CO₂)? No. Compared to just... not using AI? Yes.

My Optimized Setup

After the experiment, I switched to a hybrid approach:

  1. Quick completions: Local Ollama with a small model (qwen2.5-coder:7b) — fast, free, low power
  2. Complex reasoning: Claude Code via API — pay per use, efficient data centers
  3. Full project work: MonkeyCode with local models — good balance of quality and efficiency

The key insight: use the smallest model that works for the task. Sending a 200-line function to GPT-4 is like driving a Ferrari to the mailbox.

What Developers Can Do

If you care about this (and I think we should):

  1. Be intentional. Don't just hit Tab on every Copilot suggestion.
  2. Use local for simple tasks. Save cloud AI for complex reasoning.
  3. Cache your context. Tools like Cursor cache file embeddings — use them.
  4. Quantize your models. 4-bit models use ~75% less memory and power.

Questions for you:

  1. Do you think about the energy cost of your AI usage, or am I overthinking this?
  2. What's your current AI coding setup, and have you measured its impact? 👇

P.S. If anyone has better power measurement data (especially from data center insiders), I'd love to update these numbers. The estimates above are rough.

Top comments (0)