Skip to content

Ghost-text next-prompt suggestion in the composer (Tab to prefill, Enter to send) #1166

Open

Description

@web3wannabe

Feature Description

After a turn finishes, show a one-line suggestion of the most likely next prompt as dimmed ghost text in an empty composer. Tab prefills it (editable), Enter sends it, Esc or typing anything dismisses it.

Implementation notes:

  • At most one small/cheap model call per completed turn, only when the composer is empty and the session is idle — not per keystroke.
  • Never written into the buffer before Tab is pressed; the buffer stays empty until then.
  • Visible inline hint ("Tab to prefill · Enter to send") so the affordance is discoverable rather than a mystery box.
  • Skipped in plan mode, after an interrupted run, and when the last turn ended with an error.
  • Opt-in via a setting (e.g. suggestNextPrompt: false) and never shown headless.

Use Case

Every turn ends with the user deciding "what next", and both major competing harnesses ship exactly this, at the same cost model — one cheap call per turn:

  • Claude Code: "After a task finishes, Claude will occasionally show a followup suggestion in ghost text. Press Enter to send it or Tab to prefill your next prompt."
  • Oh My Pi (github.com/can1357/oh-my-pi): a dedicated predictor — crates/predict/ with ngram, apple and smollm backends, rendered by packages/tui/src/prompt/word-completion.ts.

It removes a full stop from every single turn, which is where most of the interaction time goes.

Additional Context

This already existed in Command Code and was rolled back — changelog 0.17.4: "revert: dynamic Haiku-predicted placeholder in input field (#509) (#614)". So the plumbing is largely there; the ask is to bring it back as an opt-in rather than default-on, which also addresses whatever cost or latency drove the revert.

A narrower variant still ships today: a ghost suggestion after /pr-comments that prefills "Fix all review comments" — same rendering, one hardcoded case.

One pitfall to avoid, seen upstream: when the suggestion appears with no visible Tab hint, users don't know it is acceptable (anthropics/claude-code#76591). Hence the inline hint above.

Priority: Important for my workflow.

Activity

  1. web3wannabe commented on Nov 20, 2026

    @web3wannabe
    Author

    Working prototype (no product changes)

    I built this as a user-space mod against the current public ModApi — it loads today with cmd --mod ./next-prompt.ts. cmd mods inspect reports: hooks: transformInput, onRunEnd, registers: slash command, widget.

    It covers the whole feature except the Tab key: onRunEnd → one cmd.model.complete (24 output tokens max, 5 s minimum gap, skipped on interrupted / max_turns / terminate / permission_denied and headless) → the line renders in an above-editor widget → Accept is a one-key button (hotkey: 'a') or /next.

    import type { ModApi } from '@commandcode/harness';
    
    const KNOBS = {
      maxOutputTokens: 24,
      minGapMs: 5_000,
      userChars: 300,
      assistantChars: 600,
      maxSuggestionChars: 140,
      hardStops: new Set(['interrupted', 'max_turns', 'terminate', 'permission_denied']),
    };
    
    const SYSTEM = [
      'You predict the next message the user will send to a coding agent.',
      'Reply with ONE imperative line, at most 12 words, no quotes, no preamble, no trailing period.',
      'Reply exactly NONE when the next step is not obvious.',
    ].join(' ');
    
    function text_of(content: unknown): string {
      if (typeof content === 'string') return content;
      if (Array.isArray(content)) {
        return content
          .map((part) =>
            typeof part === 'string'
              ? part
              : typeof part === 'object' && part !== null && 'text' in part
                ? String((part as { text?: unknown }).text ?? '')
                : '',
          )
          .join(' ');
      }
      return '';
    }
    
    function build_context(state: unknown): string | null {
      const messages = ((state as { messages?: { role?: string; content?: unknown }[] } | undefined)?.messages ?? []);
      let user = '';
      for (let i = messages.length - 1; i >= 0; i--) {
        if (messages[i]?.role === 'user') {
          user = text_of(messages[i].content).slice(0, KNOBS.userChars);
          break;
        }
      }
      if (!user) return null;
      let assistant = '';
      for (let i = messages.length - 1; i >= 0; i--) {
        if (messages[i]?.role === 'assistant') {
          assistant = text_of(messages[i].content).slice(-KNOBS.assistantChars);
          break;
        }
      }
      return `Previous user message:\n${user}\n\nLast assistant reply (tail):\n${assistant}`;
    }
    
    function clean(raw: string): string | null {
      const line = raw.split('\n').map((l) => l.trim()).filter(Boolean)[0];
      if (!line) return null;
      const text = line
        .replace(/^[-*•]\s*/, '')
        .replace(/^["'`]+|["'`]+$/g, '')
        .replace(/\.$/, '')
        .trim();
      if (!text || /^none$/i.test(text)) return null;
      if (text.length > KNOBS.maxSuggestionChars) return null;
      return text;
    }
    
    export default function mod(cmd: ModApi) {
      let pending: { text: string } | null = null;
      let inflight = false;
      let last_at = 0;
    
      cmd.hooks({
        onRunEnd: async ({ state, result }) => {
          if (inflight || !cmd.ui.capabilities.status) return;
          if (KNOBS.hardStops.has(String((result as { stopReason?: unknown })?.stopReason ?? ''))) return;
          if (Date.now() - last_at < KNOBS.minGapMs) return;
          const ctx = build_context(state);
          if (!ctx) return;
          inflight = true;
          try {
            const r = await cmd.model.complete({ system: SYSTEM, prompt: ctx, maxOutputTokens: KNOBS.maxOutputTokens });
            last_at = Date.now();
            const text = r.isAnswered ? clean(r.text) : null;
            pending = text ? { text } : null;
            cmd.ui.refreshWidgets();
          } catch {
            pending = null;
          } finally {
            inflight = false;
          }
        },
        transformInput: () => {
          pending = null;
          cmd.ui.refreshWidgets();
          return { action: 'continue' };
        },
      });
    
      cmd.ui.widget({
        placement: 'above-editor',
        render: () => {
          if (!pending) return [];
          return [
            { type: 'text', text: `↹ ${pending.text}`, dim: true },
            {
              type: 'button',
              label: 'Accept',
              hotkey: 'a',
              onPress: () => {
                const text = pending?.text;
                pending = null;
                cmd.ui.refreshWidgets();
                if (text) cmd.prompt.submit(text);
              },
            },
          ];
        },
      });
    
      cmd.addCommand({
        name: 'next',
        description: 'Send the suggested next prompt',
        handler: () => {
          if (!pending) return { message: 'no suggestion yet' };
          const text = pending.text;
          pending = null;
          return { prompt: text };
        },
      });
    }

    What the real Tab UX needs (small host delta)

    Three changes, in order of value:

    1. cmd.prompt.prefill(text) — write text into the composer without submitting. The textarea state and cursor already exist in the host; this is the only genuinely missing primitive.
    2. A ghost slot inside the composer — draw the pending line dimmed after the cursor when the buffer is empty, instead of a band above the input.
    3. Tab arbitration — when the composer is empty and a ghost is present, Tab prefills instead of cycling pane focus. This is the single product decision in the whole feature; everything else is plumbing.

    With those three, the mod above loses its button and /next and becomes exactly the Claude Code interaction.

    Cost and kill criteria

    • One completion per run, 24 output tokens, skipped on hard stops, minimum 5 s apart, opt-out setting.
    • Instrument accept rate (accepted / shown) and cost per session.
    • If accept rate stays under ~15% the feature is not earning its keep — turn it off.
  2. vipulgupta2048 commented on Nov 23, 2026

    @vipulgupta2048
    Member

    @web3wannabe thanks for the feature request. This is on the roadmap. Let me create a PR to get this going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions