#5765·tilt

Proposal: exit_settings builtin and --on-exit CLI option for customizing exit behavior

Author: nicksiegerCreated May 4, 2022Updated Sep 13, 2026
Labelsenhancement

Describe the Feature You Want

We have a number of requests (#2427, #3059, #4294, #5210, #3831) related to being able to control what happens when tilt up or tilt ci exits. A brief summary:

  1. Enable tearing down of resources on exit (#2427, #5210). Either:
  • the equivalent of tilt down, where the Tiltfile is re-executed (so that if config.tilt_subcommand == 'down': statements could run), or
  • clean up the resources without re-executing the Tiltfile -- use the manifests computed from the last Tiltfile result to clean up or disable all resources
  1. Provide multiple ways of specifying the behavior: CLI option(s), Tiltfile builtins, user config file
  2. Provide custom behavior on exit rather than using tilt down and if config.tilt_subcommand == 'down': statements (#3831, #3059)
  3. There are a couple other CLI flags and features related to behavior on exit that have no Tiltfile equivalent that could be exposed: tilt down --delete-namespaces, tilt up/ci --output-snapshot-on-exit

Proposal

This issue proposes to address the above issues and requests with a new Tiltfile builtin exit_settings() and CLI option tilt up/ci --on-exit.

python
def exit_settings(
  down: bool = False,
  disable: bool = False,
  delete_namespaces: bool = False,
  callback: Function = None,
  snapshot: Union[bool,str] = False,
)
   """Customize behavior of `tilt up` or `tilt ci` when it exits (e.g., due to interrupt or term signal).
   
   Default behavior is to do nothing, leaving any existing k8s or docker-compose resources running.

   Args:
     down: If true, execute the equivalent of `tilt down` at exit. The `Tiltfile` will be re-executed so that any `if config.tilt_subcommand == 'down':` conditional statements can be run. Mutually exclusive with `disable`: If both `down` and `disable` are true, `down` wins.
     disable: If true, disable all resources at exit. The effect is similar to `down` except that the `Tiltfile` is not re-executed.
     delete_namespaces: If true and one of `down` or `disable` is specified, delete any k8s namespaces that were created.
     callback: a Starlark function to be executed at exit. Can be used to run custom logic and `local` commands. If `down` or `disable` are also specified, the callback function will be executed before resources are torn down.
     snapshot: If true, Tilt will output a snapshot file named `tilt-snapshot-XXXXXX.json` at exit. If a string, represents a snapshot filename to save. A literal `%s` can be used in the pathname and will be replaced with a value that ensures the filename will be unique.
   """

CLI option --on-exit

A common flag --on-exit will be added to tilt up and tilt ci that allows specifying down, disable, delete_namespaces, or snapshot options.

      --on-exit strings  Values: down, disable, delete_namespace, snapshot. Customize Tilt behavior on exit. See `exit_settings` Tiltfile builtin.

In addition to the values stated, --on-exit will allow a string of the form snapshot=snapshot-%s.json to customize the snapshot filename. Equivalent to --output-snapshot-on-exit string option.

Current Behavior

Tilt does not allow much in the way of customizing what happens when tilt up or tilt ci exits.

Why Do You Want This?

Address multiple issues and user requests related to on-exit behavior.