Skip to content

Mod API: cmd.prompt.submit('/clear') is not reliable; add cmd.sessions.clear() #1182

Backlog

Description

@davidlosasgonzalez

cmd.prompt.submit('/clear') is not reliable from a mod; add cmd.sessions.clear()

Environment

  • Command Code 1.93.4, macOS 27.2.1 (darwin, arm64), Node v24.13.0.
  • Interactive TUI in tmux; a project mod at .commandcode/mods/context-cut.ts.
  • Model: deepseek/deepseek-v4.1-flash.

What I am building
A mod that, at 50% of the context and with no helper process alive, asks the model to write a handoff
and then clears the session so the next conversation starts from the handoff (the SessionStart hook
injects it). Everything is programmatic: no keyboard.

The problem
cmd.prompt.submit('/clear') does not always execute the built-in /clear:

  1. In one isolated probe (a mod with only cmd.clock.after(8000, () => cmd.prompt.submit('/clear')),
    session idle) it cleared: the SessionStart hook logged source=clear.
  2. In the same situation inside a fuller mod, the text /clear was submitted as a normal prompt:
    the model ran a turn and no source=clear appeared.
  3. In a third run it was a no-op: no clear and no new turn.

There is no cmd.sessions.clear(); cmd.sessions exposes only compact, tree, leafId,
navigateTree and setLabel.

Minimal reproduction
A mod with:

export default function (cmd: ModApi) {
  cmd.clock.after(8000, () => {
    if (!cmd.isIdle()) return;
    cmd.prompt.submit('/clear');
  });
}

Run an interactive session in tmux, let the first turn finish, and wait. Observed: sometimes the
session clears, sometimes a normal turn starts with /clear as its text, sometimes nothing happens.

What would fix it

  1. cmd.sessions.clear(): a programmatic, atomic session clear that never becomes a user prompt and
    is gated on the session being idle.
  2. A confirmation event/callback with the old and new session ids, so a mod can prove the clear
    happened (and not just read a shared log line written by another instance).
  3. Documented guarantees for cmd.store (persistence and atomicity across /clear) and for mod
    timers (are they kept or cancelled after the session switch?).
  4. If (1) is not possible, make cmd.prompt.submit('/clear') always execute the built-in command
    instead of sometimes turning it into a prompt.

Why it matters
Without a reliable clear, any automated handoff-and-clear must fall back to typing keystrokes into
the TUI, which cannot atomically exclude a draft or a concurrent message. The mod API is the only
seam that can do this safely.

Activity

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