> ## Documentation Index
> Fetch the complete documentation index at: https://bazel.build/llms.txt
> Use this file to discover all available pages before exploring further.

# template_ctx

A context object that is passed to the action template expansion function.

## Members

* [args](#args)
* [declare\_file](#declare_file)
* [run](#run)

## args

```
Args template_ctx.args()
```

Returns an Args object that can be used to build memory-efficient command lines.

## declare\_file

```
File template_ctx.declare_file(filename, *, directory)
```

Declares that implementation creates a file with the given filename within the specified directory.

Remember that in addition to declaring a file, you must separately create an action that emits the file. Creating that action will require passing the returned `File` object to the action's construction function.

### Parameters

| Parameter | Description |
| - | - |
| `filename` | [string](https://bazel.build/versions/9.3.3/rules/lib/core/string.md); required  The relative path of the file within the directory. |
| `directory` | [File](https://bazel.build/versions/9.3.3/rules/lib/builtins/File.md); required  The directory in which the file should be created. |

## run

```
None template_ctx.run(*, outputs, inputs=[], executable, tools=None, arguments=[], progress_message=None)
```

Creates an action that runs an executable.

### Parameters

| Parameter | Description |
| - | - |
| `outputs` | [sequence](https://bazel.build/versions/9.3.3/rules/lib/core/list.md) of [File](https://bazel.build/versions/9.3.3/rules/lib/builtins/File.md)s; required  List of the output files of the action. |
| `inputs` | [sequence](https://bazel.build/versions/9.3.3/rules/lib/core/list.md) of [File](https://bazel.build/versions/9.3.3/rules/lib/builtins/File.md)s; or [depset](https://bazel.build/versions/9.3.3/rules/lib/builtins/depset.md); default is `[]`  List or depset of the input files of the action. |
| `executable` | [File](https://bazel.build/versions/9.3.3/rules/lib/builtins/File.md); or [string](https://bazel.build/versions/9.3.3/rules/lib/core/string.md); or [FilesToRunProvider](https://bazel.build/versions/9.3.3/rules/lib/providers/FilesToRunProvider.md); required  The executable file to be called by the action. |
| `tools` | [sequence](../core/list.html); or [depset](../builtins/depset.html); or `None`; default is `None`  List or [`depset`](../builtins/depset.html) of any tools needed by the action. Tools are executable inputs that may have their own runfiles which are automatically made available to the action.  When a list is provided, it can be a heterogenous collection of: <ul> <li>`File`s</li> <li>`FilesToRunProvider` instances</li> <li>`depset`s of `File`s</li> </ul> `File`s from [`ctx.executable`](../builtins/ctx#executable) and `FilesToRunProvider`s which are directly in the list will have their runfiles automatically added. All tools are implicitly added as inputs.  |
| `arguments` | [sequence](https://bazel.build/versions/9.3.3/rules/lib/core/list.md); default is `[]`  Command line arguments of the action. Must be a list of strings or [`actions.args()`](#args) objects. |
| `progress_message` | [string](https://bazel.build/versions/9.3.3/rules/lib/core/string.md); or `None`; default is `None`  Progress message to show to the user during the build. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.