Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(config-state): add `cache` subcommand, gate `clear` behind confirmation (#3027)

Maximilian Roos19aa6f0a2851
diff --git a/docs/content/config.md b/docs/content/config.md
index 520c024a1..6aa9183c7 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -759,12 +759,11 @@ State is stored in `.git/` (config entries and log files), separate from configu
### Keys
+- **cache**: [Regenerable caches — CI status, summaries, git commands, hints, and the `wt switch -` target](@/config.md#wt-config-state-cache)
- **default-branch**: [The repository's default branch (`main`, `master`, etc.)](@/config.md#wt-config-state-default-branch)
-- **previous-branch**: Previous branch for `wt switch -`
-- **logs**: [Operation and debug logs](@/config.md#wt-config-state-logs)
-- **ci-status**: [CI/PR status for a branch (passed, running, failed, conflicts, no-ci, error)](@/config.md#wt-config-state-ci-status)
- **marker**: [Custom status marker for a branch (shown in `wt list`)](@/config.md#wt-config-state-marker)
- **vars**: <span class="badge-experimental"></span> [Custom variables per branch](@/config.md#wt-config-state-vars)
+- **logs**: [Operation and debug logs](@/config.md#wt-config-state-logs)
### Examples
@@ -780,8 +779,8 @@ Set a marker for current branch:
Store arbitrary data:
{{ terminal(cmd="wt config state vars set env=staging") }}
-Clear all CI status cache:
-{{ terminal(cmd="wt config state ci-status clear --all") }}
+Drop the regenerable caches:
+{{ terminal(cmd="wt config state cache clear") }}
Show all stored state:
{{ terminal(cmd="wt config state get") }}
@@ -797,20 +796,78 @@ wt config state - Manage internal data and cache
Usage: <b><span class=c>wt config state</span></b> <span class=c>[OPTIONS]</span> <span class=c>&lt;COMMAND&gt;</span>
<b><span class=g>Commands:</span></b>
- <b><span class=c>get</span></b> Get all stored state
- <b><span class=c>clear</span></b> Clear all stored state
- <b><span class=c>default-branch</span></b> Default branch detection and override
- <b><span class=c>previous-branch</span></b> Previous branch (for <b>wt switch -</b>)
- <b><span class=c>logs</span></b> Operation and debug logs
- <b><span class=c>hints</span></b> One-time hints shown in this repo
- <b><span class=c>ci-status</span></b> CI status cache
- <b><span class=c>marker</span></b> Branch markers
- <b><span class=c>vars</span></b> [experimental] Custom variables per branch
+ <b><span class=c>get</span></b> Get all stored state
+ <b><span class=c>clear</span></b> Clear all stored state
+ <b><span class=c>cache</span></b> Regenerable caches
+ <b><span class=c>default-branch</span></b> Default branch detection and override
+ <b><span class=c>logs</span></b> Operation and debug logs
+ <b><span class=c>marker</span></b> Branch markers
+ <b><span class=c>vars</span></b> [experimental] Custom variables per branch
+
+<b><span class=g>Options:</span></b>
+ <b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
+ Print help (see a summary with &#39;-h&#39;)
+
+<b><span class=g>Global Options:</span></b>
+ <b><span class=c>-C</span></b><span class=c> &lt;path&gt;</span>
+ Working directory for this command
+
+ <b><span class=c>--config</span></b><span class=c> &lt;path&gt;</span>
+ User config file path
+
+ <b><span class=c>-v</span></b>, <b><span class=c>--verbose</span></b><span class=c>...</span>
+ Verbose output (-v: info logs + hook/alias template variables on stderr; -vv: also debug
+ logs and raw subprocess output written to .git/wt/logs/)
+
+ <b><span class=c>-y</span></b>, <b><span class=c>--yes</span></b>
+ Skip approval prompts
+{% end %}
+
+## wt config state cache
+
+Regenerable caches.
+
+View or drop worktrunk's regenerable caches in one place. Everything here is rebuilt on demand — clearing only forces recomputation, never data loss.
+
+### What's cached
+
+- **CI status** — GitHub/GitLab CI per branch (30–60s TTL), shown in [`wt list`](@/list.md#ci-status)
+- **Summaries** — LLM-generated branch summaries (`wt list --full`, `wt switch` preview)
+- **Git commands** — SHA-keyed disk caches: merge-tree, ancestry, diff-stats, and `wt switch` preview renders
+- **Hints** — one-time hints already shown in this repo
+- **Previous branch** — the `wt switch -` target, re-recorded on the next switch
+
+`cache clear` drops all of the above with no prompt. It re-shows one-time hints and forgets the `wt switch -` target until the next switch — both repopulate on their own.
+
+Without a subcommand, runs `get`.
+
+### Examples
+
+Show cache contents:
+{{ terminal(cmd="wt config state cache") }}
+
+Drop all caches:
+{{ terminal(cmd="wt config state cache clear") }}
+
+### Command reference
+
+{% terminal() %}
+wt config state cache - Regenerable caches
+
+Usage: <b><span class=c>wt config state cache</span></b> <span class=c>[OPTIONS]</span> <span class=c>[COMMAND]</span>
+
+<b><span class=g>Commands:</span></b>
+ <b><span class=c>get</span></b> Show cache contents
+ <b><span class=c>clear</span></b> Drop all caches
<b><span class=g>Options:</span></b>
<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
Print help (see a summary with &#39;-h&#39;)
+<b><span class=g>Output:</span></b>
+ <b><span class=c>--format</span></b><span class=c> &lt;FORMAT&gt;</span>
+ Output format (text, json) [default: text]
+
<b><span class=g>Global Options:</span></b>
<b><span class=c>-C</span></b><span class=c> &lt;path&gt;</span>
Working directory for this command
@@ -999,6 +1056,8 @@ Usage: <b><span class=c>wt config state logs</span></b> <span class=c>[OPTIONS]<
CI status cache.
+**Deprecated** — the CI status cache is now part of [`wt config state cache`](@/config.md#wt-config-state-cache). This subcommand still works but prints a deprecation notice.
+
Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).
Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from the remote URL; set `forge.platform = "github"` (or `"gitlab"`) in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index 63b8014b3..d5ed1959a 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -773,12 +773,11 @@ State is stored in `.git/` (config entries and log files), separate from configu
### Keys
+- **cache**: [Regenerable caches — CI status, summaries, git commands, hints, and the `wt switch -` target](https://worktrunk.dev/config/#wt-config-state-cache)
- **default-branch**: [The repository's default branch (`main`, `master`, etc.)](https://worktrunk.dev/config/#wt-config-state-default-branch)
-- **previous-branch**: Previous branch for `wt switch -`
-- **logs**: [Operation and debug logs](https://worktrunk.dev/config/#wt-config-state-logs)
-- **ci-status**: [CI/PR status for a branch (passed, running, failed, conflicts, no-ci, error)](https://worktrunk.dev/config/#wt-config-state-ci-status)
- **marker**: [Custom status marker for a branch (shown in `wt list`)](https://worktrunk.dev/config/#wt-config-state-marker)
- **vars**: [experimental] [Custom variables per branch](https://worktrunk.dev/config/#wt-config-state-vars)
+- **logs**: [Operation and debug logs](https://worktrunk.dev/config/#wt-config-state-logs)
### Examples
@@ -802,9 +801,9 @@ Store arbitrary data:
$ wt config state vars set env=staging
```
-Clear all CI status cache:
+Drop the regenerable caches:
```bash
-$ wt config state ci-status clear --all
+$ wt config state cache clear
```
Show all stored state:
@@ -825,20 +824,82 @@ wt config state - Manage internal data and cache
Usage: wt config state [OPTIONS] <COMMAND>
Commands:
- get Get all stored state
- clear Clear all stored state
- default-branch Default branch detection and override
- previous-branch Previous branch (for wt switch -)
- logs Operation and debug logs
- hints One-time hints shown in this repo
- ci-status CI status cache
- marker Branch markers
- vars [experimental] Custom variables per branch
+ get Get all stored state
+ clear Clear all stored state
+ cache Regenerable caches
+ default-branch Default branch detection and override
+ logs Operation and debug logs
+ marker Branch markers
+ vars [experimental] Custom variables per branch
+
+Options:
+ -h, --help
+ Print help (see a summary with '-h')
+
+Global Options:
+ -C <path>
+ Working directory for this command
+
+ --config <path>
+ User config file path
+
+ -v, --verbose...
+ Verbose output (-v: info logs + hook/alias template variables on stderr; -vv: also debug
+ logs and raw subprocess output written to .git/wt/logs/)
+
+ -y, --yes
+ Skip approval prompts
+```
+
+## wt config state cache
+
+Regenerable caches.
+
+View or drop worktrunk's regenerable caches in one place. Everything here is rebuilt on demand — clearing only forces recomputation, never data loss.
+
+### What's cached
+
+- **CI status** — GitHub/GitLab CI per branch (30–60s TTL), shown in [`wt list`](https://worktrunk.dev/list/#ci-status)
+- **Summaries** — LLM-generated branch summaries (`wt list --full`, `wt switch` preview)
+- **Git commands** — SHA-keyed disk caches: merge-tree, ancestry, diff-stats, and `wt switch` preview renders
+- **Hints** — one-time hints already shown in this repo
+- **Previous branch** — the `wt switch -` target, re-recorded on the next switch
+
+`cache clear` drops all of the above with no prompt. It re-shows one-time hints and forgets the `wt switch -` target until the next switch — both repopulate on their own.
+
+Without a subcommand, runs `get`.
+
+### Examples
+
+Show cache contents:
+```bash
+$ wt config state cache
+```
+
+Drop all caches:
+```bash
+$ wt config state cache clear
+```
+
+### Command reference
+
+```
+wt config state cache - Regenerable caches
+
+Usage: wt config state cache [OPTIONS] [COMMAND]
+
+Commands:
+ get Show cache contents
+ clear Drop all caches
Options:
-h, --help
Print help (see a summary with '-h')
+Output:
+ --format <FORMAT>
+ Output format (text, json) [default: text]
+
Global Options:
-C <path>
Working directory for this command
@@ -1039,6 +1100,8 @@ Global Options:
CI status cache.
+**Deprecated** — the CI status cache is now part of [`wt config state cache`](https://worktrunk.dev/config/#wt-config-state-cache). This subcommand still works but prints a deprecation notice.
+
Caches GitHub/GitLab CI status for display in [`wt list`](https://worktrunk.dev/list/#ci-status).
Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from the remote URL; set `forge.platform = "github"` (or `"gitlab"`) in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
diff --git a/src/cli/config.rs b/src/cli/config.rs
index 477f4d769..786a22a27 100644
--- a/src/cli/config.rs
+++ b/src/cli/config.rs
@@ -595,12 +595,11 @@ $ wt config plugins opencode install
## Keys
+- **cache**: [Regenerable caches — CI status, summaries, git commands, hints, and the `wt switch -` target](@/config.md#wt-config-state-cache)
- **default-branch**: [The repository's default branch (`main`, `master`, etc.)](@/config.md#wt-config-state-default-branch)
-- **previous-branch**: Previous branch for `wt switch -`
-- **logs**: [Operation and debug logs](@/config.md#wt-config-state-logs)
-- **ci-status**: [CI/PR status for a branch (passed, running, failed, conflicts, no-ci, error)](@/config.md#wt-config-state-ci-status)
- **marker**: [Custom status marker for a branch (shown in `wt list`)](@/config.md#wt-config-state-marker)
- **vars**: [experimental] [Custom variables per branch](@/config.md#wt-config-state-vars)
+- **logs**: [Operation and debug logs](@/config.md#wt-config-state-logs)
## Examples
@@ -624,9 +623,9 @@ Store arbitrary data:
$ wt config state vars set env=staging
```
-Clear all CI status cache:
+Drop the regenerable caches:
```console
-$ wt config state ci-status clear --all
+$ wt config state cache clear
```
Show all stored state:
@@ -638,6 +637,7 @@ Clear all stored state:
```console
$ wt config state clear
```
+<!-- subdoc: cache -->
<!-- subdoc: default-branch -->
<!-- subdoc: logs -->
<!-- subdoc: ci-status -->
@@ -650,11 +650,15 @@ $ wt config state clear
},
}
-// Ordering: aggregate operations first (get, clear) — entry points for
-// exploring or wiping all state. Then primary state managed by wt
-// (default-branch, previous-branch, logs, hints), then per-branch display
-// annotations shown in `wt list` (ci-status, marker), then experimental keys
-// (vars).
+// Ordering: aggregate operations first (get, clear, cache) — entry points for
+// exploring, wiping, or refreshing state. Then authoritative state managed by
+// the user (default-branch override, marker, vars) and the operation logs.
+//
+// `cache` is the home for every regenerable cache (ci-status, summaries, git
+// commands, hints, previous branch). The per-category subcommands those caches
+// used to have (ci-status, hints, previous-branch) are `hide`-deprecated: they
+// still work and still appear in the match below, but print a deprecation
+// notice and are absent from `--help`.
#[derive(Subcommand)]
pub enum StateCommand {
/// Get all stored state
@@ -692,10 +696,59 @@ CI cache entries show status, age, and the commit SHA they were fetched for."#)]
- All log files
- Stale trash from worktree removal (`.git/wt/trash/`)
-Use individual subcommands (`default-branch clear`, `ci-status clear --all`, etc.)
-to clear specific state."#)]
+Prompts for confirmation before clearing, since this removes hand-authored
+markers and vars. Pass `--yes` to skip the prompt.
+
+To drop only the regenerable caches (CI status, summaries, git commands,
+hints, previous branch), run `wt config state cache clear` — it needs no
+confirmation and leaves markers, vars, and the default-branch override
+untouched."#)]
Clear,
+ /// Regenerable caches
+ #[command(
+ after_long_help = r#"View or drop worktrunk's regenerable caches in one place. Everything here is rebuilt on demand — clearing only forces recomputation, never data loss.
+
+## What's cached
+
+- **CI status** — GitHub/GitLab CI per branch (30–60s TTL), shown in [`wt list`](@/list.md#ci-status)
+- **Summaries** — LLM-generated branch summaries (`wt list --full`, `wt switch` preview)
+- **Git commands** — SHA-keyed disk caches: merge-tree, ancestry, diff-stats, and `wt switch` preview renders
+- **Hints** — one-time hints already shown in this repo
+- **Previous branch** — the `wt switch -` target, re-recorded on the next switch
+
+`cache clear` drops all of the above with no prompt. It re-shows one-time hints and forgets the `wt switch -` target until the next switch — both repopulate on their own.
+
+Without a subcommand, runs `get`.
+
+## Examples
+
+Show cache contents:
+```console
+$ wt config state cache
+```
+
+Drop all caches:
+```console
+$ wt config state cache clear
+```"#
+ )]
+ Cache {
+ #[command(subcommand)]
+ action: Option<CacheAction>,
+
+ /// Output format (text, json) [default: text]
+ #[arg(
+ long,
+ default_value = "text",
+ global = true,
+ hide_possible_values = true,
+ hide_default_value = true,
+ help_heading = "Output"
+ )]
+ format: SwitchFormat,
+ },
+
/// Default branch detection and override
#[command(
name = "default-branch",
@@ -738,7 +791,10 @@ If none of these match, detection fails; set it explicitly with `wt config state
/// Previous branch (for `wt switch -`)
#[command(
name = "previous-branch",
- after_long_help = r#"Enables `wt switch -` to return to the previous worktree, similar to `cd -` or `git checkout -`.
+ hide = true,
+ after_long_help = r#"**Deprecated** — the previous branch is now part of [`wt config state cache`](@/config.md#wt-config-state-cache). This subcommand still works but prints a deprecation notice.
+
+Enables `wt switch -` to return to the previous worktree, similar to `cd -` or `git checkout -`.
## How it works
@@ -848,7 +904,10 @@ $ wt config state logs clear
/// One-time hints shown in this repo
#[command(
- after_long_help = r#"Some hints show once per repo on first use, then are recorded in git config
+ hide = true,
+ after_long_help = r#"**Deprecated** — hints are now part of [`wt config state cache`](@/config.md#wt-config-state-cache). This subcommand still works but prints a deprecation notice.
+
+Some hints show once per repo on first use, then are recorded in git config
as `worktrunk.hints.<name>`, a count of times the hint has been shown.
## Current hints
@@ -885,7 +944,10 @@ $ wt config state hints clear NAME # re-show specific hint
/// CI status cache
#[command(
name = "ci-status",
- after_long_help = r#"Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).
+ hide = true,
+ after_long_help = r#"**Deprecated** — the CI status cache is now part of [`wt config state cache`](@/config.md#wt-config-state-cache). This subcommand still works but prints a deprecation notice.
+
+Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).
Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from the remote URL; set `forge.platform = "github"` (or `"gitlab"`) in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
@@ -1089,6 +1151,16 @@ $ wt config state previous-branch set feature
Clear,
}
+// Ordering: CRUD — get, clear.
+#[derive(Subcommand)]
+pub enum CacheAction {
+ /// Show cache contents
+ Get,
+
+ /// Drop all caches
+ Clear,
+}
+
// Ordering: CRUD — get, clear.
#[derive(Subcommand)]
pub enum CiStatusAction {
@@ -1311,6 +1383,15 @@ pub(crate) trait StateWrite {
fn write_verb(&self) -> Option<&'static str>;
}
+impl StateWrite for CacheAction {
+ fn write_verb(&self) -> Option<&'static str> {
+ match self {
+ Self::Get => None,
+ Self::Clear => Some("clear"),
+ }
+ }
+}
+
impl StateWrite for CiStatusAction {
fn write_verb(&self) -> Option<&'static str> {
match self {
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index ae8dd8bbc..a2d32d0b3 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -4,7 +4,7 @@ mod list;
mod step;
pub(crate) use config::{
- ApprovalsCommand, CiStatusAction, ConfigAliasCommand, ConfigCommand,
+ ApprovalsCommand, CacheAction, CiStatusAction, ConfigAliasCommand, ConfigCommand,
ConfigPluginsClaudeCommand, ConfigPluginsCodexCommand, ConfigPluginsCommand,
ConfigPluginsOpencodeCommand, ConfigShellCommand, DefaultBranchAction, HintsAction, LogsAction,
MarkerAction, PreviousBranchAction, StateCommand, StateWrite, VarsAction,
diff --git a/src/commands/config/mod.rs b/src/commands/config/mod.rs
index fcd165eff..4e15b2498 100644
--- a/src/commands/config/mod.rs
+++ b/src/commands/config/mod.rs
@@ -25,9 +25,9 @@ pub use plugins::{
};
pub use show::handle_config_show;
pub use state::{
- handle_logs_list, handle_state_clear, handle_state_clear_all, handle_state_get,
- handle_state_set, handle_state_show, handle_vars_clear, handle_vars_get, handle_vars_list,
- handle_vars_set,
+ handle_cache_clear, handle_cache_get, handle_logs_list, handle_state_clear,
+ handle_state_clear_all, handle_state_get, handle_state_set, handle_state_show,
+ handle_vars_clear, handle_vars_get, handle_vars_list, handle_vars_set,
};
pub use update::handle_config_update;
diff --git a/src/commands/config/state.rs b/src/commands/config/state.rs
index cc62645e1..d3a6f609d 100644
--- a/src/commands/config/state.rs
+++ b/src/commands/config/state.rs
@@ -10,12 +10,22 @@
//! removes. A user should never be able to run `state clear` and have something
//! disappear that `state get` never mentioned.
//!
-//! Categories covered by both paths:
+//! Categories split into two buckets by whether they are regenerable:
//!
-//! - Default branch cache (git config `worktrunk.default_branch.*`)
-//! - Previous branch (git config `worktrunk.history`)
+//! **Authoritative** (hand-authored or override state; lost permanently if
+//! cleared). `state clear` prompts before removing these unless `--yes`:
+//!
+//! - Default branch override (git config `worktrunk.default_branch.*`)
//! - Branch markers (git config `worktrunk.state.<branch>.marker`)
//! - Vars (git config `worktrunk.state.<branch>.vars.*`)
+//! - Logs (`.git/wt/logs/`)
+//! - Trash (`.git/wt/trash/`)
+//!
+//! **Regenerable caches** — also surfaced by `wt config state cache get`
+//! (`handle_cache_get`) and dropped by `wt config state cache clear`
+//! (`handle_cache_clear`), which needs no prompt:
+//!
+//! - Previous branch (git config `worktrunk.history`)
//! - CI status cache (`.git/wt/cache/ci-status/`)
//! - Summary cache (`.git/wt/cache/summary/`)
//! - Git commands cache (`.git/wt/cache/{merge-tree-conflicts,is-ancestor,picker-preview,…}/`)
@@ -23,12 +33,18 @@
//! when implementation lives in different modules (`sha_cache` for parsed
//! results, `commands::picker::preview_cache` for rendered previews)
//! - Hints (git config `worktrunk.hints.*`)
-//! - Logs (`.git/wt/logs/`)
-//! - Trash (`.git/wt/trash/`)
+//!
+//! Each category has a `clear_*_reported` helper that clears it and prints its
+//! message; `handle_state_clear_all` composes all of them and
+//! `handle_cache_clear` composes the regenerable subset, so the two entry
+//! points report identically. The `ci-status`, `hints`, and `previous-branch`
+//! subcommands are `hide`-deprecated in favour of `cache` but still resolve to
+//! the same state.
//!
//! When adding a new category, update BOTH `handle_state_show` and
-//! `handle_state_clear_all`, plus the `after_long_help` blocks for `state get`
-//! and `state clear` in `src/cli/config.rs`, in the same change.
+//! `handle_state_clear_all` (and `handle_cache_*` if it is a cache), plus the
+//! `after_long_help` blocks for `state get`, `state clear`, and `state cache`
+//! in `src/cli/config.rs`, in the same change.
//!
//! # Reading vs resolving
//!
@@ -66,6 +82,7 @@ use worktrunk::styling::{
};
use crate::cli::{OutputFormat, SwitchFormat};
+use crate::output::prompt::{PromptResponse, prompt_yes_no_preview};
use worktrunk::utils::epoch_now;
use super::super::list::ci_status::{CachedCiStatus, CiBranchName};
@@ -948,134 +965,213 @@ pub fn handle_state_clear(key: &str, branch: Option<String>, all: bool) -> anyho
}
/// Handle the state clear all command
-pub fn handle_state_clear_all() -> anyhow::Result<()> {
+pub fn handle_state_clear_all(yes: bool) -> anyhow::Result<()> {
let repo = Repository::current()?;
+
+ // `clear` removes hand-authored markers and vars, so confirm first unless
+ // `--yes`. The regenerable caches have their own no-prompt path
+ // (`wt config state cache clear`).
+ if !yes {
+ match prompt_yes_no_preview(
+ "Clear all stored state, including branch markers and vars?",
+ || {},
+ )? {
+ PromptResponse::Accepted => {}
+ PromptResponse::Declined => {
+ eprintln!("{}", info_message("Clear cancelled"));
+ return Ok(());
+ }
+ }
+ }
+
let mut cleared_any = false;
+ cleared_any |= clear_default_branch_reported(&repo)?;
+ cleared_any |= clear_previous_branch_reported(&repo)?;
+ cleared_any |= clear_markers_reported(&repo)?;
+ cleared_any |= clear_ci_status_reported(&repo)?;
+ cleared_any |= clear_summary_reported(&repo)?;
+ cleared_any |= clear_git_commands_reported(&repo)?;
+ cleared_any |= clear_vars_reported(&repo)?;
+ cleared_any |= clear_logs_reported(&repo)?;
+ cleared_any |= clear_hints_reported(&repo)?;
+ cleared_any |= clear_trash_reported(&repo)?;
+
+ if !cleared_any {
+ eprintln!("{}", info_message("No stored state to clear"));
+ }
+
+ Ok(())
+}
+
+/// Handle `wt config state cache clear`.
+///
+/// Drops every regenerable cache — the same categories `clear` removes minus
+/// the authoritative state (markers, vars, default-branch override). No
+/// confirmation prompt: clearing only forces recomputation. Re-shows one-time
+/// hints and forgets the `wt switch -` target; both repopulate on their own.
+pub fn handle_cache_clear() -> anyhow::Result<()> {
+ let repo = Repository::current()?;
+
+ let mut cleared_any = false;
+ cleared_any |= clear_previous_branch_reported(&repo)?;
+ cleared_any |= clear_ci_status_reported(&repo)?;
+ cleared_any |= clear_summary_reported(&repo)?;
+ cleared_any |= clear_git_commands_reported(&repo)?;
+ cleared_any |= clear_hints_reported(&repo)?;
+
+ if !cleared_any {
+ eprintln!("{}", info_message("No cache to clear"));
+ }
+
+ Ok(())
+}
- // Clear default branch cache
+// ==================== Per-category clear + report ====================
+//
+// Each helper clears one category and prints its success message when it
+// removed anything, returning whether it did. `handle_state_clear_all`
+// composes all ten; `handle_cache_clear` composes the regenerable subset.
+// Co-locating the clear call with its message keeps the two entry points
+// reporting identically.
+
+fn clear_default_branch_reported(repo: &Repository) -> anyhow::Result<bool> {
if repo.clear_default_branch_cache()? {
eprintln!("{}", success_message("Cleared default branch cache"));
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear previous branch
+fn clear_previous_branch_reported(repo: &Repository) -> anyhow::Result<bool> {
if repo.unset_config("worktrunk.history")? {
eprintln!("{}", success_message("Cleared previous branch"));
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear all markers
- let markers_cleared = clear_all_markers(&repo)?;
- if markers_cleared > 0 {
+fn clear_markers_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = clear_all_markers(repo)?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{markers_cleared}</> marker{}",
- if markers_cleared == 1 { "" } else { "s" }
+ "Cleared <bold>{cleared}</> marker{}",
+ if cleared == 1 { "" } else { "s" }
))
);
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear all CI status cache
- let ci_cleared = CachedCiStatus::clear_all(&repo)?;
- if ci_cleared > 0 {
+fn clear_ci_status_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = CachedCiStatus::clear_all(repo)?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{ci_cleared}</> CI cache entr{}",
- if ci_cleared == 1 { "y" } else { "ies" }
+ "Cleared <bold>{cleared}</> CI cache entr{}",
+ if cleared == 1 { "y" } else { "ies" }
))
);
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear all summary cache entries
- let summary_cleared = CachedSummary::clear_all(&repo)?;
- if summary_cleared > 0 {
+fn clear_summary_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = CachedSummary::clear_all(repo)?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{summary_cleared}</> summary cache entr{}",
- if summary_cleared == 1 { "y" } else { "ies" }
+ "Cleared <bold>{cleared}</> summary cache entr{}",
+ if cleared == 1 { "y" } else { "ies" }
))
);
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear all SHA-keyed git command caches: parsed results
- // (merge-tree, ancestry, diff-stats) plus rendered picker previews
- // (log, branch-diff, upstream-diff). Surfaced as one user-facing
- // category — see the parity docstring at the top of this file.
- let cache_cleared = sha_cache::clear_all(&repo)? + picker_preview_clear(&repo)?;
- if cache_cleared > 0 {
+/// Clear all SHA-keyed git command caches: parsed results (merge-tree,
+/// ancestry, diff-stats) plus rendered picker previews (log, branch-diff,
+/// upstream-diff). Surfaced as one user-facing category — see the parity
+/// docstring at the top of this file.
+fn clear_git_commands_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = sha_cache::clear_all(repo)? + picker_preview_clear(repo)?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{cache_cleared}</> git commands cache entr{}",
- if cache_cleared == 1 { "y" } else { "ies" }
+ "Cleared <bold>{cleared}</> git commands cache entr{}",
+ if cleared == 1 { "y" } else { "ies" }
))
);
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear all vars data
- let vars_cleared = clear_all_vars(&repo)?;
- if vars_cleared > 0 {
+fn clear_vars_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = clear_all_vars(repo)?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{vars_cleared}</> variable{}",
- if vars_cleared == 1 { "" } else { "s" }
+ "Cleared <bold>{cleared}</> variable{}",
+ if cleared == 1 { "" } else { "s" }
))
);
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear all logs
- let logs_cleared = clear_logs(&repo)?;
- if logs_cleared > 0 {
+fn clear_logs_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = clear_logs(repo)?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{logs_cleared}</> log file{}",
- if logs_cleared == 1 { "" } else { "s" }
+ "Cleared <bold>{cleared}</> log file{}",
+ if cleared == 1 { "" } else { "s" }
))
);
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear all hints
- let hints_cleared = repo.clear_all_hints()?;
- if hints_cleared > 0 {
+fn clear_hints_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = repo.clear_all_hints()?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{hints_cleared}</> hint{}",
- if hints_cleared == 1 { "" } else { "s" }
+ "Cleared <bold>{cleared}</> hint{}",
+ if cleared == 1 { "" } else { "s" }
))
);
- cleared_any = true;
+ return Ok(true);
}
+ Ok(false)
+}
- // Clear stale trash from worktree removal
- let trash_cleared = clear_trash(&repo)?;
- if trash_cleared > 0 {
+fn clear_trash_reported(repo: &Repository) -> anyhow::Result<bool> {
+ let cleared = clear_trash(repo)?;
+ if cleared > 0 {
eprintln!(
"{}",
success_message(cformat!(
- "Cleared <bold>{trash_cleared}</> trash entr{}",
- if trash_cleared == 1 { "y" } else { "ies" }
+ "Cleared <bold>{cleared}</> trash entr{}",
+ if cleared == 1 { "y" } else { "ies" }
))
);
- cleared_any = true;
+ return Ok(true);
}
-
- if !cleared_any {
- eprintln!("{}", info_message("No stored state to clear"));
- }
-
- Ok(())
+ Ok(false)
}
// ==================== State Show Commands ====================
@@ -1111,34 +1207,9 @@ fn handle_state_show_json(repo: &Repository) -> anyhow::Result<()> {
})
.collect();
- // Get CI status cache (pre-sorted newest-first)
- let ci_status: Vec<serde_json::Value> = CachedCiStatus::list_all(repo)
- .into_iter()
- .map(|cached| {
- let status = cached
- .status
- .as_ref()
- .map(|s| -> &'static str { s.ci_status.into() });
- serde_json::json!({
- "branch": cached.branch,
- "status": status,
- "checked_at": cached.checked_at,
- "head": cached.head
- })
- })
- .collect();
-
- // Get summary cache (freshest entry per branch, pre-sorted newest-first)
- let summaries: Vec<serde_json::Value> = CachedSummary::list_all(repo)
- .into_iter()
- .map(|cached| {
- serde_json::json!({
- "branch": cached.branch,
- "summary": cached.summary,
- "generated_at": cached.generated_at,
- })
- })
- .collect();
+ // Get CI status and summary caches (pre-sorted newest-first)
+ let ci_status = ci_status_json(repo);
+ let summaries = summaries_json(repo);
let (command_log, hook_output, diagnostic) = partition_log_files_json(repo)?;
@@ -1212,11 +1283,7 @@ fn handle_state_show_table(repo: &Repository) -> anyhow::Result<()> {
writeln!(out)?;
// Show previous branch (for `wt switch -`)
- writeln!(out, "{}", format_heading("PREVIOUS BRANCH", None))?;
- match repo.switch_previous() {
- Some(prev) => writeln!(out, "{}", format_with_gutter(&prev, None))?,
- None => writeln!(out, "{}", format_with_gutter("(none)", None))?,
- }
+ render_previous_branch_section(&mut out, repo)?;
writeln!(out)?;
// Show branch markers
@@ -1261,6 +1328,117 @@ fn handle_state_show_table(repo: &Repository) -> anyhow::Result<()> {
writeln!(out)?;
// Show CI status cache (pre-sorted newest-first)
+ render_ci_status_section(&mut out, repo)?;
+ writeln!(out)?;
+
+ // Show summary cache (LLM summaries keyed by branch + diff hash)
+ render_summary_section(&mut out, repo)?;
+ writeln!(out)?;
+
+ // Show git commands cache summary
+ render_git_commands_section(&mut out, repo)?;
+ writeln!(out)?;
+
+ // Show hints
+ render_hints_section(&mut out, repo)?;
+ writeln!(out)?;
+
+ // Show log files
+ render_all_log_sections(&mut out, repo)?;
+ writeln!(out)?;
+
+ // Show trash (staged worktree removals awaiting background delete)
+ let trash_dir = repo.wt_trash_dir();
+ let trash_display = format_path_for_display(&trash_dir);
+ writeln!(
+ out,
+ "{}",
+ format_heading("TRASH", Some(&format!("@ {trash_display}")))
+ )?;
+ let trash = list_trash_entries(repo)?;
+ if trash.is_empty() {
+ writeln!(out, "{}", format_with_gutter("(none)", None))?;
+ } else {
+ let rows: Vec<Vec<String>> = trash
+ .iter()
+ .map(|e| {
+ let age = e
+ .metadata
+ .modified()
+ .ok()
+ .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
+ .map(|d| format_relative_time_short(d.as_secs() as i64))
+ .unwrap_or_else(|| "?".to_string());
+ vec![e.name.clone(), age]
+ })
+ .collect();
+ let rendered = crate::md_help::render_data_table(&["Entry", "Age"], &rows);
+ writeln!(out, "{}", rendered.trim_end())?;
+ }
+
+ show_help_in_pager(&out, true);
+
+ Ok(())
+}
+
+// ==================== Cache view ====================
+//
+// `cache get`/`cache clear` operate on the regenerable subset of state. The
+// section renderers and JSON builders below are shared with the aggregate
+// `state get` so both views render each category identically.
+
+/// Handle `wt config state cache get` (regenerable caches only).
+pub fn handle_cache_get(format: SwitchFormat) -> anyhow::Result<()> {
+ let repo = Repository::current()?;
+ match format {
+ SwitchFormat::Json => handle_cache_get_json(&repo),
+ SwitchFormat::Text => handle_cache_get_table(&repo),
+ }
+}
+
+fn handle_cache_get_table(repo: &Repository) -> anyhow::Result<()> {
+ let mut out = String::new();
+
+ render_previous_branch_section(&mut out, repo)?;
+ writeln!(out)?;
+ render_ci_status_section(&mut out, repo)?;
+ writeln!(out)?;
+ render_summary_section(&mut out, repo)?;
+ writeln!(out)?;
+ render_git_commands_section(&mut out, repo)?;
+ writeln!(out)?;
+ render_hints_section(&mut out, repo)?;
+
+ show_help_in_pager(&out, true);
+
+ Ok(())
+}
+
+fn handle_cache_get_json(repo: &Repository) -> anyhow::Result<()> {
+ let output = serde_json::json!({
+ "previous_branch": repo.switch_previous(),
+ "ci_status": ci_status_json(repo),
+ "summaries": summaries_json(repo),
+ "git_commands_cache": sha_cache::count_all(repo) + picker_preview_count(repo),
+ "hints": repo.list_shown_hints(),
+ });
+
+ println!("{}", serde_json::to_string_pretty(&output)?);
+ Ok(())
+}
+
+// ==================== Shared section renderers ====================
+
+fn render_previous_branch_section(out: &mut String, repo: &Repository) -> anyhow::Result<()> {
+ writeln!(out, "{}", format_heading("PREVIOUS BRANCH", None))?;
+ match repo.switch_previous() {
+ Some(prev) => writeln!(out, "{}", format_with_gutter(&prev, None))?,
+ None => writeln!(out, "{}", format_with_gutter("(none)", None))?,
+ }
+ Ok(())
+}
+
+fn render_ci_status_section(out: &mut String, repo: &Repository) -> anyhow::Result<()> {
writeln!(out, "{}", format_heading("CI STATUS CACHE", None))?;
let entries = CachedCiStatus::list_all(repo);
if entries.is_empty() {
@@ -1285,9 +1463,10 @@ fn handle_state_show_table(repo: &Repository) -> anyhow::Result<()> {
crate::md_help::render_data_table(&["Branch", "Status", "Age", "Head"], &rows);
writeln!(out, "{}", rendered.trim_end())?;
}
- writeln!(out)?;
+ Ok(())
+}
- // Show summary cache (LLM summaries keyed by branch + diff hash, pre-sorted newest-first)
+fn render_summary_section(out: &mut String, repo: &Repository) -> anyhow::Result<()> {
writeln!(out, "{}", format_heading("SUMMARY CACHE", None))?;
let summary_entries = CachedSummary::list_all(repo);
if summary_entries.is_empty() {
@@ -1304,12 +1483,14 @@ fn handle_state_show_table(repo: &Repository) -> anyhow::Result<()> {
let rendered = crate::md_help::render_data_table(&["Branch", "Summary", "Age"], &rows);
writeln!(out, "{}", rendered.trim_end())?;
}
- writeln!(out)?;
+ Ok(())
+}
- // Show git commands cache summary. Spans both `sha_cache` (parsed
- // SHA-keyed results) and the picker preview cache (rendered SHA-keyed
- // previews) — one user-facing category covering every SHA-keyed disk
- // cache, regardless of which module owns the entries.
+/// Render the git commands cache summary. Spans both `sha_cache` (parsed
+/// SHA-keyed results) and the picker preview cache (rendered SHA-keyed
+/// previews) — one user-facing category covering every SHA-keyed disk cache,
+/// regardless of which module owns the entries.
+fn render_git_commands_section(out: &mut String, repo: &Repository) -> anyhow::Result<()> {
writeln!(out, "{}", format_heading("GIT COMMANDS CACHE", None))?;
let cache_count = sha_cache::count_all(repo) + picker_preview_count(repo);
if cache_count == 0 {
@@ -1322,9 +1503,10 @@ fn handle_state_show_table(repo: &Repository) -> anyhow::Result<()> {
format_with_gutter(&format!("{cache_count} {label}"), None)
)?;
}
- writeln!(out)?;
+ Ok(())
+}
- // Show hints
+fn render_hints_section(out: &mut String, repo: &Repository) -> anyhow::Result<()> {
writeln!(out, "{}", format_heading("HINTS", None))?;
let hints = repo.list_shown_hints();
if hints.is_empty() {
@@ -1334,44 +1516,42 @@ fn handle_state_show_table(repo: &Repository) -> anyhow::Result<()> {
writeln!(out, "{}", format_with_gutter(&hint, None))?;
}
}
- writeln!(out)?;
-
- // Show log files
- render_all_log_sections(&mut out, repo)?;
- writeln!(out)?;
+ Ok(())
+}
- // Show trash (staged worktree removals awaiting background delete)
- let trash_dir = repo.wt_trash_dir();
- let trash_display = format_path_for_display(&trash_dir);
- writeln!(
- out,
- "{}",
- format_heading("TRASH", Some(&format!("@ {trash_display}")))
- )?;
- let trash = list_trash_entries(repo)?;
- if trash.is_empty() {
- writeln!(out, "{}", format_with_gutter("(none)", None))?;
- } else {
- let rows: Vec<Vec<String>> = trash
- .iter()
- .map(|e| {
- let age = e
- .metadata
- .modified()
- .ok()
- .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
- .map(|d| format_relative_time_short(d.as_secs() as i64))
- .unwrap_or_else(|| "?".to_string());
- vec![e.name.clone(), age]
+/// CI status cache entries as JSON (pre-sorted newest-first). Shared by
+/// `state get` and `cache get`.
+fn ci_status_json(repo: &Repository) -> Vec<serde_json::Value> {
+ CachedCiStatus::list_all(repo)
+ .into_iter()
+ .map(|cached| {
+ let status = cached
+ .status
+ .as_ref()
+ .map(|s| -> &'static str { s.ci_status.into() });
+ serde_json::json!({
+ "branch": cached.branch,
+ "status": status,
+ "checked_at": cached.checked_at,
+ "head": cached.head
})
- .collect();
- let rendered = crate::md_help::render_data_table(&["Entry", "Age"], &rows);
- writeln!(out, "{}", rendered.trim_end())?;
- }
-
- show_help_in_pager(&out, true);
+ })
+ .collect()
+}
- Ok(())
+/// Summary cache entries as JSON (freshest per branch, pre-sorted
+/// newest-first). Shared by `state get` and `cache get`.
+fn summaries_json(repo: &Repository) -> Vec<serde_json::Value> {
+ CachedSummary::list_all(repo)
+ .into_iter()
+ .map(|cached| {
+ serde_json::json!({
+ "branch": cached.branch,
+ "summary": cached.summary,
+ "generated_at": cached.generated_at,
+ })
+ })
+ .collect()
}
// ==================== Vars Operations ====================
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 0c881082c..a00c9e72c 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -35,13 +35,13 @@ pub(crate) use alias::{
try_alias,
};
pub(crate) use config::{
- add_approvals, clear_approvals, handle_alias_dry_run, handle_alias_show, handle_claude_install,
- handle_claude_install_statusline, handle_claude_uninstall, handle_codex_install,
- handle_codex_uninstall, handle_config_create, handle_config_show, handle_config_update,
- handle_hints_clear, handle_hints_get, handle_logs_list, handle_opencode_install,
- handle_opencode_uninstall, handle_state_clear, handle_state_clear_all, handle_state_get,
- handle_state_set, handle_state_show, handle_vars_clear, handle_vars_get, handle_vars_list,
- handle_vars_set,
+ add_approvals, clear_approvals, handle_alias_dry_run, handle_alias_show, handle_cache_clear,
+ handle_cache_get, handle_claude_install, handle_claude_install_statusline,
+ handle_claude_uninstall, handle_codex_install, handle_codex_uninstall, handle_config_create,
+ handle_config_show, handle_config_update, handle_hints_clear, handle_hints_get,
+ handle_logs_list, handle_opencode_install, handle_opencode_uninstall, handle_state_clear,
+ handle_state_clear_all, handle_state_get, handle_state_set, handle_state_show,
+ handle_vars_clear, handle_vars_get, handle_vars_list, handle_vars_set,
};
pub(crate) use configure_shell::{
handle_configure_shell, handle_show_theme, handle_unconfigure_shell,
diff --git a/src/main.rs b/src/main.rs
index 85a1fd658..ac7bed18f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -51,23 +51,23 @@ use commands::worktree::{PushKind, PushOutcome, PushResult, handle_no_ff_merge,
use commands::{
HookCliArgs, MergeFlagOverrides, MergeOptions, RebaseResult, RemoveTarget, SquashResult,
SwitchOptions, add_approvals, clear_approvals, handle_alias_dry_run, handle_alias_show,
- handle_claude_install, handle_claude_install_statusline, handle_claude_uninstall,
- handle_codex_install, handle_codex_uninstall, handle_completions, handle_config_create,
- handle_config_show, handle_config_update, handle_configure_shell, handle_custom_command,
- handle_hints_clear, handle_hints_get, handle_hook_show, handle_init, handle_list,
- handle_logs_list, handle_merge, handle_opencode_install, handle_opencode_uninstall,
- handle_promote, handle_rebase, handle_show_theme, handle_squash, handle_state_clear,
- handle_state_clear_all, handle_state_get, handle_state_set, handle_state_show,
- handle_unconfigure_shell, handle_vars_clear, handle_vars_get, handle_vars_list,
- handle_vars_set, resolve_worktree_arg, run_hook, run_switch, step_commit, step_copy_ignored,
- step_diff, step_eval, step_for_each, step_prune, step_relocate, step_tether,
+ handle_cache_clear, handle_cache_get, handle_claude_install, handle_claude_install_statusline,
+ handle_claude_uninstall, handle_codex_install, handle_codex_uninstall, handle_completions,
+ handle_config_create, handle_config_show, handle_config_update, handle_configure_shell,
+ handle_custom_command, handle_hints_clear, handle_hints_get, handle_hook_show, handle_init,
+ handle_list, handle_logs_list, handle_merge, handle_opencode_install,
+ handle_opencode_uninstall, handle_promote, handle_rebase, handle_show_theme, handle_squash,
+ handle_state_clear, handle_state_clear_all, handle_state_get, handle_state_set,
+ handle_state_show, handle_unconfigure_shell, handle_vars_clear, handle_vars_get,
+ handle_vars_list, handle_vars_set, resolve_worktree_arg, run_hook, run_switch, step_commit,
+ step_copy_ignored, step_diff, step_eval, step_for_each, step_prune, step_relocate, step_tether,
};
use output::{BackgroundFallbackMode, handle_remove_output};
use worktrunk::git::BranchDeletionMode;
use cli::{
- ApprovalsCommand, CiStatusAction, Cli, Commands, ConfigAliasCommand, ConfigCommand,
- ConfigPluginsClaudeCommand, ConfigPluginsCodexCommand, ConfigPluginsCommand,
+ ApprovalsCommand, CacheAction, CiStatusAction, Cli, Commands, ConfigAliasCommand,
+ ConfigCommand, ConfigPluginsClaudeCommand, ConfigPluginsCodexCommand, ConfigPluginsCommand,
ConfigPluginsOpencodeCommand, ConfigShellCommand, DefaultBranchAction, HintsAction,
HookCommand, HookOptions, ListArgs, ListSubcommand, LogsAction, MarkerAction, MergeArgs,
PreviousBranchAction, RemoveArgs, StateCommand, StateWrite, StepCommand, SwitchArgs,
@@ -140,7 +140,21 @@ pub(crate) fn flag_pair(positive: bool, negative: bool) -> Option<bool> {
fn warn_select_deprecated() {
eprintln!(
"{}",
- warning_message("wt select is deprecated; use wt switch instead")
+ warning_message(cformat!(
+ "wt select is deprecated; use <bold>wt switch</> instead"
+ ))
+ );
+}
+
+/// Emit the deprecation notice for a `wt config state` subcommand that has
+/// moved under `wt config state cache` (ci-status, hints, previous-branch).
+/// These still work — the warning nudges callers toward `cache`.
+fn warn_state_subcommand_deprecated(name: &str) {
+ eprintln!(
+ "{}",
+ warning_message(cformat!(
+ "wt config state {name} is deprecated; use <bold>wt config state cache</> instead"
+ ))
);
}
@@ -152,7 +166,9 @@ fn warn_select_deprecated() {
pub(crate) fn warn_no_verify_deprecated() {
eprintln!(
"{}",
- warning_message("--no-verify is deprecated; use --no-hooks instead")
+ warning_message(cformat!(
+ "--no-verify is deprecated; use <bold>--no-hooks</> instead"
+ ))
);
}
@@ -167,7 +183,9 @@ fn handle_hook_command(action: HookCommand, yes: bool) -> anyhow::Result<()> {
HookCommand::Approvals { action } => {
eprintln!(
"{}",
- warning_message("wt hook approvals is deprecated; use wt config approvals instead")
+ warning_message(cformat!(
+ "wt hook approvals is deprecated; use <bold>wt config approvals</> instead"
+ ))
);
match action {
ApprovalsCommand::Add { all } => add_approvals(all),
@@ -441,8 +459,17 @@ fn guard_format_on_write(action_name: &str, format: SwitchFormat) -> anyhow::Res
Err(enhance_clap_error(err))
}
-fn handle_state_command(action: StateCommand) -> anyhow::Result<()> {
+fn handle_state_command(action: StateCommand, yes: bool) -> anyhow::Result<()> {
match action {
+ StateCommand::Cache { action, format } => {
+ if let Some(verb) = action.as_ref().and_then(StateWrite::write_verb) {
+ guard_format_on_write(verb, format)?;
+ }
+ match action {
+ Some(CacheAction::Get) | None => handle_cache_get(format),
+ Some(CacheAction::Clear) => handle_cache_clear(),
+ }
+ }
StateCommand::DefaultBranch { action } => match action {
Some(DefaultBranchAction::Get) | None => {
handle_state_get("default-branch", None, SwitchFormat::Text)
@@ -452,16 +479,22 @@ fn handle_state_command(action: StateCommand) -> anyhow::Result<()> {
}
Some(DefaultBranchAction::Clear) => handle_state_clear("default-branch", None, false),
},
- StateCommand::PreviousBranch { action } => match action {
- Some(PreviousBranchAction::Get) | None => {
- handle_state_get("previous-branch", None, SwitchFormat::Text)
- }
- Some(PreviousBranchAction::Set { branch }) => {
- handle_state_set("previous-branch", branch, None)
+ StateCommand::PreviousBranch { action } => {
+ warn_state_subcommand_deprecated("previous-branch");
+ match action {
+ Some(PreviousBranchAction::Get) | None => {
+ handle_state_get("previous-branch", None, SwitchFormat::Text)
+ }
+ Some(PreviousBranchAction::Set { branch }) => {
+ handle_state_set("previous-branch", branch, None)
+ }
+ Some(PreviousBranchAction::Clear) => {
+ handle_state_clear("previous-branch", None, false)
+ }
}
- Some(PreviousBranchAction::Clear) => handle_state_clear("previous-branch", None, false),
- },
+ }
StateCommand::CiStatus { action, format } => {
+ warn_state_subcommand_deprecated("ci-status");
if let Some(verb) = action.as_ref().and_then(StateWrite::write_verb) {
guard_format_on_write(verb, format)?;
}
@@ -500,6 +533,7 @@ fn handle_state_command(action: StateCommand) -> anyhow::Result<()> {
}
}
StateCommand::Hints { action, format } => {
+ warn_state_subcommand_deprecated("hints");
if let Some(verb) = action.as_ref().and_then(StateWrite::write_verb) {
guard_format_on_write(verb, format)?;
}
@@ -520,7 +554,7 @@ fn handle_state_command(action: StateCommand) -> anyhow::Result<()> {
}
},
StateCommand::Get { format } => handle_state_show(format),
- StateCommand::Clear => handle_state_clear_all(),
+ StateCommand::Clear => handle_state_clear_all(yes),
}
}
@@ -591,7 +625,7 @@ fn handle_config_command(action: ConfigCommand, yes: bool) -> anyhow::Result<()>
ConfigAliasCommand::DryRun { name, args } => handle_alias_dry_run(name, args),
},
ConfigCommand::Plugins { action } => handle_plugins_command(action, yes),
- ConfigCommand::State { action } => handle_state_command(action),
+ ConfigCommand::State { action } => handle_state_command(action, yes),
}
}
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index c1c3f5137..e578ccc19 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -1697,23 +1697,24 @@ mod bare_repo_prompt_pty {
"Legacy top-level skip key should no longer be written"
);
- // Round-trip through `wt config state`: the opt-out is listed by
- // `state hints` and removed by the aggregate `state clear`.
+ // Round-trip through `wt config state`: the opt-out is listed by the
+ // cache view and removed by the aggregate `state clear`.
let mut hints_cmd = wt_command();
test.configure_wt_cmd(&mut hints_cmd);
hints_cmd
- .args(["config", "state", "hints"])
+ .args(["config", "state", "cache"])
.current_dir(&main_worktree);
let hints_listed = String::from_utf8(hints_cmd.output().unwrap().stdout).unwrap();
assert!(
hints_listed.contains("skip-bare-repo-prompt"),
- "state hints should list the opt-out.\nstdout: {hints_listed}"
+ "state cache should list the opt-out hint.\nstdout: {hints_listed}"
);
+ // `state clear` removes everything but prompts first — `--yes` skips it.
let mut clear_cmd = wt_command();
test.configure_wt_cmd(&mut clear_cmd);
clear_cmd
- .args(["config", "state", "clear"])
+ .args(["config", "state", "clear", "--yes"])
.current_dir(&main_worktree);
assert!(
clear_cmd.output().unwrap().status.success(),
diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rs
index db3d54c03..4f08cccfa 100644
--- a/tests/integration_tests/config_state.rs
+++ b/tests/integration_tests/config_state.rs
@@ -1,8 +1,9 @@
use crate::common::{TEST_EPOCH, TestRepo, repo, repo_with_remote, wt_command};
use insta::assert_snapshot;
use rstest::rstest;
+use std::io::Write as _;
use std::path::{Path, PathBuf};
-use std::process::Command;
+use std::process::{Command, Stdio};
use worktrunk::path::sanitize_for_filename;
/// Relative path of a hook log file under the wt logs directory.
@@ -241,7 +242,10 @@ fn test_state_set_previous_branch(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Set previous branch to feature");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state previous-branch is deprecated; use wt config state cache instead
+ ✓ Set previous branch to feature
+ ");
// Verify it was set
let output = wt_state_cmd(&repo, "previous-branch", "get", &[])
@@ -262,7 +266,10 @@ fn test_state_clear_previous_branch(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared previous branch");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state previous-branch is deprecated; use wt config state cache instead
+ ✓ Cleared previous branch
+ ");
// Verify it was cleared
let output = wt_state_cmd(&repo, "previous-branch", "get", &[])
@@ -279,7 +286,10 @@ fn test_state_clear_previous_branch_empty(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No previous branch to clear");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state previous-branch is deprecated; use wt config state cache instead
+ ○ No previous branch to clear
+ ");
}
// ============================================================================
@@ -369,6 +379,7 @@ fn test_state_get_ci_status_nonexistent_branch(repo: TestRepo) {
.unwrap();
assert!(!output.status.success());
assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
✗ No branch named nonexistent
↳ To create a new branch, run wt switch --create nonexistent; to list branches, run wt list --branches --remotes
");
@@ -469,7 +480,10 @@ fn test_state_clear_ci_status_all_empty(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No CI cache entries to clear");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
+ ○ No CI cache entries to clear
+ ");
}
#[rstest]
@@ -489,7 +503,10 @@ fn test_state_clear_ci_status_branch(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared CI cache for main");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
+ ✓ Cleared CI cache for main
+ ");
assert!(
!cache_file.exists(),
"cache file should be gone after clear"
@@ -505,7 +522,10 @@ fn test_state_clear_ci_status_branch_not_cached(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No CI cache for main");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
+ ○ No CI cache for main
+ ");
assert!(!cache_file.exists(), "cache file should still not exist");
}
@@ -883,7 +903,9 @@ fn wt_state_clear_all_cmd(repo: &TestRepo) -> std::process::Command {
let mut cmd = wt_command();
cmd.current_dir(repo.root_path());
cmd.env("CLICOLOR_FORCE", "1");
- cmd.args(["config", "state", "clear"]);
+ // `clear` prompts before removing markers/vars; `--yes` skips it so these
+ // tests exercise the clearing itself. The prompt path has its own tests.
+ cmd.args(["config", "state", "clear", "--yes"]);
cmd
}
@@ -1029,6 +1051,238 @@ fn test_state_clear_all_nothing_to_clear(repo: TestRepo) {
assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No stored state to clear");
}
+/// Run `wt config state clear` (no `--yes`) with the given stdin, so the
+/// confirmation prompt reads `input`.
+fn clear_all_with_stdin(repo: &TestRepo, input: &str) -> std::process::Output {
+ let mut cmd = wt_command();
+ cmd.current_dir(repo.root_path());
+ cmd.env("CLICOLOR_FORCE", "1");
+ cmd.args(["config", "state", "clear"]);
+ cmd.stdin(Stdio::piped());
+ cmd.stdout(Stdio::piped());
+ cmd.stderr(Stdio::piped());
+ let mut child = cmd.spawn().unwrap();
+ child
+ .stdin
+ .take()
+ .unwrap()
+ .write_all(input.as_bytes())
+ .unwrap();
+ child.wait_with_output().unwrap()
+}
+
+/// Without `--yes` and with no interactive input, the prompt declines and
+/// nothing is cleared.
+#[rstest]
+fn test_state_clear_all_prompt_declines(repo: TestRepo) {
+ repo.git_command()
+ .args(["config", "worktrunk.history", "feature"])
+ .run()
+ .unwrap();
+
+ let mut cmd = wt_command();
+ cmd.current_dir(repo.root_path());
+ cmd.env("CLICOLOR_FORCE", "1");
+ cmd.args(["config", "state", "clear"]);
+ cmd.stdin(Stdio::null());
+ let output = cmd.output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+
+ ❯ Clear all stored state, including branch markers and vars? [y/N/?] ○ Clear cancelled
+ ");
+
+ // Previous branch must survive the declined prompt.
+ assert!(
+ repo.git_command()
+ .args(["config", "--get", "worktrunk.history"])
+ .run()
+ .unwrap()
+ .status
+ .success()
+ );
+}
+
+/// Answering `y` at the prompt clears everything (covers the accepted branch).
+#[rstest]
+fn test_state_clear_all_prompt_accepts(repo: TestRepo) {
+ repo.git_command()
+ .args(["config", "worktrunk.history", "feature"])
+ .run()
+ .unwrap();
+
+ let output = clear_all_with_stdin(&repo, "y\n");
+ assert!(output.status.success());
+ assert!(
+ String::from_utf8_lossy(&output.stderr).contains("Cleared previous branch"),
+ "stderr: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ assert!(
+ !repo
+ .git_command()
+ .args(["config", "--get", "worktrunk.history"])
+ .run()
+ .unwrap()
+ .status
+ .success(),
+ "previous branch should be cleared after accepting"
+ );
+}
+
+// ============================================================================
+// cache
+// ============================================================================
+
+/// `wt config state cache` (no subcommand) defaults to `get`.
+#[rstest]
+fn test_state_cache_bare_get_empty(repo: TestRepo) {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ cmd.args(["config", "state", "cache"]);
+ cmd.current_dir(repo.root_path());
+ let output = cmd.output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stdout), @"
+ PREVIOUS BRANCH
+   (none)
+
+ CI STATUS CACHE
+   (none)
+
+ SUMMARY CACHE
+   (none)
+
+ GIT COMMANDS CACHE
+   (none)
+
+ HINTS
+   (none)
+ ");
+}
+
+#[rstest]
+fn test_state_cache_get_json_empty(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "cache", "get", &["--format=json"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stdout), @r#"
+ {
+ "ci_status": [],
+ "git_commands_cache": 0,
+ "hints": [],
+ "previous_branch": null,
+ "summaries": []
+ }
+ "#);
+}
+
+#[rstest]
+fn test_state_cache_clear_empty(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "cache", "clear", &[]).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No cache to clear");
+}
+
+#[rstest]
+fn test_state_cache_clear_with_entries(repo: TestRepo) {
+ // Seed every regenerable cache category.
+ repo.git_command()
+ .args(["config", "worktrunk.history", "feature"])
+ .run()
+ .unwrap();
+ write_ci_cache(
+ &repo,
+ "feature",
+ r#"{"checked_at":1704067200,"head":"abc123","branch":"feature"}"#,
+ );
+ write_summary_cache(&repo, "feature", "aaaaaaaaaaaaaaaa", "Short summary", 0);
+ let git_dir = repo.root_path().join(".git");
+ let sha_cache_dir = git_dir.join("wt/cache/merge-tree-conflicts");
+ std::fs::create_dir_all(&sha_cache_dir).unwrap();
+ std::fs::write(sha_cache_dir.join("abc123-def456.json"), "true").unwrap();
+ repo.git_command()
+ .args(["config", "worktrunk.hints.worktree-path", "1"])
+ .run()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "cache", "clear", &[]).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ✓ Cleared previous branch
+ ✓ Cleared 1 CI cache entry
+ ✓ Cleared 1 summary cache entry
+ ✓ Cleared 1 git commands cache entry
+ ✓ Cleared 1 hint
+ ");
+}
+
+/// `cache clear` must leave authoritative state (markers, vars,
+/// default-branch override) untouched — only regenerable caches are dropped.
+#[rstest]
+fn test_state_cache_clear_preserves_authoritative(repo: TestRepo) {
+ repo.set_marker("main", "🚧");
+ repo.git_command()
+ .args(["config", "worktrunk.state.main.vars.env", "staging"])
+ .run()
+ .unwrap();
+ repo.git_command()
+ .args(["config", "worktrunk.history", "feature"])
+ .run()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "cache", "clear", &[]).output().unwrap();
+ assert!(output.status.success());
+
+ // Regenerable: previous branch is cleared.
+ assert!(
+ !repo
+ .git_command()
+ .args(["config", "--get", "worktrunk.history"])
+ .run()
+ .unwrap()
+ .status
+ .success(),
+ "previous branch (cache) should be cleared"
+ );
+ // Authoritative: marker and var survive.
+ assert!(
+ repo.git_command()
+ .args(["config", "--get", "worktrunk.state.main.marker"])
+ .run()
+ .unwrap()
+ .status
+ .success(),
+ "marker should survive cache clear"
+ );
+ assert!(
+ repo.git_command()
+ .args(["config", "--get", "worktrunk.state.main.vars.env"])
+ .run()
+ .unwrap()
+ .status
+ .success(),
+ "var should survive cache clear"
+ );
+}
+
+/// The subcommands folded into `cache` (ci-status, hints, previous-branch)
+/// still work but print a deprecation notice on stderr.
+#[rstest]
+fn test_state_deprecated_subcommands_warn(repo: TestRepo) {
+ for name in ["ci-status", "hints", "previous-branch"] {
+ let output = wt_state_cmd(&repo, name, "get", &[]).output().unwrap();
+ assert!(output.status.success(), "{name} get should succeed");
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains(&format!("wt config state {name} is deprecated; use"))
+ && stderr.contains("wt config state cache"),
+ "{name} should warn: {stderr}"
+ );
+ }
+}
+
// ============================================================================
// state get
// ============================================================================
@@ -1449,7 +1703,10 @@ fn test_state_clear_ci_status_all_with_entries(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared 2 CI cache entries");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
+ ✓ Cleared 2 CI cache entries
+ ");
}
#[rstest]
@@ -1467,7 +1724,10 @@ fn test_state_clear_ci_status_all_single_entry(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared 1 CI cache entry");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
+ ✓ Cleared 1 CI cache entry
+ ");
}
#[rstest]
@@ -1493,7 +1753,10 @@ fn test_state_clear_ci_status_specific_branch(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared CI cache for feature");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
+ ✓ Cleared CI cache for feature
+ ");
assert!(
!cache_file.exists(),
"cache file should be gone after clear"
@@ -1514,7 +1777,10 @@ fn test_state_clear_ci_status_specific_branch_not_cached(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No CI cache for feature");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state ci-status is deprecated; use wt config state cache instead
+ ○ No CI cache for feature
+ ");
assert!(!cache_file.exists(), "cache file should still not exist");
}
@@ -1579,7 +1845,10 @@ fn test_state_clear_marker_all_single(repo: TestRepo) {
fn test_state_hints_get_empty(repo: TestRepo) {
let output = wt_state_cmd(&repo, "hints", "get", &[]).output().unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No hints have been shown");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state hints is deprecated; use wt config state cache instead
+ ○ No hints have been shown
+ ");
}
#[rstest]
@@ -1606,7 +1875,10 @@ fn test_state_hints_get_with_hints(repo: TestRepo) {
fn test_state_hints_clear_empty(repo: TestRepo) {
let output = wt_state_cmd(&repo, "hints", "clear", &[]).output().unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ No hints to clear");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state hints is deprecated; use wt config state cache instead
+ ○ No hints to clear
+ ");
}
#[rstest]
@@ -1623,7 +1895,10 @@ fn test_state_hints_clear_all(repo: TestRepo) {
let output = wt_state_cmd(&repo, "hints", "clear", &[]).output().unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared 2 hints");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state hints is deprecated; use wt config state cache instead
+ ✓ Cleared 2 hints
+ ");
// Verify hints were cleared
let output = repo
@@ -1644,7 +1919,10 @@ fn test_state_hints_clear_single(repo: TestRepo) {
let output = wt_state_cmd(&repo, "hints", "clear", &[]).output().unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared 1 hint");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state hints is deprecated; use wt config state cache instead
+ ✓ Cleared 1 hint
+ ");
}
#[rstest]
@@ -1663,7 +1941,10 @@ fn test_state_hints_clear_specific(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"✓ Cleared hint worktree-path");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state hints is deprecated; use wt config state cache instead
+ ✓ Cleared hint worktree-path
+ ");
// Verify only that hint was cleared
let output = repo
@@ -1687,7 +1968,10 @@ fn test_state_hints_clear_specific_not_set(repo: TestRepo) {
.output()
.unwrap();
assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"○ Hint nonexistent was not set");
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ▲ wt config state hints is deprecated; use wt config state cache instead
+ ○ Hint nonexistent was not set
+ ");
}
// ============================================================================
diff --git a/tests/integration_tests/help.rs b/tests/integration_tests/help.rs
index d5ac23ce4..a3c692540 100644
--- a/tests/integration_tests/help.rs
+++ b/tests/integration_tests/help.rs
@@ -84,6 +84,7 @@ fn snapshot_help(test_name: &str, args: &[&str]) {
"config plugins codex install --help"
)]
#[case("help_config_state", "config state --help")]
+#[case("help_config_state_cache", "config state cache --help")]
#[case(
"help_config_state_default_branch",
"config state default-branch --help"
diff --git a/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_add.snap b/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_add.snap
index a9e2ee910..60a139091 100644
--- a/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_add.snap
+++ b/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_add.snap
@@ -12,32 +12,43 @@ info:
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
NO_COLOR: ""
OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
PATH: "[PATH]"
PSModulePath: ""
- RUST_LOG: warn
SHELL: ""
TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: false
@@ -45,6 +56,6 @@ exit_code: 1
----- stdout -----
----- stderr -----
-▲ wt hook approvals is deprecated; use wt config approvals instead
+▲ wt hook approvals is deprecated; use wt config approvals instead
✗ No project configuration found
↳ Create a config file at: _REPO_/.config/wt.toml
diff --git a/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_clear.snap b/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_clear.snap
index 3b4729f6b..689de96a6 100644
--- a/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_clear.snap
+++ b/tests/snapshots/integration__integration_tests__approvals__hook_approvals_deprecated_clear.snap
@@ -12,32 +12,43 @@ info:
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
NO_COLOR: ""
OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
PATH: "[PATH]"
PSModulePath: ""
- RUST_LOG: warn
SHELL: ""
TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
@@ -45,5 +56,5 @@ exit_code: 0
----- stdout -----
----- stderr -----
-▲ wt hook approvals is deprecated; use wt config approvals instead
+▲ wt hook approvals is deprecated; use wt config approvals instead
○ No approvals to clear for this project
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state.snap b/tests/snapshots/integration__integration_tests__help__help_config_state.snap
index b7534e3eb..c488f45cc 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state.snap
@@ -42,15 +42,13 @@ wt config state - Manage internal data and cache
Usage: wt config state [OPTIONS] <COMMAND>
Commands:
- get Get all stored state
- clear Clear all stored state
- default-branch Default branch detection and override
- previous-branch Previous branch (for wt switch -)
- logs Operation and debug logs
- hints One-time hints shown in this repo
- ci-status CI status cache
- marker Branch markers
- vars [experimental] Custom variables per branch
+ get Get all stored state
+ clear Clear all stored state
+ cache Regenerable caches
+ default-branch Default branch detection and override
+ logs Operation and debug logs
+ marker Branch markers
+ vars [experimental] Custom variables per branch
Options:
-h, --help
@@ -73,12 +71,11 @@ State is stored in .git/ (config entries and log files), separate from c
Keys
+- cache: Regenerable caches — CI status, summaries, git commands, hints, and the wt switch - target
- default-branch: The repository's default branch (main, master, etc.)
-- previous-branch: Previous branch for wt switch -
-- logs: Operation and debug logs
-- ci-status: CI/PR status for a branch (passed, running, failed, conflicts, no-ci, error)
- marker: Custom status marker for a branch (shown in wt list)
- vars: [experimental] Custom variables per branch
+- logs: Operation and debug logs
Examples
@@ -94,8 +91,8 @@ Set a marker for current branch:
Store arbitrary data:
  wt config state vars set env=staging
-Clear all CI status cache:
-  wt config state ci-status clear --all
+Drop the regenerable caches:
+  wt config state cache clear
Show all stored state:
  wt config state get
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_cache.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_cache.snap
new file mode 100644
index 000000000..b1fc81588
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_cache.snap
@@ -0,0 +1,92 @@
+---
+source: tests/integration_tests/help.rs
+info:
+ program: wt
+ args:
+ - config
+ - state
+ - cache
+ - "--help"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ NO_COLOR: ""
+ PSModulePath: ""
+ SHELL: ""
+ TERM: alacritty
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+---
+success: true
+exit_code: 0
+----- stdout -----
+wt config state cache - Regenerable caches
+
+Usage: wt config state cache [OPTIONS] [COMMAND]
+
+Commands:
+ get Show cache contents
+ clear Drop all caches
+
+Options:
+ -h, --help
+ Print help (see a summary with '-h')
+
+Output:
+ --format <FORMAT>
+ Output format (text, json) [default: text]
+
+Global Options:
+ -C <path>
+ Working directory for this command
+
+ --config <path>
+ User config file path
+
+ -v, --verbose...
+ Verbose output (-v: info logs + hook/alias template variables on stderr; -vv: also debug logs and raw subprocess output written to .git/wt/logs/)
+
+ -y, --yes
+ Skip approval prompts
+
+View or drop worktrunk's regenerable caches in one place. Everything here is rebuilt on demand — clearing only forces recomputation, never data loss.
+
+What's cached
+
+- CI status — GitHub/GitLab CI per branch (30–60s TTL), shown in wt list
+- Summaries — LLM-generated branch summaries (wt list --full, wt switch preview)
+- Git commands — SHA-keyed disk caches: merge-tree, ancestry, diff-stats, and wt switch preview renders
+- Hints — one-time hints already shown in this repo
+- Previous branch — the wt switch - target, re-recorded on the next switch
+
+cache clear drops all of the above with no prompt. It re-shows one-time hints and forgets the wt switch - target until the next switch — both repopulate on their own.
+
+Without a subcommand, runs get.
+
+Examples
+
+Show cache contents:
+  wt config state cache
+
+Drop all caches:
+  wt config state cache clear
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
index bd3c0a54a..e11320526 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
@@ -67,6 +67,8 @@ Usage: wt config state ci-status [OPTIONS] [COMMAND]
-y, --yes
Skip approval prompts
+Deprecated — the CI status cache is now part of wt config state cache. This subcommand still works but prints a deprecation notice.
+
Caches GitHub/GitLab CI status for display in wt list.
Requires gh (GitHub) or glab (GitLab) CLI, authenticated. Platform auto-detects from the remote URL; set forge.platform = "github" (or "gitlab") in .config/wt.toml for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set forge.hostname.
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_clear.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_clear.snap
index 80ba2f394..eae5e32a9 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_clear.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_clear.snap
@@ -70,7 +70,12 @@ Clears all stored state:
- All log files
- Stale trash from worktree removal (.git/wt/trash/)
-Use individual subcommands (default-branch clear, ci-status clear --all, etc.)
-to clear specific state.
+Prompts for confirmation before clearing, since this removes hand-authored
+markers and vars. Pass --yes to skip the prompt.
+
+To drop only the regenerable caches (CI status, summaries, git commands,
+hints, previous branch), run wt config state cache clear — it needs no
+confirmation and leaves markers, vars, and the default-branch override
+untouched.
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_previous_branch.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_previous_branch.snap
index c61adc40f..2ac5abbdb 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_previous_branch.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_previous_branch.snap
@@ -64,6 +64,8 @@ Usage: wt config state previous-branch [OPTIONS] [COM
-y, --yes
Skip approval prompts
+Deprecated — the previous branch is now part of wt config state cache. This subcommand still works but prints a deprecation notice.
+
Enables wt switch - to return to the previous worktree, similar to cd - or git checkout -.
How it works
diff --git a/tests/snapshots/integration__integration_tests__switch__select_deprecated_requires_tty.snap b/tests/snapshots/integration__integration_tests__switch__select_deprecated_requires_tty.snap
index 0da6f6169..7d312e93d 100644
--- a/tests/snapshots/integration__integration_tests__switch__select_deprecated_requires_tty.snap
+++ b/tests/snapshots/integration__integration_tests__switch__select_deprecated_requires_tty.snap
@@ -28,7 +28,6 @@ info:
OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
PATH: "[PATH]"
PSModulePath: ""
- RUST_LOG: warn
SHELL: ""
TERM: alacritty
USERPROFILE: "[TEST_HOME]"
@@ -55,5 +54,5 @@ exit_code: 1
----- stdout -----
----- stderr -----
-▲ wt select is deprecated; use wt switch instead
+▲ wt select is deprecated; use wt switch instead
✗ Interactive picker requires an interactive terminal