
The Pitch: We all write questionable code sometimes, especially at 2 AM on a Friday. Instead of waiting for your senior developer to destroy your pull request, why not build a local AI agent to roast your code right in your terminal?
Today, we are building roast-me, a tiny Python CLI that reads a file and uses an LLM to give you brutally honest feedback.
🛠️ The Stack
Python 3 (No heavy frameworks, just standard libraries)
Any LLM API (We'll use OpenAI's format, but you can swap the base URL to use local models via Ollama or LM Studio for a free alternative).
Step 1: The Python Script (roast.py)
Create a new file called roast.py and drop in this code. The magic here is entirely in the System Prompt.
import sys
import os
import requests
# Set your API key in your terminal: export OPENAI_API_KEY="your-key"
API_KEY = os.getenv("OPENAI_API_KEY")
API_URL = "https://api.openai.com/v1/chat/completions"
def roast_code(file_path):
try:
with open(file_path, 'r') as file:
code = file.read()
except FileNotFoundError:
return "Bro, the file doesn't even exist. -10 points for Gryffindor."
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# The Secret Sauce: The System Prompt
system_prompt = """
You are a cynical, elite senior software engineer.
Your job is to review the code provided by the user and ROAST it mercilessly.
Be sarcastic, point out bad variable names, inefficient loops, and lack of comments.
After thoroughly roasting them, provide 1 actual good piece of advice to fix it.
Keep it under 150 words.
"""
payload = {
"model": "gpt-4o-mini", # Cheap and fast
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": f"Roast this code:\n\n{code}"}
]
}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
print("\n🔥 THE ROAST 🔥\n")
print(response.json()['choices'][0]['message']['content'])
print("\n")
else:
print(f"Error: {response.status_code} - Even the AI refused to look at this.")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python roast.py <file_to_roast>")
else:
roast_code(sys.argv[1])Step 2: Make it Global (The Dev Way)
Nobody wants to type python /path/to/roast.py index.js every time. Let's make it a native terminal command.
Open your ~/.bashrc or ~/.zshrc file and add this alias:
alias roast-me='python3 ~/path/to/your/folder/roast.py'Run source ~/.zshrc (or .bashrc) to apply the changes.
Step 3: Test your ego
Create a terrible file, like bad_code.js, with an awful nested loop or meaningless variable names (let a = 1;). Then, run your new command:
roast-me bad_code.jsThe Result: You now have a personalized, sarcastic AI mentor living in your terminal.
