Inspiration
Every "green code" tool just asks an LLM to eyeball a score. We wanted proof, not vibes: actually run the code, count real CPU cycles, and turn them into an energy label — like the A–G rating on appliances. Software already has a measurable carbon cost at scale; we wanted to make it visible to any developer in seconds.
What it does
Paste any GitHub repository and GreenCode returns an energy class (A–G), a CO₂ estimate, an efficiency score, and the specific inefficiencies in your code — nested O(n²) loops, string concatenation in loops, redundant work, memory leaks. One click on "Optimize with AI" and a model rewrites the inefficient snippet, preserving behavior. A CLI does real dynamic profiling locally (CPU → mWh → gCO₂e) with a transparent, published formula, so the score is grounded in measurement — not guessing.
How we built it
A Next.js 16 web app, a Node CLI (npx ecocode), and a VS Code extension. The AI layer is provider-agnostic (OpenAI-compatible): it runs on OpenAI (gpt-4o-mini) for fast, reliable inference, and can switch to NVIDIA NIM (google/gemma-4-31b-it, with fallback to Nemotron 120B/550B) via a single environment variable. Robust JSON extraction and cross-model fallback mean an unstable response never breaks the flow. A new agent module runs the real CLI measurement on the hottest files and grounds the AI's suggestions on the measured numbers. The energy formula (CPU_Time × Wattage / 3600, grid intensity 442 gCO₂e/kWh) is public on the Methodology page.
Challenges we ran into
While building the NVIDIA path, reasoning models burned their whole token budget thinking and never produced clean JSON on large repos — we switched to an instruct model and added cross-model fallback. Picking the right files to analyze (real logic, not config or boilerplate) was key to surfacing genuine inefficiencies instead of a bland "everything is fine" score.
Accomplishments that we're proud of
A working end-to-end product — web app, CLI, and VS Code extension — that catches real, specific problems (it flagged an actual memory leak and an O(n²) loop) and fixes them correctly with one click. And a transparent methodology: the CPU → energy → CO₂ formula is published, not a black box. Honesty over hype.
What we learned
Grounding AI on real measurements — and being transparent about what's measured vs estimated — beats a black-box score. We also learned that model choice matters more than model size: an instruct model that returns clean JSON beat much larger reasoning models for this task.
What's next for GreenCode — Code Energy Analyzer & AI Fixer
Automatic pull requests with the fixes, CI gates that fail a build when it drops below a target energy class, and a public leaderboard of the greenest repositories — turning energy efficiency into something teams can track and compete on.
Built With
- ai-agents
- green-software
- nextjs
- node.js
- nvidia-nim
- openai
- supabase
- sustainability
- typescript
- vscode-extension
Log in or sign up for Devpost to join the conversation.