Skip to content

Commit f4c6ce3

Browse files
committed
docs: add documentation for new template variable features
- Document _1, _2, etc. positional args as template variables - Document _args for numbered list of all positional args - Document --_varname CLI flags without frontmatter declaration - Add Auto-Injected Template Variables table to README - Update CLAUDE.md with new system keys - Add example files: positional-vars, args-list, optional-flags
1 parent a539f96 commit f4c6ce3

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,16 @@ Commands are resolved in priority order:
9393
**System keys** (consumed by md, not passed to command):
9494
- `_varname`: Template variables (e.g., `_name: "default"``{{ _name }}` in body → `--_name` CLI flag)
9595
- `_stdin`: Auto-injected template variable containing piped input
96+
- `_1`, `_2`, etc.: Auto-injected positional CLI args (e.g., `md task.md "foo"``{{ _1 }}` = "foo")
97+
- `_args`: Auto-injected numbered list of all positional args
9698
- `env` (object form): Sets process.env before execution
9799
- `$1`, `$2`, etc.: Map positional args to flags
98100
- `_interactive`: Enable interactive mode (overrides print-mode defaults)
99101
- `_subcommand`: Prepend subcommand(s) to CLI args (e.g., `_subcommand: exec`)
100102
- `_cwd`: Override working directory for inline commands (`` !`cmd` ``)
101103

104+
**Note:** `--_varname` CLI flags work without frontmatter declaration. If a `_` prefixed variable is used in the body but not provided, you'll be prompted for it.
105+
102106
**All other keys** are passed directly as CLI flags:
103107

104108
```yaml

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,54 @@ mdflow create.claude.md --_feature_name "Payments" --_target_dir "src/billing"
161161

162162
The `--_feature_name` and `--_target_dir` flags are consumed by mdflow for template substitution—they won't be passed to the command.
163163

164+
**No frontmatter declaration required:** You can pass `--_varname` flags without declaring them in frontmatter. If the variable is used in the body but not provided, you'll be prompted for it:
165+
166+
```yaml
167+
---
168+
print: true
169+
---
170+
{% if _verbose == "yes" %}Detailed analysis:{% endif %}
171+
Review this code: {{ _target }}
172+
```
173+
174+
```bash
175+
mdflow review.claude.md --_verbose yes --_target "./src"
176+
```
177+
178+
### Positional Arguments as Template Variables
179+
180+
CLI positional arguments are available as `{{ _1 }}`, `{{ _2 }}`, etc.:
181+
182+
```yaml
183+
---
184+
print: true
185+
---
186+
Translate "{{ _1 }}" to {{ _2 }}.
187+
```
188+
189+
```bash
190+
mdflow translate.claude.md "hello world" "French"
191+
# → Translate "hello world" to French.
192+
```
193+
194+
Use `{{ _args }}` to get all positional args as a numbered list:
195+
196+
```yaml
197+
---
198+
print: true
199+
---
200+
Process these items:
201+
{{ _args }}
202+
```
203+
204+
```bash
205+
mdflow process.claude.md "apple" "banana" "cherry"
206+
# → Process these items:
207+
# → 1. apple
208+
# → 2. banana
209+
# → 3. cherry
210+
```
211+
164212
### `_stdin` - Piped Input
165213

166214
When you pipe content to mdflow, it's available as the `_stdin` template variable:
@@ -192,6 +240,14 @@ cat README.md | mdflow summarize.claude.md
192240
| `_subcommand` | string/string[] | Prepend subcommand(s) to CLI args |
193241
| `_cwd` | string | Override working directory for inline commands |
194242

243+
### Auto-Injected Template Variables
244+
245+
| Variable | Description |
246+
|----------|-------------|
247+
| `{{ _stdin }}` | Content piped to mdflow |
248+
| `{{ _1 }}`, `{{ _2 }}`... | Positional CLI arguments |
249+
| `{{ _args }}` | All positional args as numbered list (1. arg1, 2. arg2, ...) |
250+
195251
### All Other Keys → CLI Flags
196252

197253
Every other frontmatter key is passed directly to the command:

examples/args-list.claude.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
# Example: Using _args to get all positional args as a numbered list
3+
# Usage: md args-list.claude.md "apple" "banana" "cherry"
4+
print: true
5+
---
6+
Process these items:
7+
{{ _args }}

examples/optional-flags.claude.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
# Example: Using --_varname flags without frontmatter declaration
3+
# Usage: md optional-flags.claude.md --_mode detailed
4+
# Or just: md optional-flags.claude.md (will prompt for _mode)
5+
print: true
6+
---
7+
{% if _mode == "detailed" %}
8+
Provide a detailed, comprehensive analysis.
9+
{% else %}
10+
Provide a brief summary.
11+
{% endif %}
12+
13+
Analyze this codebase.

examples/positional-vars.claude.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
# Example: Using positional CLI args as template variables
3+
# Usage: md positional-vars.claude.md "hello" "French"
4+
print: true
5+
---
6+
Translate "{{ _1 }}" to {{ _2 }}.

0 commit comments

Comments
 (0)