🌱 GreenSage – VS Code Extension for Sustainable Coding
GreenSage is a Visual Studio Code extension that helps developers write energy-efficient, carbon-aware, and sustainable code by following the principles of the Green Software Foundation.
It analyzes selected portions of your code and suggests improvements that reduce energy consumption, carbon emissions, and hardware waste, while still maintaining correctness and performance.
✨ Features
- 🔍 Selective Code Analysis – Highlight code in your editor and click Analyze Selected Code to receive green suggestions.
- ⚡ Intelligent Improvements – Suggestions are generated using AI, guided by the Green Software Foundation’s Software Carbon Intensity (SCI) framework.
- 🎨 Theme Aware UI – The results panel matches your VS Code theme (dark/light).
- ♻️ Replace with One Click – Apply suggested code changes directly in your file with a Replace in Editor button.
- 📊 GSF-Aligned Guidance – Recommendations follow energy efficiency, carbon awareness, and hardware efficiency principles.
📦 Installation
Clone the repository:
git clone https://github.com/your-username/greensage.git
cd greensage
Install dependencies:
npm install
Compile the extension:
npm run compile
Open the project in VS Code:
code .
Press F5
to run the extension in a new Extension Development Host window.
⚙️ Configuration
GreenSage requires an OpenAI API key to generate intelligent suggestions.
Create a .env
file in the project root:
OPENAI_API_KEY=your_openai_api_key_here
Restart VS Code after setting up the environment file.
🚀 Usage
- Select any portion of code in your editor.
- Right-click and choose Analyze Selected Code, or run the command via the Command Palette (
Ctrl+Shift+P
→ "GreenSage: Analyze Selected Code").
- The right-hand panel will show:
- 🌱 Reasoning – Why the code can be improved
- 🧾 Original Code – The code you selected
- ✅ Suggested Code – The optimized version
- Click Replace in Editor to apply the changes directly.
📖 Example
Original Code:
data = []
for i in range(1000000):
data.append(i * 2)
Suggested Code:
data = [i * 2 for i in range(1_000_000)]
Reason:
- Uses list comprehension, which is more memory-efficient and reduces CPU cycles, aligning with GSF’s energy efficiency guidelines.
🌍 Alignment with Green Software Foundation
GreenSage aligns with the Green Software Foundation (GSF) principles:
- Energy Efficiency – Optimize algorithms and data structures to reduce energy consumption.
- Carbon Awareness – Favor operations that minimize carbon intensity when possible.
- Hardware Efficiency – Reduce resource waste by using efficient patterns.
- SCI Framework – Encourages measurable improvements using Software Carbon Intensity
(E × I) + M per R
.
🛠 Development
- Language: TypeScript
- Framework: VS Code Extension API
- AI Backend: OpenAI GPT models
Build
npm run compile
Run
Press F5
in VS Code to open the extension in dev mode.
🤝 Contributing
Contributions are welcome!
If you’d like to add new features, improve GSF-aligned checks, or enhance UI/UX, feel free to fork the repo and submit a PR.
📜 License
MIT License © 2025 – SkolarAi
🔋 GreenSage – making code sustainable, one refactor at a time. 🌱