feat: --interactive mode (drive interactive session for subscription pricing)#2
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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—--interactiveand--toolsflags; 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— newinteractiveextra (pexpect+pyte).run_interactivedrive (trust → reply → complete). Full suite: 101 passing.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.