No deterministic way to reference files relative to current working directory in slash commands and sub-agents

Resolved 💬 3 comments Opened Mar 3, 2026 by alexeyv Closed Mar 7, 2026

Problem

When running Claude Code from a shared root (e.g., a bare repo or worktree parent), then switching into a specific worktree during the session, there is no reliable way for a slash command or sub-agent to reference a file that exists inside the current worktree.

Scenario

~/project/           ← Claude launched here (shared root)
~/project/main/      ← worktree: has ./config.md (v1)
~/project/feature/   ← worktree: has ./config.md (v2)

A reusable slash command installed at the shared root needs to say "read ./config.md from whichever worktree we're currently in." Every worktree has this file, but with different contents.

What exists today and why it fails

  1. @ references — Resolved client-side at message submission time against the launch CWD. If Claude was launched from ~/project/ and later switched into ~/project/feature/, @config.md still resolves against ~/project/ — where the file doesn't exist. In sub-agent Task prompts, @ references don't resolve at all; they pass through as literal text.
  1. {project-root}/config.md or similar prompt conventions — Not a real substitution. There is no variable system. This relies on the LLM interpreting the curly-brace token as "probably means the working directory" and making a Read tool call. It works most of the time because LLMs are good at guessing intent, but it's non-deterministic behavior standing in for what should be a resolved path.
  1. Hardcoded absolute paths — Only works for a single worktree. Defeats the purpose of reusable commands.

What's needed

A first-class variable (e.g., $CWD, $PROJECT_ROOT, or an extended @ syntax) that:

  • Resolves to the current working directory at the time the prompt is processed, not at session launch
  • Works in slash command definitions
  • Works in sub-agent/Task prompts
  • Is deterministic — the LLM receives an actual resolved path, not a hint to interpret

This is not specific to worktrees. Any workflow where the effective working directory changes after launch (worktrees, monorepos, multi-project sessions) hits the same gap.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗