Ghostwriter AI Intermediate
Ghostwriter is Replit's built-in AI coding assistant. It provides intelligent code completion, generates entire functions from comments, transforms existing code, explains complex logic, and helps debug errors — all directly in the editor.
What is Ghostwriter?
Ghostwriter is an AI pair programmer integrated into the Replit editor. It uses large language models trained on code to understand your intent and generate relevant suggestions. Unlike standalone AI tools, Ghostwriter has full context of your project files and running environment.
Code Completion
Ghostwriter provides real-time code suggestions as you type. It predicts what you are about to write and offers inline completions:
# Type a function signature and Ghostwriter completes the body def calculate_fibonacci(n): # Ghostwriter suggests: if n <= 1: return n return calculate_fibonacci(n - 1) + calculate_fibonacci(n - 2)
To use completions:
- Tab — Accept the current suggestion
- Escape — Dismiss the suggestion
- Alt+] — Cycle through alternative suggestions
Code Generation
Write a comment describing what you want, and Ghostwriter generates the code:
// Create an Express server with a GET /api/users endpoint // that returns a JSON array of users from a database const express = require('express'); const app = express(); app.get('/api/users', async (req, res) => { try { const users = await db.query('SELECT * FROM users'); res.json(users); } catch (error) { res.status(500).json({ error: error.message }); } });
Ghostwriter Chat
Open the Ghostwriter Chat panel to have a conversation with the AI about your code. It can:
| Action | Example Prompt | Result |
|---|---|---|
| Explain code | "Explain what this function does" | Detailed explanation of selected code |
| Generate code | "Write a function to validate email addresses" | Complete function with validation logic |
| Debug errors | "Why am I getting a TypeError here?" | Error analysis and suggested fix |
| Refactor | "Refactor this to use async/await instead of callbacks" | Modernized code with same functionality |
| Write tests | "Write unit tests for the UserService class" | Test file with comprehensive test cases |
Code Transformation
Select code and use Ghostwriter to transform it. Highlight a block of code, then use the Ghostwriter menu to:
- Explain Code: Get a plain-English explanation of what the selected code does
- Generate Code: Replace the selection with AI-generated code based on a prompt
- Transform Code: Convert code between styles (e.g., class-based to functional)
- Fix Bugs: Let Ghostwriter identify and fix bugs in the selection
Try It Yourself
Create a new Python Repl and try these Ghostwriter features: (1) Type a comment describing a function and let Ghostwriter generate it, (2) Open Ghostwriter Chat and ask it to explain the generated code, (3) Select the code and ask Ghostwriter to add error handling.
Lilly Tech Systems