Skip to content

Repository files navigation

Ghostwrite

AI that assists. You that writes.
Inline code completion powered by Claude, GPT-4o, and Gemini—for developers who want LLM intelligence without giving up the keyboard.

LicensePhilosophyNo Agents

Quick StartFeaturesConfigurationHow It WorksPrivacy & Cost


Why Ghostwrite?

AI coding tools have a philosophy problem.

Most assume you want to write less code. They optimize for delegation—agents that scaffold entire features, chat interfaces that generate files wholesale, autonomous systems that treat your codebase as a problem to be solved without you.

That's useful sometimes. But it's not the only way to work.

Ghostwrite is for developers who still want to write code.

If you find value in staying close to your logic. If you think better when your hands are on the keyboard. If you've noticed that "just let the AI do it" often means "now debug what the AI did"—Ghostwrite was built for how you work.

What makes it different

Inline only. No chat panels. No autonomous agents. No context-switching. Completions appear where you're typing, when you're ready for them.

Bidirectional context. Most tools only see what's above your cursor. Ghostwrite analyzes code before and after—so completions fit the shape of what you're building, not just what you've built.

functionprocessUser(user: User){// Ghostwrite sees this context above ↑|// ← Your cursor is here// AND this context below ↓returnenrichedUser;}

Smart boundaries. Completions stop at logical endpoints. No runaway generation that overshoots your intent and leaves you cleaning up.

Your choice of model. Claude, GPT-4o, or Gemini. Use what works for your context and budget. Switch anytime.

Full control. Configure token limits, context windows, trigger delays, and debounce timing. The tool adapts to you, not the reverse.

Who this is for

  • Engineers who want assistance, not automation
  • Developers who've felt alienated by "vibe coding" culture
  • Teams that value code comprehension alongside velocity
  • Anyone who's tired of tools that assume they want to write less code

Who this is not for

  • If you want AI to write entire features autonomously
  • If you prefer chat-based code generation
  • If you're optimizing purely for lines-of-code-per-hour

We'd rather be honest: those workflows are valid, but they're not what Ghostwrite is designed for.

Technical differentiators

CapabilityGhostwriteAgentic Tools
PhilosophyYou write the codeAI writes for you
InterfaceInline completionsChat panels, autonomous agents
Context AnalysisBidirectional (before + after cursor)Varies
Completion BoundariesSmart (stops at logical endpoints)Often overshoots
ModelYour choice (Claude, GPT-4o, Gemini)Usually locked
ConfigurationFull control (tokens, context, timing)Limited
Secret DetectionBuilt-in (blocks credentials in context)Rarely included

Quick Start

1. Choose Your Provider

Ghostwrite supports three AI providers. Pick one and get an API key:

ProviderSign UpEnvironment Variable
Anthropic (default)console.anthropic.comANTHROPIC_AUTH_TOKEN
OpenAIplatform.openai.comOPENAI_API_KEY
Google Geminiaistudio.google.comGEMINI_API_KEY

2. Set Environment Variables

# Add to your shell profile (~/.zshrc, ~/.bashrc, etc.)# Option A: Anthropic (default)export ANTHROPIC_AUTH_TOKEN="sk-ant-..."# Option B: OpenAIexport GHOSTWRITE_PROVIDER="openai"export OPENAI_API_KEY="sk-..."# Option C: Geminiexport GHOSTWRITE_PROVIDER="gemini"export GEMINI_API_KEY="..."

Restart your terminal or run source ~/.zshrc.

3. Install Ghostwrite

Clone and install locally:

git clone https://github.com/ghostwrite-ai/ghostwrite.git
cd ghostwrite
npm install
npm run package

Then install the generated .vsix file: Extensions > ... > Install from VSIX

4. Start Coding

Open any file and start typing. Completions appear automatically after a brief pause.

That's it. Press Tab to accept, Escape to dismiss.


Features

Bidirectional Context

Ghostwrite analyzes code before and after your cursor position. This means suggestions understand:

  • The function you're implementing
  • The return type you need to satisfy
  • Variables already declared below
  • Patterns used throughout the file

Smart Boundary Detection

Completions stop at natural code boundaries:

  • End of statements (;, ,)
  • Closing braces (}, ), ])
  • Logical break points

No more accepting a suggestion only to delete half of it.

Streaming Completions

See suggestions as they generate. Accept early if the first part is what you need, or wait for the complete suggestion.

Built-in Secret Detection

Ghostwrite automatically blocks completions when it detects potential secrets in your context:

  • API keys (AWS, GitHub, Stripe, Anthropic, OpenAI)
  • Passwords and auth tokens
  • Private keys
  • Database connection strings

The status bar shows a shield icon when secrets are detected.

Intelligent Request Management

  • Debouncing: Waits for you to pause typing before requesting
  • Caching: Reuses valid completions as you type forward
  • Cancellation: Aborts in-flight requests when you keep typing
  • Retry Logic: Automatically retries on transient failures

Configuration

Access settings via Preferences > Settings > Ghostwrite or add to settings.json:

{
"ghostwrite.enabled": true,
"ghostwrite.maxTokens": 256,
"ghostwrite.debounceMs": 300,
"ghostwrite.contextLines": 100,
"ghostwrite.secretDetection": true,
"ghostwrite.timeoutMs": 30000
}

Settings Reference

SettingDefaultRangeDescription
enabledtrueEnable/disable completions globally
maxTokens25632–1024Maximum tokens per completion
debounceMs30050–2000Delay before triggering (ms)
contextLines10010–500Lines of context in each direction
secretDetectiontrueBlock when secrets detected
timeoutMs300005000–120000Request timeout (ms)

Tuning Recommendations

For faster suggestions: Lower debounceMs to 150-200 (increases API calls)

For longer completions: Increase maxTokens to 512 (increases cost)

For large files: Increase contextLines to 200 (increases cost, improves context)

For cost control: Lower maxTokens to 128 and contextLines to 50


Commands

CommandDescriptionDefault Keybinding
Ghostwrite: Toggle On/OffEnable/disable completions

Access via Command Palette (Cmd/Ctrl+Shift+P).


Status Bar

The status bar indicator shows Ghostwrite's current state:

IconStateMeaning
👻ReadyWaiting for input
LoadingGenerating completion
DisabledExtension is off
⚠️ErrorAuth, quota, or network issue
🛡️BlockedSecrets detected in context

Click the status bar to toggle Ghostwrite on/off.


How It Works

┌─────────────────────────────────────────────────────────────────┐
│ Your Editor │
├─────────────────────────────────────────────────────────────────┤
│ ... code above cursor (up to 100 lines) ... │
│ │
│ function example() { │
│ const data = | ← cursor position │
│ return processed; │
│ } │
│ │
│ ... code below cursor (up to 100 lines) ... │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Ghostwrite Extension │
├─────────────────────────────────────────────────────────────────┤
│ 1. Extract bidirectional context │
│ 2. Scan for secrets (block if found) │
│ 3. Build prompt with language + filename │
│ 4. Stream completion from your chosen provider │
│ 5. Stop at logical boundary │
│ 6. Present as inline suggestion │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ AI Provider (your choice) │
├─────────────────────────────────────────────────────────────────┤
│ • Claude Opus 4.5 (Anthropic) │
│ • GPT-4o (OpenAI) │
│ • Gemini 1.5 Pro (Google) │
└─────────────────────────────────────────────────────────────────┘

Privacy & Cost

What Data Is Sent

When generating completions, Ghostwrite sends to your chosen provider's API:

  • Code before your cursor (configurable, default 100 lines)
  • Code after your cursor (configurable, default 100 lines)
  • File language and name
  • Your system username (for rate limiting, Anthropic only)

No code is stored locally beyond the current session. See your provider's privacy policy for server-side handling:

Secret Detection

Enabled by default, Ghostwrite scans context for:

  • AWS access keys and secrets
  • GitHub tokens (PAT, OAuth)
  • Stripe API keys
  • Private keys (RSA, DSA, EC)
  • Database connection strings
  • Generic API keys and passwords

When detected, completions are blocked and the status bar shows 🛡️.

API Costs

All providers charge based on token usage. Costs vary by provider:

ProviderModelApprox. Cost per 1K tokens
AnthropicClaude Opus 4.5~$0.015 input, ~$0.075 output
OpenAIGPT-4o~$0.005 input, ~$0.015 output
GoogleGemini 1.5 Pro~$0.00125 input, ~$0.005 output

Monitor usage: Check your provider's dashboard.

Control costs: Reduce maxTokens and contextLines settings.


Environment Variables

Provider Selection

VariableDefaultDescription
GHOSTWRITE_PROVIDERanthropicProvider to use: anthropic, openai, or gemini

Anthropic

VariableRequiredDescription
ANTHROPIC_AUTH_TOKENYes*Anthropic API key
ANTHROPIC_BASE_URLNoCustom API endpoint (proxies, enterprise)
ANTHROPIC_MODELNoModel override (default: claude-opus-4-5-20251101)

OpenAI

VariableRequiredDescription
OPENAI_API_KEYYes*OpenAI API key
OPENAI_BASE_URLNoCustom API endpoint (Azure, proxies)
OPENAI_ORGANIZATIONNoOrganization ID for multi-org accounts
OPENAI_MODELNoModel override (default: gpt-4o)

Gemini

VariableRequiredDescription
GEMINI_API_KEYYes*Google AI API key
GEMINI_MODELNoModel override (default: gemini-1.5-pro)

*Required only when using that provider.


Troubleshooting

"Invalid API Key" Error

  1. Verify your API key is set for your provider:
    • Anthropic: echo $ANTHROPIC_AUTH_TOKEN
    • OpenAI: echo $OPENAI_API_KEY
    • Gemini: echo $GEMINI_API_KEY
  2. Check the key is valid at your provider's dashboard
  3. Restart VS Code after setting the variable

"Unknown Provider" Error

Ensure GHOSTWRITE_PROVIDER is set to one of: anthropic, openai, or gemini (case-insensitive).

No Completions Appearing

  1. Check status bar — is Ghostwrite enabled?
  2. Type some code and pause (completions need a trigger delay)
  3. Check Output panel (View > Output > Ghostwrite) for errors

Completions Are Slow

  1. Reduce contextLines to 50
  2. Reduce maxTokens to 128
  3. Check your network connection

"Secrets Detected" Blocking

If you're working with test credentials or examples:

  1. Disable temporarily: "ghostwrite.secretDetection": false
  2. Move secrets to environment variables
  3. Use .env.example with placeholder values

Architecture

src/
├── extension.ts # VS Code extension entry point
├── completionProvider.ts # Inline completion logic
├── contextBuilder.ts # Bidirectional context extraction
├── secretDetector.ts # Credential scanning
├── errorHandler.ts # Error classification & retry logic
├── requestManager.ts # Debouncing & request lifecycle
├── statusBar.ts # Status indicator management
├── types.ts # TypeScript interfaces
└── providers/
├── types.ts # Provider interfaces & config types
├── anthropicAdapter.ts # Anthropic SDK adapter
├── openaiAdapter.ts # OpenAI SDK adapter
├── geminiAdapter.ts # Gemini SDK adapter
├── configParser.ts # Environment config parsing
└── providerFactory.ts # Provider instantiation

Built with:

  • TypeScript — Full type safety, zero any, no type assertions
  • neverthrow — Type-safe error handling with Result<T, E>
  • Adapter pattern — Provider-agnostic streaming interface
  • Functional patterns — Immutable data, pure functions, discriminated unions

Development

# Clone the repository
git clone https://github.com/ghostwrite-ai/ghostwrite.git
cd ghostwrite
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch mode for development
npm run watch
# Package for distribution
npm run package

Running Locally

  1. Open the project in VS Code
  2. Press F5 to launch Extension Development Host
  3. Test completions in the new VS Code window

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Run npm run compile to verify
  5. Commit: git commit -m 'Add amazing feature'
  6. Push: git push origin feature/amazing-feature
  7. Open a Pull Request

License

MIT — Use freely, attribution appreciated.


Built for developers who still want to write code.
Report BugRequest Feature

About

Your code's invisible collaborator. Inline completions powered by your favorite models.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages