Skip to content

feat: --interactive mode (drive interactive session for subscription pricing)#2

Merged
kurok merged 1 commit into
mainfrom
feat/interactive-mode
Jun 9, 2026
Merged

feat: --interactive mode (drive interactive session for subscription pricing)#2
kurok merged 1 commit into
mainfrom
feat/interactive-mode

Conversation

@kurok

@kurok kurok commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Why

Claude Code prices -p/headless usage separately from interactive sessions (new pricing from Jun 15). This adds --interactive, which drives the interactive session programmatically so scripted/batch calls stay on the Claude subscription.

How

  • claudecmd/interactive_runner.py — spawns the interactive TUI under a PTY (pexpect), renders it with a real terminal emulator (pyte) so spacing/layout survive, auto-answers the one-time workspace-trust dialog, detects turn completion via a quiet period, and extracts the assistant reply from the rendered screen.
  • cli.py--interactive and --tools flags; text / --json ("mode":"interactive") / --raw (full rendered screen) outputs. Positional prompt is placed first in argv so variadic options can't swallow it.
  • setup.cfg — new interactive extra (pexpect+pyte).
  • tests — extractor, argv builder, and a fully-mocked run_interactive drive (trust → reply → complete). Full suite: 101 passing.
  • README — Interactive mode section + caveats.

Verified live

claudecmd --interactive --json --model haiku --tools "" "...PONG"
{"ok": true, "result": "PONG", ..., "mode": "interactive"} in ~6.8s.

Caveats (documented)

Screen-scrapes a human-facing TUI, so it's inherently less robust than -p: no session-id/cost metadata, heuristic completion detection, tool-permission prompts must be avoided (--tools ""), extraction tuned to Claude Code v2.1.x.

Add an --interactive mode that runs Claude Code's interactive session under a
pseudo-terminal instead of 'claude -p', so scripted calls stay on the Claude
subscription rather than separately-priced -p/headless usage.

- new claudecmd/interactive_runner.py: pexpect spawn + pyte terminal emulator,
  auto-answers the workspace-trust dialog, quiet-period completion detection,
  and heuristic extraction of the assistant reply from the rendered screen
- cli.py: --interactive and --tools flags; text/--json/--raw output paths
- prompt placed first in argv so variadic options (--tools/--add-dir) can't
  swallow it; --tools kept last
- setup.cfg: new 'interactive' extra (pexpect + pyte); added to dev
- tests: extractor, argv builder, and a fully-mocked run_interactive drive
- README: Interactive mode section, flags, install extra, caveats

Signed-off-by: kurok <22548029+kurok@users.noreply.github.com>
@kurok kurok merged commit ebf0c63 into main Jun 9, 2026
1 check passed
@kurok kurok deleted the feat/interactive-mode branch June 9, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant