Skip to content

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

feat: add `wt step eval` for template expression evaluation (#1004)

Maximilian Roosa7f224d263df
diff --git a/docs/content/step.md b/docs/content/step.md
index 9130e149c..15b997a73 100644
--- a/docs/content/step.md
+++ b/docs/content/step.md
@@ -36,6 +36,7 @@ wt step push
- `push` — Fast-forward target to current branch
- [`diff`](#wt-step-diff) — Show all changes since branching (committed, staged, unstaged, untracked)
- [`copy-ignored`](#wt-step-copy-ignored) — Copy gitignored files between worktrees
+- [`eval`](#wt-step-eval) — <span class="badge-experimental"></span> Evaluate a template expression
- [`for-each`](#wt-step-for-each) — <span class="badge-experimental"></span> Run a command in every worktree
- [`promote`](#wt-step-promote) — <span class="badge-experimental"></span> Swap a branch into the main worktree
- [`prune`](#wt-step-prune) — Remove worktrees and branches merged into the default branch
@@ -64,6 +65,7 @@ Usage: <b><span class=c>wt step</span></b> <span class=c>[OPTIONS]</span> <span
<b><span class=c>rebase</span></b> Rebase onto target
<b><span class=c>diff</span></b> Show all changes since branching
<b><span class=c>copy-ignored</span></b> Copy gitignored files to another worktree
+ <b><span class=c>eval</span></b> [experimental] Evaluate a template expression
<b><span class=c>for-each</span></b> [experimental] Run command in each worktree
<b><span class=c>promote</span></b> [experimental] Swap a branch into the main worktree
<b><span class=c>prune</span></b> [experimental] Remove worktrees merged into the default branch
@@ -451,6 +453,86 @@ Usage: <b><span class=c>wt step copy-ignored</span></b> <span class=c>[OPTIONS]<
Verbose output (-v: hooks, templates; -vv: debug report)
{% end %}
+## wt step eval <span class="badge-experimental"></span>
+
+Evaluate a template expression. Prints the result to stdout for use in scripts and shell substitutions.
+
+Evaluates a template expression in the current worktree context and prints the result to stdout. All [hook template variables and filters](@/hook.md#template-variables) are available.
+
+Output goes to stdout with no decoration, making it suitable for shell substitution and piping.
+
+### Examples
+
+Get the port for the current branch:
+
+```bash
+$ wt step eval '{{ branch | hash_port }}'
+16066
+```
+
+Use in shell substitution:
+
+```bash
+$ curl http://localhost:$(wt step eval '{{ branch | hash_port }}')/health
+```
+
+Combine multiple values:
+
+```bash
+$ wt step eval '{{ branch | hash_port }},{{ ("supabase-api-" ~ branch) | hash_port }}'
+16066,16739
+```
+
+Use conditionals and filters:
+
+```bash
+$ wt step eval '{{ branch | sanitize_db }}'
+feature_auth_oauth2_a1b
+```
+
+Show available template variables:
+
+```bash
+$ wt step eval --dry-run '{{ branch }}'
+branch=feature/auth-oauth2
+worktree_path=/home/user/projects/myapp-feature-auth-oauth2
+...
+Result: feature/auth-oauth2
+```
+
+Note: This command is experimental and may change in future versions.
+
+### Command reference
+
+{% terminal() %}
+wt step eval - [experimental] Evaluate a template expression
+
+Prints the result to stdout for use in scripts and shell substitutions.
+
+Usage: <b><span class=c>wt step eval</span></b> <span class=c>[OPTIONS]</span> <span class=c>&lt;TEMPLATE&gt;</span>
+
+<b><span class=g>Arguments:</span></b>
+ <span class=c>&lt;TEMPLATE&gt;</span>
+ Template expression to evaluate
+
+<b><span class=g>Options:</span></b>
+ <b><span class=c>--dry-run</span></b>
+ Show template variables and expanded result
+
+ <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: hooks, templates; -vv: debug report)
+{% end %}
+
## wt step for-each <span class="badge-experimental"></span>
Run command in each worktree. Executes sequentially with real-time output; continues on failure.
diff --git a/skills/worktrunk/reference/step.md b/skills/worktrunk/reference/step.md
index 4d5e5e0f6..503023078 100644
--- a/skills/worktrunk/reference/step.md
+++ b/skills/worktrunk/reference/step.md
@@ -27,6 +27,7 @@ wt step push
- `push` — Fast-forward target to current branch
- [`diff`](#wt-step-diff) — Show all changes since branching (committed, staged, unstaged, untracked)
- [`copy-ignored`](#wt-step-copy-ignored) — Copy gitignored files between worktrees
+- [`eval`](#wt-step-eval) — [experimental] Evaluate a template expression
- [`for-each`](#wt-step-for-each) — [experimental] Run a command in every worktree
- [`promote`](#wt-step-promote) — [experimental] Swap a branch into the main worktree
- [`prune`](#wt-step-prune) — Remove worktrees and branches merged into the default branch
@@ -49,6 +50,7 @@ Usage: <b><span class=c>wt step</span></b> <span class=c>[OPTIONS]</span> <span
<b><span class=c>rebase</span></b> Rebase onto target
<b><span class=c>diff</span></b> Show all changes since branching
<b><span class=c>copy-ignored</span></b> Copy gitignored files to another worktree
+ <b><span class=c>eval</span></b> [experimental] Evaluate a template expression
<b><span class=c>for-each</span></b> [experimental] Run command in each worktree
<b><span class=c>promote</span></b> [experimental] Swap a branch into the main worktree
<b><span class=c>prune</span></b> [experimental] Remove worktrees merged into the default branch
@@ -427,6 +429,84 @@ Usage: <b><span class=c>wt step copy-ignored</span></b> <span class=c>[OPTIONS]<
<b><span class=c>-v</span></b>, <b><span class=c>--verbose</span></b><span class=c>...</span>
Verbose output (-v: hooks, templates; -vv: debug report)
+## wt step eval [experimental]
+
+Evaluate a template expression. Prints the result to stdout for use in scripts and shell substitutions.
+
+Evaluates a template expression in the current worktree context and prints the result to stdout. All [hook template variables and filters](https://worktrunk.dev/hook/#template-variables) are available.
+
+Output goes to stdout with no decoration, making it suitable for shell substitution and piping.
+
+### Examples
+
+Get the port for the current branch:
+
+```bash
+$ wt step eval '{{ branch | hash_port }}'
+16066
+```
+
+Use in shell substitution:
+
+```bash
+$ curl http://localhost:$(wt step eval '{{ branch | hash_port }}')/health
+```
+
+Combine multiple values:
+
+```bash
+$ wt step eval '{{ branch | hash_port }},{{ ("supabase-api-" ~ branch) | hash_port }}'
+16066,16739
+```
+
+Use conditionals and filters:
+
+```bash
+$ wt step eval '{{ branch | sanitize_db }}'
+feature_auth_oauth2_a1b
+```
+
+Show available template variables:
+
+```bash
+$ wt step eval --dry-run '{{ branch }}'
+branch=feature/auth-oauth2
+worktree_path=/home/user/projects/myapp-feature-auth-oauth2
+...
+Result: feature/auth-oauth2
+```
+
+Note: This command is experimental and may change in future versions.
+
+### Command reference
+
+wt step eval - [experimental] Evaluate a template expression
+
+Prints the result to stdout for use in scripts and shell substitutions.
+
+Usage: <b><span class=c>wt step eval</span></b> <span class=c>[OPTIONS]</span> <span class=c>&lt;TEMPLATE&gt;</span>
+
+<b><span class=g>Arguments:</span></b>
+ <span class=c>&lt;TEMPLATE&gt;</span>
+ Template expression to evaluate
+
+<b><span class=g>Options:</span></b>
+ <b><span class=c>--dry-run</span></b>
+ Show template variables and expanded result
+
+ <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: hooks, templates; -vv: debug report)
+
## wt step for-each [experimental]
Run command in each worktree. Executes sequentially with real-time output; continues on failure.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index e8466aad1..f6df4a890 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -1033,6 +1033,7 @@ wt step push
- `push` — Fast-forward target to current branch
- [`diff`](#wt-step-diff) — Show all changes since branching (committed, staged, unstaged, untracked)
- [`copy-ignored`](#wt-step-copy-ignored) — Copy gitignored files between worktrees
+- [`eval`](#wt-step-eval) — [experimental] Evaluate a template expression
- [`for-each`](#wt-step-for-each) — [experimental] Run a command in every worktree
- [`promote`](#wt-step-promote) — [experimental] Swap a branch into the main worktree
- [`prune`](#wt-step-prune) — Remove worktrees and branches merged into the default branch
@@ -1048,6 +1049,7 @@ wt step push
<!-- subdoc: squash -->
<!-- subdoc: diff -->
<!-- subdoc: copy-ignored -->
+<!-- subdoc: eval -->
<!-- subdoc: for-each -->
<!-- subdoc: promote -->
<!-- subdoc: prune -->
diff --git a/src/cli/step.rs b/src/cli/step.rs
index c7f647ec8..2c3e95fa7 100644
--- a/src/cli/step.rs
+++ b/src/cli/step.rs
@@ -326,6 +326,65 @@ The `.worktreeinclude` pattern is shared with [Claude Code on desktop](https://c
force: bool,
},
+ /// \[experimental\] Evaluate a template expression
+ ///
+ /// Prints the result to stdout for use in scripts and shell substitutions.
+ #[command(
+ after_long_help = r#"Evaluates a template expression in the current worktree context and prints the result to stdout. All [hook template variables and filters](@/hook.md#template-variables) are available.
+
+Output goes to stdout with no decoration, making it suitable for shell substitution and piping.
+
+## Examples
+
+Get the port for the current branch:
+
+```console
+$ wt step eval '{{ branch | hash_port }}'
+16066
+```
+
+Use in shell substitution:
+
+```console
+$ curl http://localhost:$(wt step eval '{{ branch | hash_port }}')/health
+```
+
+Combine multiple values:
+
+```console
+$ wt step eval '{{ branch | hash_port }},{{ ("supabase-api-" ~ branch) | hash_port }}'
+16066,16739
+```
+
+Use conditionals and filters:
+
+```console
+$ wt step eval '{{ branch | sanitize_db }}'
+feature_auth_oauth2_a1b
+```
+
+Show available template variables:
+
+```console
+$ wt step eval --dry-run '{{ branch }}'
+branch=feature/auth-oauth2
+worktree_path=/home/user/projects/myapp-feature-auth-oauth2
+...
+Result: feature/auth-oauth2
+```
+
+Note: This command is experimental and may change in future versions.
+"#
+ )]
+ Eval {
+ /// Template expression to evaluate
+ template: String,
+
+ /// Show template variables and expanded result
+ #[arg(long)]
+ dry_run: bool,
+ },
+
/// \[experimental\] Run command in each worktree
///
/// Executes sequentially with real-time output; continues on failure.
diff --git a/src/commands/alias.rs b/src/commands/alias.rs
index 32f35cabe..391cc0330 100644
--- a/src/commands/alias.rs
+++ b/src/commands/alias.rs
@@ -28,6 +28,7 @@ const BUILTIN_STEP_COMMANDS: &[&str] = &[
"commit",
"copy-ignored",
"diff",
+ "eval",
"for-each",
"promote",
"prune",
diff --git a/src/commands/eval.rs b/src/commands/eval.rs
new file mode 100644
index 000000000..e39bb4db0
--- /dev/null
+++ b/src/commands/eval.rs
@@ -0,0 +1,53 @@
+//! Eval command implementation
+//!
+//! Evaluates a template expression in the current worktree context and prints
+//! the result to stdout. Designed for scripting — output is raw (no shell
+//! escaping, no decoration).
+
+use std::collections::HashMap;
+
+use worktrunk::config::{UserConfig, expand_template};
+use worktrunk::git::Repository;
+
+use crate::commands::command_executor::{CommandContext, build_hook_context};
+
+/// Evaluate a template expression in the current worktree context.
+///
+/// Prints the expanded result to stdout with a trailing newline. All hook
+/// template variables and filters are available.
+///
+/// With `dry_run`, prints the template variables and the expanded result
+/// With `dry_run`, prints the template variables and the expanded result
+/// to stderr — useful for debugging templates.
+pub fn step_eval(template: &str, dry_run: bool) -> anyhow::Result<()> {
+ let repo = Repository::current()?;
+ let config = UserConfig::load()?;
+
+ let wt = repo.current_worktree();
+ let branch = wt.branch()?;
+ let worktree_path = wt.root()?;
+
+ let ctx = CommandContext::new(&repo, &config, branch.as_deref(), &worktree_path, false);
+ let context_map = build_hook_context(&ctx, &[])?;
+
+ let vars: HashMap<&str, &str> = context_map
+ .iter()
+ .map(|(k, v)| (k.as_str(), v.as_str()))
+ .collect();
+
+ // No shell escaping — output is literal for scripting
+ let result = expand_template(template, &vars, false, &repo, "eval")?;
+
+ if dry_run {
+ let mut keys: Vec<&str> = context_map.keys().map(|k| k.as_str()).collect();
+ keys.sort();
+ for key in keys {
+ eprintln!("{}={}", key, context_map[key]);
+ }
+ eprintln!("---");
+ eprintln!("Result: {result}");
+ } else {
+ println!("{result}");
+ }
+ Ok(())
+}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index e6df7fc42..34207e998 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -6,6 +6,7 @@ pub(crate) mod commit;
pub(crate) mod config;
pub(crate) mod configure_shell;
pub(crate) mod context;
+mod eval;
mod for_each;
mod handle_switch;
mod hook_commands;
@@ -33,6 +34,7 @@ pub(crate) use config::{
pub(crate) use configure_shell::{
handle_configure_shell, handle_show_theme, handle_unconfigure_shell,
};
+pub(crate) use eval::step_eval;
pub(crate) use for_each::step_for_each;
pub(crate) use handle_switch::{SwitchOptions, handle_switch};
pub(crate) use hook_commands::{add_approvals, clear_approvals, handle_hook_show, run_hook};
diff --git a/src/main.rs b/src/main.rs
index 91ee13b6c..8a779be54 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -52,7 +52,7 @@ use commands::{
handle_rebase, handle_remove, handle_remove_current, handle_show_theme, handle_squash,
handle_state_clear, handle_state_clear_all, handle_state_get, handle_state_set,
handle_state_show, handle_switch, handle_unconfigure_shell, resolve_worktree_arg, run_hook,
- step_commit, step_copy_ignored, step_diff, step_for_each, step_prune, step_relocate,
+ step_commit, step_copy_ignored, step_diff, step_eval, step_for_each, step_prune, step_relocate,
};
use output::handle_remove_output;
@@ -286,6 +286,7 @@ fn handle_step_command(action: StepCommand) -> anyhow::Result<()> {
dry_run,
force,
} => step_copy_ignored(from.as_deref(), to.as_deref(), dry_run, force),
+ StepCommand::Eval { template, dry_run } => step_eval(&template, dry_run),
StepCommand::ForEach { args } => step_for_each(args),
StepCommand::Promote { branch } => {
handle_promote(branch.as_deref()).map(|result| match result {
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 92423ab12..ba3889b12 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -633,14 +633,15 @@ fn test_complete_step_subcommands(repo: TestRepo) {
"Missing copy-ignored"
);
assert!(subcommands.contains(&"diff"), "Missing diff");
+ assert!(subcommands.contains(&"eval"), "Missing eval");
assert!(subcommands.contains(&"for-each"), "Missing for-each");
assert!(subcommands.contains(&"promote"), "Missing promote");
assert!(subcommands.contains(&"prune"), "Missing prune");
assert!(subcommands.contains(&"relocate"), "Missing relocate");
assert_eq!(
subcommands.len(),
- 10,
- "Should have exactly 10 step subcommands"
+ 11,
+ "Should have exactly 11 step subcommands"
);
}
diff --git a/tests/integration_tests/eval.rs b/tests/integration_tests/eval.rs
new file mode 100644
index 000000000..37c131732
--- /dev/null
+++ b/tests/integration_tests/eval.rs
@@ -0,0 +1,81 @@
+//! Integration tests for `wt step eval`
+
+use crate::common::{TestRepo, make_snapshot_cmd, repo};
+use insta_cmd::assert_cmd_snapshot;
+use rstest::rstest;
+
+#[rstest]
+fn test_eval_branch(repo: TestRepo) {
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["eval", "{{ branch }}"],
+ None,
+ ));
+}
+
+#[rstest]
+fn test_eval_hash_port(repo: TestRepo) {
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["eval", "{{ branch | hash_port }}"],
+ None,
+ ));
+}
+
+#[rstest]
+fn test_eval_multiple_values(repo: TestRepo) {
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &[
+ "eval",
+ "{{ branch | hash_port }},{{ (\"supabase-api-\" ~ branch) | hash_port }}"
+ ],
+ None,
+ ));
+}
+
+#[rstest]
+fn test_eval_sanitize_db(repo: TestRepo) {
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["eval", "{{ branch | sanitize_db }}"],
+ None,
+ ));
+}
+
+#[rstest]
+fn test_eval_template_error(repo: TestRepo) {
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["eval", "{{ undefined_var }}"],
+ None,
+ ));
+}
+
+#[rstest]
+fn test_eval_dry_run(repo: TestRepo) {
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &["eval", "--dry-run", "{{ branch | hash_port }}"],
+ None,
+ ));
+}
+
+#[rstest]
+fn test_eval_conditional(repo: TestRepo) {
+ assert_cmd_snapshot!(make_snapshot_cmd(
+ &repo,
+ "step",
+ &[
+ "eval",
+ "{% if branch == 'main' %}production{% else %}development{% endif %}"
+ ],
+ None,
+ ));
+}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 9cd75106a..65a929ce1 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -29,6 +29,7 @@ pub mod directives;
pub mod doc_templates;
pub mod e2e_shell;
pub mod e2e_shell_post_start;
+pub mod eval;
pub mod for_each;
pub mod git_error_display;
pub mod help;
diff --git a/tests/integration_tests/output_system_guard.rs b/tests/integration_tests/output_system_guard.rs
index 53f5d880c..6d475db47 100644
--- a/tests/integration_tests/output_system_guard.rs
+++ b/tests/integration_tests/output_system_guard.rs
@@ -34,6 +34,8 @@ const STDOUT_ALLOWED_PATHS: &[&str] = &[
"config/state.rs",
// Hint list output
"config/hints.rs",
+ // Template evaluation output for scripting
+ "eval.rs",
// LLM prompt output for wt step commit --show-prompt
"step_commands.rs",
// --no-cd flag: branch name output for scripting
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_branch.snap b/tests/snapshots/integration__integration_tests__eval__eval_branch.snap
new file mode 100644
index 000000000..c995a20fd
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__eval__eval_branch.snap
@@ -0,0 +1,42 @@
+---
+source: tests/integration_tests/eval.rs
+info:
+ program: wt
+ args:
+ - step
+ - eval
+ - "{{ branch }}"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+main
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_conditional.snap b/tests/snapshots/integration__integration_tests__eval__eval_conditional.snap
new file mode 100644
index 000000000..da37747c4
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__eval__eval_conditional.snap
@@ -0,0 +1,42 @@
+---
+source: tests/integration_tests/eval.rs
+info:
+ program: wt
+ args:
+ - step
+ - eval
+ - "{% if branch == 'main' %}production{% else %}development{% endif %}"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+production
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_dry_run.snap b/tests/snapshots/integration__integration_tests__eval__eval_dry_run.snap
new file mode 100644
index 000000000..8feb8fc41
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__eval__eval_dry_run.snap
@@ -0,0 +1,64 @@
+---
+source: tests/integration_tests/eval.rs
+info:
+ program: wt
+ args:
+ - step
+ - eval
+ - "--dry-run"
+ - "{{ branch | hash_port }}"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ 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_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+branch=main
+commit=05a4a45d0b981dad5c27db59dca482836d59f89e
+default_branch=main
+main_worktree=repo
+main_worktree_path=_REPO_
+primary_worktree_path=_REPO_
+remote=origin
+remote_url=../origin.git
+repo=repo
+repo_path=_REPO_
+repo_root=_REPO_
+short_commit=05a4a45
+upstream=origin/main
+worktree=_REPO_
+worktree_name=repo
+worktree_path=_REPO_
+---
+Result: 12107
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_hash_port.snap b/tests/snapshots/integration__integration_tests__eval__eval_hash_port.snap
new file mode 100644
index 000000000..3d8a7690f
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__eval__eval_hash_port.snap
@@ -0,0 +1,42 @@
+---
+source: tests/integration_tests/eval.rs
+info:
+ program: wt
+ args:
+ - step
+ - eval
+ - "{{ branch | hash_port }}"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+12107
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_multiple_values.snap b/tests/snapshots/integration__integration_tests__eval__eval_multiple_values.snap
new file mode 100644
index 000000000..b671c7d64
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__eval__eval_multiple_values.snap
@@ -0,0 +1,42 @@
+---
+source: tests/integration_tests/eval.rs
+info:
+ program: wt
+ args:
+ - step
+ - eval
+ - "{{ branch | hash_port }},{{ (\"supabase-api-\" ~ branch) | hash_port }}"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+12107,14260
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_sanitize_db.snap b/tests/snapshots/integration__integration_tests__eval__eval_sanitize_db.snap
new file mode 100644
index 000000000..f1b3ddf7a
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__eval__eval_sanitize_db.snap
@@ -0,0 +1,42 @@
+---
+source: tests/integration_tests/eval.rs
+info:
+ program: wt
+ args:
+ - step
+ - eval
+ - "{{ branch | sanitize_db }}"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+main_vfz
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_template_error.snap b/tests/snapshots/integration__integration_tests__eval__eval_template_error.snap
new file mode 100644
index 000000000..598fff190
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__eval__eval_template_error.snap
@@ -0,0 +1,48 @@
+---
+source: tests/integration_tests/eval.rs
+info:
+ program: wt
+ args:
+ - step
+ - eval
+ - "{{ undefined_var }}"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ 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_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ Failed to expand eval: undefined value @ line 1
+  {{ undefined_var }}
+↳ Available variables: branch, commit, default_branch, main_worktree, main_worktree_path, primary_worktree_path, remote, remote_url, repo, repo_path, repo_root, short_commit, upstream, worktree, worktree_name, worktree_path
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_long.snap b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
index 9e4cb53c3..5a074abd7 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
@@ -44,6 +44,7 @@ Usage: wt step [OPTIONS] <COMMAND>
rebase Rebase onto target
diff Show all changes since branching
copy-ignored Copy gitignored files to another worktree
+ eval [experimental] Evaluate a template expression
for-each [experimental] Run command in each worktree
promote [experimental] Swap a branch into the main worktree
prune [experimental] Remove worktrees merged into the default branch
@@ -84,6 +85,7 @@ Manual merge workflow with review between steps:
- push — Fast-forward target to current branch
- diff — Show all changes since branching (committed, staged, unstaged, untracked)
- copy-ignored — Copy gitignored files between worktrees
+- eval — [experimental] Evaluate a template expression
- for-each — [experimental] Run a command in every worktree
- promote — [experimental] Swap a branch into the main worktree
- prune — Remove worktrees and branches merged into the default branch
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_short.snap b/tests/snapshots/integration__integration_tests__help__help_step_short.snap
index 93910c91c..b51f8e2a9 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_short.snap
@@ -42,6 +42,7 @@ Usage: wt step [OPTIONS] <COMMAND>
rebase Rebase onto target
diff Show all changes since branching
copy-ignored Copy gitignored files to another worktree
+ eval [experimental] Evaluate a template expression
for-each [experimental] Run command in each worktree
promote [experimental] Swap a branch into the main worktree
prune [experimental] Remove worktrees merged into the default branch