Inline suggestions for AI chat composers.
Ghost Text shows people the rest of their message as they type, and the next one after a reply. Tab takes it. Open source, for any textarea and any model.
Try it: click the message box, then press Tab. Try it: tap the message box, then tap the suggestion.
Wrap your textarea.
Your textarea stays yours: its value, caret, undo and styles. Ghost Text draws over it and listens to keys.
import { useGhostText } from '@ghosttext/react';
const { ghostTextRef } = useGhostText({ source, messages });
<textarea
ref={ghostTextRef}
value={value}
onChange={event => setValue(event.target.value)}
/>
Not using React? ghostText(textarea, options) does the
same.
Bring any model.
A source is a function from what is typed to suggestions. Combine them. The first one with an answer wins.
import { cascade, endpoint, history } from '@ghosttext/core';
import { chromeAI } from '@ghosttext/chrome-ai';
const source = cascade(
history(),
chromeAI(),
endpoint({ url: '/api/ghost-text' })
);
- History
- Messages they sent before. Instant, local, no model.
- Chrome AI
- Gemini Nano on the device. Free, private, offline.
- Your model
- Any OpenAI-compatible API, behind your endpoint. The key stays on your server.
Plugins see every step. Skip slash commands, filter links, count what gets accepted.
const commands = definePlugin({
name: 'commands',
onContext: context => !context.before.startsWith('/') && context,
onAccept: ({ suggestion }) => track('accept', suggestion.source),
});
The hard parts are done.
- Native editing. An accept is one undo step and a real input event.
- Every keyboard. IME composition, right-to-left text, word by word.
- Touch. Tap the suggestion to take it.
- Screen readers. Each suggestion is announced once, without interrupting.
- Never stale. A slow answer never replaces a newer one.
- Light. About 10 kB with React. No dependencies.
Ready for your coding agent.
Point your agent at the docs and it can add Ghost Text for you.
-
llms.txtandllms-full.txtdescribe the library in plain text. - An agent skill teaches the steps and the pitfalls.
- A shadcn component, one command away: