feat(commands): /dryrun — preview the next chat completion request without sending it
Problem
When iterating on a long DeepSeek V4 Pro turn — long system prompt, many cached repo files, tool definitions, attached @mentions, multi-step thinking — the developer cannot see what is actually about to be sent without sending it.
For V4 Pro users this has a concrete, recurring cost:
- Thinking tokens are billed and a single bad turn can be expensive.
- The 1M context window means accidental prompt bloat is silent
until
/tokensshows it after the fact. - Tool schemas, system prompt, skill packs, and
reasoning_contentreplay (#939) all silently inflate the request input. Today the only way to know how big the next request is, is to send it. - Strict tool mode (#938) and provider/model differences make small request-shape regressions hard to spot from the transcript.
Proposed solution
A new read-only slash command, /dryrun (alias /preview-request),
that renders exactly what the next chat completion request would
look like without sending it.
Two output modes:
/dryrun— one-screen summary:- active provider + base URL (with
/v1vs/betaresolved), - active model + reasoning effort,
- message count broken down by role (system / user / assistant /
tool) and a note if
reasoning_contentreplay would be attached on assistant tool-call messages, - system prompt size in chars / approx tokens,
- tool count + total tool-schema approx tokens,
- composer-draft size if non-empty,
- estimated total input tokens via the existing
crate::compaction::estimate_tokenshelper, and a footer line explicitly labeling it as an approximation.
- active provider + base URL (with
/dryrun --full— the full JSON body that would be POSTed, pretty-printed, with:Authorization/ API-key headers redacted tosk-…<last4>,- tool-result message bodies truncated past N chars with a
[truncated K chars]marker, - any field added later (e.g. strict-tool toggle) automatically included because the body is built from the same struct the engine sends.
/dryrun is read-only: it does not mutate api_messages,
session.*, telemetry, cache history, or the composer. It does
not call the network. It does not record a turn.
Why this is a good fit
- High frequency, V4-Pro-specific value: directly attacks the "I don't know what I'm about to spend" problem that the 1M context window + thinking pricing creates.
- Pure read of in-memory state — outside the telemetry / cost / session-accounting risky surface that PR #967 was closed for.
- Minimal new surface: 1 new command file plus three tiny wirings.
- Composes well with existing
/tokens(post-hoc) and/cost(post-hoc) by giving the missing pre-hoc view.
Scope (single small PR, target 4 files)
Files touched:
-
NEW
crates/tui/src/commands/dryrun.rs(~200 LOC):- Builds a synthetic message list from
app.api_messagesplus a syntheticusermessage fromapp.composer.inputif it is non-empty. - Calls
crate::compaction::estimate_tokensfor the input token estimate (no new estimator). - Formats the summary or the JSON body via
serde_jsonagainst the same outbound message struct the engine already uses. - Redaction helpers + truncation helpers live in this file with unit tests.
- Builds a synthetic message list from
-
crates/tui/src/commands/mod.rs— register the command inpub mod, inCOMMANDS, and in the dispatch match (mirrors/tokens). -
crates/tui/src/localization.rs— add 2 message IDs (CmdDryrunDescription,DryrunFooterApprox) with strings for every shipped locale, following the existing pattern. -
(Only if the existing engine request-build helper is
pub(crate)and not reachable fromcommands/) a tiny visibility bump on that single function, with a comment. No new public crate API.
No change to telemetry, cost, session accounting, cache history,
provider/model switch logic, /clear, or /load.
Alternatives considered
- Extending
/tokenswith a "would-send" mode: rejected —/tokensis post-hoc and overloading it muddies its contract. - Logging the request to a file behind a debug flag: rejected — forces the user to leave the TUI and grep, doesn't help during composition.
- A
--dry-runflag on the engine: rejected — engine surface is the wrong layer for an interactive ergonomic and would be a much larger PR.
Additional context
AI-use disclosure / human-owner statement
This proposal was drafted with AI assistance (GitHub Copilot / Claude). The human owner is @peixl, who reviews each change line-by-line, owns the resulting PR, and is responsible for the test plan and merge.
Test plan for the eventual PR
Unit tests in crates/tui/src/commands/dryrun.rs:
dryrun_summary_includes_model_provider_and_token_estimatedryrun_summary_appends_composer_draft_as_synthetic_user_turndryrun_summary_does_not_mutate_app_state(snapshotapi_messages,session.*,composer.inputbefore and after).dryrun_full_redacts_api_key_to_last4dryrun_full_truncates_long_tool_result_bodiesdryrun_handles_empty_session_without_panic
Workspace gates:
cargo test -p deepseek-tui dryrun_ --lockedcargo test -p deepseek-tui --lockedcargo fmt --all -- --checkcargo clippy -p deepseek-tui --all-targets --all-features --locked -- -D warningsgit diff --check origin/main...HEAD
Manual:
- Start a session with a non-trivial system prompt and one tool
call, type a draft, run
/dryrunand/dryrun --full, confirm numbers and JSON match what the next send produces. - Confirm
/dryrunon a fresh session prints non-zero system prompt size and0for everything else, no panics, no network.
Awaiting maintainer accept
Per the contributor guide and PR #967's closing note, no implementation will be pushed until this issue is accepted by a maintainer. Filing as a proposal first.
This would also be useful as a reusable request-manifest builder for the runtime API, not only as an interactive slash command.
A safe shape could be a redacted manifest rather than the full request body by default:
- resolved provider/base URL category, without secrets
- concrete model and reasoning/thinking setting
- whether auto routing was used, and the final selected route if available
- max_tokens / temperature / top_p when set
- message count by role
- tool schema count and maybe schema hash/refs
- estimated input tokens, clearly labeled as estimated
- request hash for correlation
I would keep raw prompts, raw tool schemas, API keys, and auth headers out of the default manifest. Full JSON preview could stay an explicit /dryrun --full style action.
intereseting idea! I like this a lot
Thanks for the suggestion here. I opened PR #1099 with an implementation:
The PR adds a new /dryrun command for previewing the next Chat Completions request without sending it or recording a turn. It also includes /dryrun --full for an explicit JSON preview, with auth headers redacted and large tool-result bodies bounded so the output stays safe to inspect.
A few details included in the preview:
- resolved provider/base URL and request URL
- model, reasoning, and max token settings
- message counts by role
- thinking replay status
- system prompt, tool schema, and composer draft estimates
- approximate input token totals
I also added /preview-request as an alias.
While validating this on Windows, I fixed two environment-sensitive failures that were blocking clean verification here:
- REPL/code-execution now falls back to a usable Python interpreter instead of getting stuck on the WindowsApps
python3.exestub. - The skills empty-directory test no longer assumes the machine has no globally visible skills.
Validation passed locally:
cargo test --workspace --all-features --lockedcargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo build --locked
This is a well-scoped, low-risk proposal — a read-only command that builds the request body from the same struct the engine sends, with no network/telemetry/session mutation. It also composes nicely with #1747 (diffing two /dryrun --full bodies is the fastest way to find what's busting the prefix cache).
One note for whoever implements it: the engine's request-build path now lives in crates/tui/src/core/engine/ (turn loop) and crates/tui/src/client/chat.rs; the message struct to serialize for --full is the one in chat.rs. The token estimate helper referenced (crate::compaction::estimate_tokens) is still present.
Per the proposal, @peixl is awaiting maintainer acceptance and wants to own the PR line-by-line, so I'm not pre-empting it with an implementation. Recommending acceptance — it's a clean fit for v0.8.51+ and the test plan is already solid. Leaving open for the maintainer go-ahead.
Generated by Claude Code
Moved to the v0.9.3 milestone as part of a v0.9.2 scope pass.
Why: this needs a human at a real terminal — a manual QA matrix or an explicit human decision that no agent can execute. It should not sit on a release milestone as if it were pending engineering.
This is a scheduling call, not a rejection or a downgrade — the issue is unchanged and keeps its labels. v0.9.2 was carrying 61 open issues while its actually-shippable work had landed; leaving items on a release milestone they were never going to make hides what is really left and makes the count useless for deciding when to cut.
Closing as not planned in a v0.9.4 board hygiene pass.
This is an older-milestone epic / design wishlist / exploratory feature that is not on the live execution train. Leaving it open taxes agents the same way stale rebrand tickets did.
If this is still wanted for a current release: open a new narrow issue with acceptance criteria and a milestone that is actually shipping — do not reopen this blob.
Thank you for filing this and for the detail you included — reports like yours are how we find real product gaps.
Sorry for the earlier automated close during board hygiene; that was aimed at old internal design epics, not at community reports. Your issue matters.
Update: we are actively working the v0.9.4 reliability / tools / provider train right now (composer send failures, provider route preflight, File tools, Fleet, and related setup). We are putting this on milestone v0.9.4 so it stays on the live board instead of rotting as needs-info / older-milestone noise.
Thanks for the /dryrun proposal — previewing the next completion request without sending is a great operator tool. Parked on v0.9.4 as a scoped feature rather than a forever-open wishlist.
If you still hit this on a current Codewhale build, a quick note with version (codewhale --version / release tag) and a short repro is hugely helpful — we will treat that as priority signal on this ticket.
Thanks @peixl for the report.
This issue is staying open for maintainer triage. CodeWhale gets better because people bring us real edge cases from real machines, providers, regions, and workflows.
If you can add a reproduction, logs, version output, screenshots, or the provider/model involved, that makes it much easier for us to verify and harvest the fix. Maintainers may comment /lgtmi to mark recurring issue reporters as approved so this intake note is skipped next time.
/dryrun becomes a natural follow-on once request building moves into crates/core — tracked under v0.9.5 #5261. It's a follow-on, not a duplicate; linked and left open.
Shipped as /preview-request with /dryrun and /preview_request aliases in e57554ad9, with exact preview-to-wire coverage added in 7cbee1b6f. Preview and production consume the same prepared outbound request, remain offline/read-only, and expose a redacted manifest rather than exporting unsafe raw request bodies. The implementation credits and harvests @GTC2080’s PR #1099. This has been released since v0.9.2; closing as shipped.