Skip to content

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

Add {{ owner }} template variable for worktree paths (#2051)

Gregg Donovan3e8799ae2748
diff --git a/dev/config.example.toml b/dev/config.example.toml
index 250264a02..6e6dfd3b5 100644
--- a/dev/config.example.toml
+++ b/dev/config.example.toml
@@ -15,6 +15,7 @@
#
# - `{{ repo_path }}` — absolute path to the repository root (e.g., `/Users/me/code/myproject`. Or for bare repos, the bare directory itself)
# - `{{ repo }}` — repository directory name (e.g., `myproject`)
+# - `{{ owner }}` — primary remote owner path (may include subgroups like `group/subgroup`)
# - `{{ branch }}` — raw branch name (e.g., `feature/auth`)
# - `{{ branch | sanitize }}` — filesystem-safe: `/` and `\` become `-` (e.g., `feature-auth`)
# - `{{ branch | sanitize_db }}` — database-safe: lowercase, underscores, hash suffix (e.g., `feature_auth_x7k`)
@@ -33,6 +34,10 @@
#
# worktree-path = "~/worktrees/{{ repo }}/{{ branch | sanitize }}"
#
+# By remote owner path (`~/development/max-sixty/myproject/feature/auth`):
+#
+# worktree-path = "~/development/{{ owner }}/{{ repo }}/{{ branch }}"
+#
# Bare repository (`~/code/myproject/feature-auth`):
#
# worktree-path = "{{ repo_path }}/../{{ branch | sanitize }}"
diff --git a/docs/content/config.md b/docs/content/config.md
index 6a289b650..7966ce972 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -77,6 +77,7 @@ Controls where new worktrees are created.
- `{{ repo_path }}` — absolute path to the repository root (e.g., `/Users/me/code/myproject`. Or for bare repos, the bare directory itself)
- `{{ repo }}` — repository directory name (e.g., `myproject`)
+- `{{ owner }}` — primary remote owner path (may include subgroups like `group/subgroup`)
- `{{ branch }}` — raw branch name (e.g., `feature/auth`)
- `{{ branch | sanitize }}` — filesystem-safe: `/` and `\` become `-` (e.g., `feature-auth`)
- `{{ branch | sanitize_db }}` — database-safe: lowercase, underscores, hash suffix (e.g., `feature_auth_x7k`)
@@ -101,6 +102,12 @@ Centralized worktrees directory (`~/worktrees/myproject/feature-auth`):
worktree-path = "~/worktrees/{{ repo }}/{{ branch | sanitize }}"
```
+By remote owner path (`~/development/max-sixty/myproject/feature/auth`):
+
+```toml
+worktree-path = "~/development/{{ owner }}/{{ repo }}/{{ branch }}"
+```
+
Bare repository (`~/code/myproject/feature-auth`):
```toml
diff --git a/docs/content/hook.md b/docs/content/hook.md
index 1b6eb4477..2f5bd6df0 100644
--- a/docs/content/hook.md
+++ b/docs/content/hook.md
@@ -112,6 +112,7 @@ Hooks can use template variables that expand at runtime:
| `{{ cwd }}` | Directory where the hook command runs |
| `{{ repo }}` | Repository directory name |
| `{{ repo_path }}` | Absolute path to repository root |
+| `{{ owner }}` | Primary remote owner path (may include subgroups) |
| `{{ primary_worktree_path }}` | Primary worktree path |
| `{{ default_branch }}` | Default branch name |
| `{{ remote }}` | Primary remote name |
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index 305179bd2..7eb64cd8a 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -76,6 +76,7 @@ Controls where new worktrees are created.
- `{{ repo_path }}` — absolute path to the repository root (e.g., `/Users/me/code/myproject`. Or for bare repos, the bare directory itself)
- `{{ repo }}` — repository directory name (e.g., `myproject`)
+- `{{ owner }}` — primary remote owner path (may include subgroups like `group/subgroup`)
- `{{ branch }}` — raw branch name (e.g., `feature/auth`)
- `{{ branch | sanitize }}` — filesystem-safe: `/` and `\` become `-` (e.g., `feature-auth`)
- `{{ branch | sanitize_db }}` — database-safe: lowercase, underscores, hash suffix (e.g., `feature_auth_x7k`)
@@ -100,6 +101,12 @@ Centralized worktrees directory (`~/worktrees/myproject/feature-auth`):
worktree-path = "~/worktrees/{{ repo }}/{{ branch | sanitize }}"
```
+By remote owner path (`~/development/max-sixty/myproject/feature/auth`):
+
+```toml
+worktree-path = "~/development/{{ owner }}/{{ repo }}/{{ branch }}"
+```
+
Bare repository (`~/code/myproject/feature-auth`):
```toml
diff --git a/skills/worktrunk/reference/hook.md b/skills/worktrunk/reference/hook.md
index 43d05c6d2..bd8a1df94 100644
--- a/skills/worktrunk/reference/hook.md
+++ b/skills/worktrunk/reference/hook.md
@@ -103,6 +103,7 @@ Hooks can use template variables that expand at runtime:
| `{{ cwd }}` | Directory where the hook command runs |
| `{{ repo }}` | Repository directory name |
| `{{ repo_path }}` | Absolute path to repository root |
+| `{{ owner }}` | Primary remote owner path (may include subgroups) |
| `{{ primary_worktree_path }}` | Primary worktree path |
| `{{ default_branch }}` | Default branch name |
| `{{ remote }}` | Primary remote name |
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 478341ef0..bd5ff60ae 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -1276,6 +1276,7 @@ Hooks can use template variables that expand at runtime:
| `{{ cwd }}` | Directory where the hook command runs |
| `{{ repo }}` | Repository directory name |
| `{{ repo_path }}` | Absolute path to repository root |
+| `{{ owner }}` | Primary remote owner path (may include subgroups) |
| `{{ primary_worktree_path }}` | Primary worktree path |
| `{{ default_branch }}` | Default branch name |
| `{{ remote }}` | Primary remote name |
@@ -1708,6 +1709,7 @@ Controls where new worktrees are created.
- `{{ repo_path }}` — absolute path to the repository root (e.g., `/Users/me/code/myproject`. Or for bare repos, the bare directory itself)
- `{{ repo }}` — repository directory name (e.g., `myproject`)
+- `{{ owner }}` — primary remote owner path (may include subgroups like `group/subgroup`)
- `{{ branch }}` — raw branch name (e.g., `feature/auth`)
- `{{ branch | sanitize }}` — filesystem-safe: `/` and `\` become `-` (e.g., `feature-auth`)
- `{{ branch | sanitize_db }}` — database-safe: lowercase, underscores, hash suffix (e.g., `feature_auth_x7k`)
@@ -1732,6 +1734,12 @@ Centralized worktrees directory (`~/worktrees/myproject/feature-auth`):
worktree-path = "~/worktrees/{{ repo }}/{{ branch | sanitize }}"
```
+By remote owner path (`~/development/max-sixty/myproject/feature/auth`):
+
+```toml
+worktree-path = "~/development/{{ owner }}/{{ repo }}/{{ branch }}"
+```
+
Bare repository (`~/code/myproject/feature-auth`):
```toml
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index dcfa65c14..3eb083d98 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -112,6 +112,10 @@ pub fn build_hook_context(
map.insert("repo_root".into(), repo_path);
map.insert("worktree".into(), worktree);
+ if let Some(parsed_remote) = ctx.repo.primary_remote_parsed_url() {
+ map.insert("owner".into(), parsed_remote.owner().to_string());
+ }
+
// Default branch
if let Some(default_branch) = ctx.repo.default_branch() {
map.insert("default_branch".into(), default_branch);
diff --git a/src/config/expansion.rs b/src/config/expansion.rs
index 7afa0aeda..998452cdc 100644
--- a/src/config/expansion.rs
+++ b/src/config/expansion.rs
@@ -30,6 +30,7 @@ use crate::styling::{
/// This list is the single source of truth for `--var` validation in CLI.
pub const TEMPLATE_VARS: &[&str] = &[
"repo",
+ "owner",
"branch",
"worktree_name",
"repo_path",
diff --git a/src/config/user/accessors.rs b/src/config/user/accessors.rs
index 1a5658a03..be3b0fb85 100644
--- a/src/config/user/accessors.rs
+++ b/src/config/user/accessors.rs
@@ -224,6 +224,7 @@ impl UserConfig {
/// * `main_worktree` - Main worktree directory name (replaces {{ main_worktree }} in template)
/// * `branch` - Branch name (replaces {{ branch }} in template; use `{{ branch | sanitize }}` for paths)
/// * `repo` - Repository for template function access
+ /// * remote owner/namespace is available as {{ owner }}
/// * `project` - Optional project identifier (e.g., "github.com/user/repo") to look up
/// project-specific worktree-path template
pub fn format_path(
@@ -244,6 +245,12 @@ impl UserConfig {
vars.insert("repo", main_worktree);
vars.insert("branch", branch);
vars.insert("repo_path", repo_path.as_str());
+ let owner = repo
+ .primary_remote_parsed_url()
+ .map(|parsed_remote| parsed_remote.owner().to_string());
+ if let Some(ref owner) = owner {
+ vars.insert("owner", owner.as_str());
+ }
Ok(
expand_template(&template, &vars, false, repo, "worktree-path")
.map(|p| shellexpand::tilde(&p).into_owned())?,
diff --git a/src/config/user/tests.rs b/src/config/user/tests.rs
index 34c78cf2a..5d901f45c 100644
--- a/src/config/user/tests.rs
+++ b/src/config/user/tests.rs
@@ -430,6 +430,58 @@ fn test_worktrunk_config_format_path_tilde_expansion() {
);
}
+#[test]
+fn test_worktrunk_config_format_path_owner_variable() {
+ let mut test = TestRepo::with_initial_commit();
+ test.setup_remote("main");
+ test.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "[email protected]:max-sixty/worktrunk.git",
+ ]);
+
+ let config = UserConfig {
+ configs: OverridableConfig {
+ worktree_path: Some("{{ owner }}/{{ repo }}/{{ branch }}".to_string()),
+ ..Default::default()
+ },
+ ..Default::default()
+ };
+
+ let path = config
+ .format_path("myrepo", "feature/branch", &test.repo, None)
+ .unwrap();
+
+ assert_eq!(path, "max-sixty/myrepo/feature/branch");
+}
+
+#[test]
+fn test_worktrunk_config_format_path_owner_uses_full_namespace() {
+ let mut test = TestRepo::with_initial_commit();
+ test.setup_remote("main");
+ test.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "[email protected]:group/subgroup/project.git",
+ ]);
+
+ let config = UserConfig {
+ configs: OverridableConfig {
+ worktree_path: Some("{{ owner }}/{{ repo }}/{{ branch }}".to_string()),
+ ..Default::default()
+ },
+ ..Default::default()
+ };
+
+ let path = config
+ .format_path("myrepo", "feature/branch", &test.repo, None)
+ .unwrap();
+
+ assert_eq!(path, "group/subgroup/myrepo/feature/branch");
+}
+
#[test]
fn test_merge_config_serde() {
let config = MergeConfig {
diff --git a/src/git/repository/remotes.rs b/src/git/repository/remotes.rs
index 8f5947706..143d1086d 100644
--- a/src/git/repository/remotes.rs
+++ b/src/git/repository/remotes.rs
@@ -276,6 +276,16 @@ impl Repository {
.clone()
}
+ /// Parse the primary remote URL into structured host/owner/repo components.
+ ///
+ /// Uses the raw configured URL rather than `effective_remote_url()` so owner/namespace
+ /// extraction follows the same "path is the source of truth" rule used elsewhere.
+ pub fn primary_remote_parsed_url(&self) -> Option<GitRemoteUrl> {
+ self.primary_remote_url()
+ .as_deref()
+ .and_then(GitRemoteUrl::parse)
+ }
+
/// Get a project identifier for approval tracking.
///
/// Uses the git remote URL if available (e.g., "github.com/user/repo"),
diff --git a/tests/integration_tests/eval.rs b/tests/integration_tests/eval.rs
index 37c131732..e7093cfdc 100644
--- a/tests/integration_tests/eval.rs
+++ b/tests/integration_tests/eval.rs
@@ -67,6 +67,32 @@ fn test_eval_dry_run(repo: TestRepo) {
));
}
+#[rstest]
+fn test_eval_owner(repo: TestRepo) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "[email protected]:max-sixty/worktrunk.git",
+ ]);
+
+ let output = repo
+ .wt_command()
+ .args(["step", "eval", "{{ owner }}/{{ repo }}"])
+ .output()
+ .expect("Failed to run wt step eval");
+
+ assert!(
+ output.status.success(),
+ "wt step eval should succeed, stderr: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ assert_eq!(
+ String::from_utf8_lossy(&output.stdout).trim(),
+ "max-sixty/repo"
+ );
+}
+
#[rstest]
fn test_eval_conditional(repo: TestRepo) {
assert_cmd_snapshot!(make_snapshot_cmd(
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
index cffd7f2c2..8bb940c79 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
@@ -75,6 +75,7 @@ Creates ~/.config/worktrunk/config.toml with the following content:
  #
  # - `{{ repo_path }}` — absolute path to the repository root (e.g., `/Users/me/code/myproject`. Or for bare repos, the bare directory itself)
  # - `{{ repo }}` — repository directory name (e.g., `myproject`)
+  # - `{{ owner }}` — primary remote owner path (may include subgroups like `group/subgroup`)
  # - `{{ branch }}` — raw branch name (e.g., `feature/auth`)
  # - `{{ branch | sanitize }}` — filesystem-safe: `/` and `\` become `-` (e.g., `feature-auth`)
  # - `{{ branch | sanitize_db }}` — database-safe: lowercase, underscores, hash suffix (e.g., `feature_auth_x7k`)
@@ -93,6 +94,10 @@ Creates ~/.config/worktrunk/config.toml with the following content:
  #
  # worktree-path = "~/worktrees/{{ repo }}/{{ branch | sanitize }}"
  #
+  # By remote owner path (`~/development/max-sixty/myproject/feature/auth`):
+  #
+  # worktree-path = "~/development/{{ owner }}/{{ repo }}/{{ branch }}"
+  #
  # Bare repository (`~/code/myproject/feature-auth`):
  #
  # worktree-path = "{{ repo_path }}/../{{ branch | sanitize }}"
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index 282a77e2f..513f09855 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -8,7 +8,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "500"
- GIT_EDITOR: ""
+ GIT_PAGER: ""
LANG: C
LC_ALL: C
NO_COLOR: ""
@@ -121,6 +121,7 @@ Controls where new worktrees are created.
- {{ repo_path }} — absolute path to the repository root (e.g., /Users/me/code/myproject. Or for bare repos, the bare directory itself)
- {{ repo }} — repository directory name (e.g., myproject)
+- {{ owner }} — primary remote owner path (may include subgroups like group/subgroup)
- {{ branch }} — raw branch name (e.g., feature/auth)
- {{ branch | sanitize }} — filesystem-safe: / and \ become - (e.g., feature-auth)
- {{ branch | sanitize_db }} — database-safe: lowercase, underscores, hash suffix (e.g., feature_auth_x7k)
@@ -139,6 +140,10 @@ Centralized worktrees directory (~/worktrees/myproject/feature-auth):
  worktree-path = "~/worktrees/{{ repo }}/{{ branch | sanitize }}"
+By remote owner path (~/development/max-sixty/myproject/feature/auth):
+
+  worktree-path = "~/development/{{ owner }}/{{ repo }}/{{ branch }}"
+
Bare repository (~/code/myproject/feature-auth):
  worktree-path = "{{ repo_path }}/../{{ branch | sanitize }}"