# Keep a long job running after the chat ends

A long build or a dev server keeps running when the conversation that started it ends. Come back
later, from the same client or another, and read where it got to.

**In short:** `task_start {"command": "npm run build", "cwd": "~/app"}`, later `tasks_list` to find it,
`task_output {"task": <id>}` to read it, `task_stop` to end it.

## When to use this

The job takes longer than a single call may wait (at most 10 minutes for
[`exec_run`](https://docs.cmdop.ai/reference/tools/exec_run.md)), or it should keep running, like a dev server.

## Steps

1. The agent needs the `exec` class ([grant risk classes](https://docs.cmdop.ai/guides/access/grant.md)).
2. Start it with [`task_start`](https://docs.cmdop.ai/reference/tools/task_start.md). It returns the task id at once.
3. End the chat if you like. The task keeps running.
4. Later, in a new chat or from the SDK, call [`tasks_list`](https://docs.cmdop.ai/reference/tools/tasks_list.md) to find
   it, and [`task_output`](https://docs.cmdop.ai/reference/tools/task_output.md) to read its screen.
5. Stop it with [`task_stop`](https://docs.cmdop.ai/reference/tools/task_stop.md) when it is no longer needed.

What it does not survive: pausing the machine, and a restart of the machine program. The full
table is on [Run commands and tasks](https://docs.cmdop.ai/guides/run.md).

## Check

`task_output` shows the program's own output, and `tasks_list` lists the task under the agent
that started it.

## If it fails

- [`denied`](https://docs.cmdop.ai/reference/errors/denied.md): `exec` is off for this agent or on this machine.
- [`busy`](https://docs.cmdop.ai/reference/errors/busy.md): the machine already runs as many calls as it takes; retry.

## Related

[Tasks](https://docs.cmdop.ai/concepts/tasks.md) · [Run commands and tasks](https://docs.cmdop.ai/guides/run.md)
