Available Variables
| Variable | Syntax | Usage Locations | Description |
|---|---|---|---|
| Project Root | ${root} | Filesystem paths, System prompt | Expands to the project root directory |
| Agent Directory | ${agentDir} | Filesystem paths, System prompt | Expands to the directory containing the agent file |
| Temp Directory | ${tmpDir} | Filesystem paths, System prompt | Expands to the system temp directory |
| Environment Variable | ${env:VAR_NAME} | mcpServers.<name>.auth.token only | Expands to the value of an environment variable |
${root} - Project Root
The ${root} variable expands to your project’s root directory, which is detected by looking for markers like .git, package.json, or .agentuse directory.
Usage
Use${root} in filesystem tool path configurations to reference paths relative to your project root, regardless of where you run the agent from.
Benefits
- Portable: Paths work regardless of current working directory
- Consistent: Always references the same location relative to project
- Safe: Restricts file access to defined project paths
${agentDir} - Agent Directory
The ${agentDir} variable expands to the directory containing the agent file. This is useful for referencing files bundled with your agent.
Usage
Use${agentDir} to access files that are distributed alongside your agent file, such as scripts, configs, or data files.
Benefits
- Self-contained agents: Bundle resources with your agent file
- Relocatable: Agent works regardless of where it’s installed
- No absolute paths: Avoid hardcoding paths in agent definitions
${agentDir} is only available when the agent is loaded from a file. If the agent is loaded from a string or other source, this variable will not be resolved.${tmpDir} - Temp Directory
The ${tmpDir} variable expands to the system’s temporary directory (os.tmpdir()).
Usage
Use${tmpDir} for temporary file storage that doesn’t need to persist across agent runs.
Benefits
- Platform-independent: Works on macOS, Linux, and Windows
- No cleanup needed: Temp files are typically cleaned by the OS
- Safe for scratch work: Ideal for intermediate processing files
${env:VAR_NAME} - Environment Variables
The ${env:VAR_NAME} syntax allows you to reference environment variables in your configuration. This is particularly useful for sensitive values like API tokens.
Usage
Currently supported in HTTP MCP server authentication:How It Works
- When the agent starts,
${env:API_TOKEN}is replaced withprocess.env.API_TOKEN - If the environment variable is not set, a warning is logged
- Use
requiredEnvVarsto ensure the variable exists before the agent runs
Security Benefits
- No hardcoded secrets: Tokens stay in environment variables, not in code
- Version control safe:
.agentusefiles can be committed without exposing secrets - Explicit requirements:
requiredEnvVarsdocuments what’s needed to run the agent
Variables in System Prompt
You can use path variables (${root}, ${agentDir}, ${tmpDir}) in the markdown content (system prompt) of your agent file. This helps the agent understand its environment.
Usage
Security Note
${env:VAR_NAME} is not supported in the system prompt to prevent accidental secret exposure. Environment variables should only be used for authentication tokens in MCP server configuration, where they are handled securely and never sent to the LLM.
Examples
Complete Agent with All Path Variables
Self-Contained Agent with Bundled Resources
Multiple Environment Variables
Variable Resolution
Variables are resolved at different times:| Variable | Resolution Time | Scope |
|---|---|---|
${root} | Agent initialization | Filesystem paths, System prompt |
${agentDir} | Agent initialization | Filesystem paths, System prompt |
${tmpDir} | Agent initialization | Filesystem paths, System prompt |
${env:VAR_NAME} | MCP connection setup | HTTP auth tokens only |
Troubleshooting
Variable not expanding
Variable not expanding
Ensure you’re using the correct syntax:
- Project root:
${root}(lowercase) - Agent directory:
${agentDir}(camelCase) - Temp directory:
${tmpDir}(camelCase) - Environment variables:
${env:VAR_NAME}(withenv:prefix)
${VAR_NAME} syntax without the env: prefix is not supported.agentDir not resolving
agentDir not resolving
${agentDir} is only available when the agent is loaded from a file path. It will not resolve when:- The agent is loaded from a URL
- The agent is loaded from a string
- The agent file path is not passed to the runner
${agentDir} will remain as literal text and path validation may fail.Environment variable not found
Environment variable not found
If you see a warning about an environment variable not being set:
- Check that the variable is exported in your shell or defined in
.env - Verify the variable name matches exactly (case-sensitive)
- Add the variable to
requiredEnvVarsfor early validation
Path not resolving correctly
Path not resolving correctly
If
${root} isn’t pointing to the expected directory:- Ensure your project has a recognizable marker (
.git,package.json, etc.) - Run the agent from within your project directory
- Use
agentuse run -C /path/to/projectto specify the project root
