skip to content

For an OpenClaw cron job, when should it run with `--session main` rather than `--session isolated`, and what changes between them?

level: middleimportance: should knowfreq 9%

answer

  1. where the turn's context comes from
  2. system event versus agent message
  3. a fresh cron:<jobId> transcript
  4. main jobs cannot announce
  5. isolated jobs announce by default

basics

~20 s

A main-session job drops a system event into the agent's main session, handled with that conversation's context. An isolated job runs its own agent turn in a fresh cron session each time and can announce its result to a chat channel.

solid answer

~50 s

`--session main` jobs carry a `--system-event` (or a script): the text is queued into the owning agent's main session and handled with that session's existing context and delivery route, woken immediately or at the next heartbeat according to `--wake`. They suit reminders that belong in the ongoing conversation. `--session isolated` jobs carry a `--message` (or a command or script) and run a dedicated agent turn in a `cron:<jobId>` session with a new transcript every run, so the owner's chat history does not leak in and the run's turns stay out of the main conversation. They default to `--announce` delivery, and options such as `--model`, `--thinking` and `--light-context` apply to them. The CLI enforces the split: `--session main` with `--message` is rejected, and so are `--announce` or `--channel` on a main job. For context that should carry across runs, `session:<id>` names a persistent session.

code

bash · 9 lines
bash
# Nudge the ongoing conversation
openclaw cron add --name "Call the bank" --at "2h" \
  --session main --system-event "Remind me to call the bank."

# Self-contained report with its own delivery
openclaw cron add --name "Weekly digest" --cron "0 18 * * 5" \
  --tz "Europe/Berlin" --session isolated \
  --message "Summarize this week's merged changes." \
  --announce --channel slack --to "channel:C1234567890"

go deeper

for a junior

Remember that main jobs carry a system event into the main conversation, while isolated jobs run their own agent turn in a fresh session.

for a middle

Explain what context each target sees, why main jobs cannot announce, and that isolated jobs default to announce delivery in their cron:<jobId> session.

for a senior

Show judgment on placement: keep recurring deliverables isolated so they stay repeatable and out of the owner's chat, and trim them with --light-context and --tools.

for a principal

Weigh how much scheduled work should touch the owner's main conversation at all, and when a persistent session:<id> is worth its growing context.

## Two places a scheduled turn can run An OpenClaw job has a **session target** set with `--session`. It decides which conversation the work happens in, which context the model sees, and how the result gets back to a person. The four values are `main`, `isolated`, `current` and `session:<id>`; most interview questions are about the first two. A **session** in OpenClaw is a conversation with its own transcript. The **main session** is the owning agent's primary conversation, where the owner's direct messages normally land. ## Main-session jobs - The payload is a **system event** (`--system-event "..."`) or a script. A system event makes no model call by itself; it is queued into the main session. - `--wake now` (the default on create) asks for an immediate heartbeat so the event is handled at once; `--wake next-heartbeat` lets it wait for the next scheduled heartbeat. - The event is processed **with the main session's existing context** and its last delivery route, so the reply goes wherever that conversation goes. - Chat announce delivery is not available: `--announce`, `--channel` and `--to` on a main job are rejected. Primary webhook delivery is still allowed. - The event text is self-contained. It does not automatically pull in the heartbeat prompt or the heartbeat monitor scratch; say so in the text if it should. ## Isolated jobs - The payload is an **agent message** (`--message "..."`), a command or a script; the CLI refuses an isolated job without one of them. - Each occurrence runs in the job's own `cron:<jobId>` session with a **new transcript and session id**. Safe preferences such as thinking level carry over, but ambient conversation context, channel routing and elevation do not. - Delivery defaults to **announce**; `--no-deliver` keeps the result internal and `--webhook` POSTs it instead. - Agent-turn options apply: `--model`, `--fallbacks`, `--thinking`, `--tools` and `--light-context`, which skips injecting the workspace bootstrap files and applies only to isolated agent-turn jobs. - `cron.sessionRetention` (default `24h`) prunes finished isolated run sessions. ## Side by side | | `--session main` | `--session isolated` | |---|---|---| | Payload | `--system-event` or script | `--message`, command or script | | Context | main conversation as it stands | fresh transcript each run | | Where turns land | owner's main conversation | `cron:<jobId>` | | Chat delivery | session's own route; announce rejected | announce by default | | Best for | reminders, nudges | reports, background chores | ## The other two targets - **`current`** runs detached but reads a bounded tail of the conversation the job was created from, and commits its result back to that conversation. Agent-turn jobs created from a chat default to it; CLI and API callers without a session key fall back to `isolated`. - **`session:<id>`** is a persistent named session: context builds across runs, which suits a daily standup that should refer to yesterday's summary. ## Cost and freshness - An isolated agent turn builds its own prompt each run, normally including the workspace bootstrap files. For a narrow, frequent job, `--light-context` and a smaller `--tools` list keep each run cheap, and `--model` can put routine summaries on a lighter model than the agent's default. - A main-session event is handled inside the main conversation, so it is answered with whatever context that conversation already carries. - Internal automation turns do not extend a session's daily or idle reset freshness; only visible user activity does, so a scheduled job does not keep an old main session alive. - Isolated runs also clean up after themselves: tracked browser tabs and bundled MCP runtimes created for the `cron:<jobId>` session are closed on completion, best effort. ## Choosing 1. If the job is a nudge that the ongoing conversation should absorb ("remind me to call the bank"), use `main` with a system event. 2. If the job produces a deliverable on its own (the 7 a.m. briefing, a weekly digest), use `isolated` with a message and announce delivery: it is repeatable, it does not drag the owner's chat into the prompt, and its turns do not crowd the main conversation. 3. If the deliverable should build on its own history, use `session:<id>`. The mistake to avoid is treating `main` as "an isolated job that also sees my chat". It runs no agent message and cannot announce; the CLI stops you with `Main jobs require --system-event or --script.`

  • Why is `--light-context` worth setting on a frequent OpenClaw isolated job?
    An isolated agent turn normally injects the workspace bootstrap files into its prompt, as any agent turn does. `--light-context` keeps that bootstrap context empty for the job, so a frequent, narrow task such as a status check sends a much smaller prompt each run. It applies only to isolated agent-turn jobs; a main-session job runs inside the existing conversation and has nothing to trim.
  • When does an OpenClaw agent-turn job end up with the `current` session target without anyone asking for it?
    When the agent creates the job from a chat, because the create request carries that conversation's session context and agent-turn jobs default to it. The job then runs detached, reads a bounded tail of that conversation, and commits its result back there. CLI and API callers that supply no session key fall back to `isolated` instead.

A main-session job is a note slipped into an ongoing meeting: it is read with everything already said in the room. An isolated job is a contractor who arrives with a blank notebook each visit and leaves a report at the front desk.

  • An isolated cron job sees the owner's recent chat history.
  • A main-session job can announce to any channel with --channel and --to.
  • --session main with --message runs a full agent turn inside the main session.
  • Isolated jobs reuse one transcript, so their context grows run after run.
  • --light-context trims the prompt for main-session jobs too.