Skip to content

feat(print): dispatch leading slash lines in -p / non-interactive mode#112

Merged
paultyng merged 1 commit into
mainfrom
feat/print-leading-slash-dispatch
Jun 2, 2026
Merged

feat(print): dispatch leading slash lines in -p / non-interactive mode#112
paultyng merged 1 commit into
mainfrom
feat/print-leading-slash-dispatch

Conversation

@paultyng
Copy link
Copy Markdown
Owner

@paultyng paultyng commented Jun 2, 2026

Summary

  • claude -p, codex exec, and cursor agent --print now dispatch leading /-prefixed lines through the slash handler instead of treating them as opaque prompt text.
  • The walk stops at the first non-slash line; that line plus everything after it becomes the prompt that gets echoed.
  • /think and /stream are terminal: their parsed message is the prompt and their duration is slept before the echo, so orchestrators can use them as a sleep / pacing primitive in -p mode.

Diverges from real claude --print, which sends /help to the model as literal text. Documented in COMPATIBILITY.md.

Test plan

  • go test ./... passes
  • go vet clean
  • gofmt -l clean on files touched by this PR
  • Smoke: testagent claude -p "/panel hi" renders panel and exits 0
  • Smoke: testagent claude -p "/exit 7" exits 7
  • Smoke: time testagent claude -p "/think 1s hi" ≈ 1.01s
  • Smoke: testagent claude -p $'/panel one\n/panel two\nreal prompt' renders both panels then echoes [test-agent] real prompt
  • Smoke: testagent codex exec "/exit 3" exits 3
  • Smoke: testagent cursor --print "/panel hi" renders panel

🤖 Generated with Claude Code

Walk the prompt line by line in the print / codex-exec paths; route each
leading line that starts with "/" through the slash handler, stopping at
the first non-slash line. The remainder is the prompt that gets echoed.
/think and /stream are terminal: their parsed message is the prompt and
their durations are slept before the echo, giving orchestrators a
generic pacing mechanism in non-interactive mode (where the engine's
per-turn timing is otherwise unavailable).

Diverges from real claude --print, which sends "/help" to the model as
literal text. The divergence is intentional and documented in
COMPATIBILITY.md — testagent is a fake driven by orchestrator scripts,
not a model proxy.

Shared slash.Handler.PrePromptDispatch does the walk; each vendor wires
it into its print/exec entry point with vendor-appropriate teardown
(claude: Stop + SessionEnd + MCP close; codex: Stop only, ExitError on
non-zero /exit; cursor: same as claude on a background context).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@paultyng paultyng marked this pull request as ready for review June 2, 2026 22:41
@paultyng paultyng enabled auto-merge (squash) June 2, 2026 22:41
@paultyng paultyng merged commit 427c316 into main Jun 2, 2026
4 checks passed
@paultyng paultyng deleted the feat/print-leading-slash-dispatch branch June 2, 2026 22:42
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