Skip to content

ryannono/Ghostwrite

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.

License Philosophy No 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.

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

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

Capability Ghostwrite Agentic Tools
Philosophy You write the code AI writes for you
Interface Inline completions Chat panels, autonomous agents
Context Analysis Bidirectional (before + after cursor) Varies
Completion Boundaries Smart (stops at logical endpoints) Often overshoots
Model Your choice (Claude, GPT-4o, Gemini) Usually locked
Configuration Full control (tokens, context, timing) Limited
Secret Detection Built-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:

Provider Sign Up Environment Variable
Anthropic (default) console.anthropic.com ANTHROPIC_AUTH_TOKEN
OpenAI platform.openai.com OPENAI_API_KEY
Google Gemini aistudio.google.com GEMINI_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: OpenAI
export GHOSTWRITE_PROVIDER="openai"
export OPENAI_API_KEY="sk-..."

# Option C: Gemini
export 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

Setting Default Range Description
enabled true Enable/disable completions globally
maxTokens 256 32–1024 Maximum tokens per completion
debounceMs 300 50–2000 Delay before triggering (ms)
contextLines 100 10–500 Lines of context in each direction
secretDetection true Block when secrets detected
timeoutMs 30000 5000–120000 Request 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

Command Description Default Keybinding
Ghostwrite: Toggle On/Off Enable/disable completions

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


Status Bar

The status bar indicator shows Ghostwrite's current state:

Icon State Meaning
👻 Ready Waiting for input
Loading Generating completion
Disabled Extension is off
⚠️ Error Auth, quota, or network issue
🛡️ Blocked Secrets 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:

Provider Model Approx. Cost per 1K tokens
Anthropic Claude Opus 4.5 ~$0.015 input, ~$0.075 output
OpenAI GPT-4o ~$0.005 input, ~$0.015 output
Google Gemini 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

Variable Default Description
GHOSTWRITE_PROVIDER anthropic Provider to use: anthropic, openai, or gemini

Anthropic

Variable Required Description
ANTHROPIC_AUTH_TOKEN Yes* Anthropic API key
ANTHROPIC_BASE_URL No Custom API endpoint (proxies, enterprise)
ANTHROPIC_MODEL No Model override (default: claude-opus-4-5-20251101)

OpenAI

Variable Required Description
OPENAI_API_KEY Yes* OpenAI API key
OPENAI_BASE_URL No Custom API endpoint (Azure, proxies)
OPENAI_ORGANIZATION No Organization ID for multi-org accounts
OPENAI_MODEL No Model override (default: gpt-4o)

Gemini

Variable Required Description
GEMINI_API_KEY Yes* Google AI API key
GEMINI_MODEL No Model 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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published