Guide7 min read
Agents in cron and CI: why the job stays green and opens the same issue every night
A run with nobody watching starts with whatever is on that machine. What stays on your laptop, two tests we ran with a broken MCP server in Claude Code and Codex, a 15-minute drill, and where last night's result has to live.

A nightly job triages failing tests. You wrote it on your laptop: claude -p with a prompt file, a memory server the agent uses to look up what it already reported, and a line in your own CLAUDE.md saying the payments migration tests are quarantined until the 12th. On the laptop it behaved. On Monday you moved it to CI. By Friday it had opened the same issue about the same flaky test five times and had "fixed" a quarantined test twice. Every run exited 0.
Nothing was wrong with the prompt. The runner had no home directory of yours, so it had no CLAUDE.md. The memory server was an entry in a config file on your laptop. And Tuesday's run had no way to know what Monday's run found. The CLI did what its documentation says it does: it started with what was on that machine and carried on.
Same prompt, three different agents
A run with nobody at the keyboard executes in one of three places:
- A cron entry or a timer on a machine you own. Your home directory is there: your user-level instruction file, the MCP servers you added, your saved login, the harness's own memory and yesterday's sessions.
- A CI runner. A fresh machine or container with the checkout and whatever the job installs. Nothing from anyone's home directory.
- The vendor's scheduler. A fresh clone or a fresh chat on the vendor's side, with what is committed to the repository and what is attached to the account. Nothing from your local config.
Most jobs are written in the first place and moved to the second or third. The move is where things get left behind.

Four things that stay on the laptop
- The user-level instruction file.
~/.claude/CLAUDE.md,~/.codex/AGENTS.md, your global Cursor rules. A runner has none of them. - The MCP server you added from the command line. Claude Code's default scope and the Codex and Cursor user configs are files in your home directory.
- The harness's memory. In Claude Code, auto memory is "machine-local" and its files "are not shared across machines or cloud environments". In Codex, memories are local and off by default.
- Yesterday's session.
--resumeandcodex exec resumeread session files from disk. On a fresh runner there is nothing to resume, and a vendor-scheduled task starts a new session by design.
The first two have a fix inside the repository. All three harnesses load the project instruction file from the checkout, so a rule committed there reaches the job wherever it runs. The server gets declared where the job reads it. The last two have no such fix: what one run found has to be written somewhere the next run reads.
One Claude Code detail. The mode its documentation recommends for CI, --bare, does not load even the project CLAUDE.md, and the same documentation says bare mode "will become the default for -p in a future release". In that mode the file goes in with --append-system-prompt-file.
The server that does not load and the green job
This is where the green job with the wrong result comes from. We ran two tests on our own machine on November 29, 2026.
In Claude Code 2.1.329, a claude -p call got an MCP config with two broken entries: one with a url and no type, one pointing at a local port that refuses connections. The result was success and the exit code was 0. Neither server was there, and nothing showed up on stderr. The only trace was in the first event of the stream-json output, system/init: one server with status failed and the other under mcp_server_errors.
In Codex 0.156.1, codex exec with the same unreachable server and required = true exited 1. It stopped at startup and never sent a request to the model. Without required, the run went past the dead server and reached the model request, which failed because the CLI on the test machine was not logged in. So we saw where each run stopped, and we did not see a run with an optional server reach the end.
For Cursor, the CLI docs do not say what agent -p does when a server fails to connect. The cloud Automations docs say that when a server rejects the credentials, "the run continues without that server's tools".
An agent that cannot reach its memory does not stop. It answers from the repository alone, and in the job log that answer looks like any other.
Make the job fail when its memory is missing
- Claude Code. Pass the config explicitly with
--mcp-configand--strict-mcp-config, ask forstream-jsonoutput and checksystem/initbefore you accept the result. Allow the memory tools with--allowedTools: in an unattended run, a call that needs approval is denied and the run carries on. - Codex.
required = trueon the server's table. - Cursor.
agent mcp listin a step before the run, and a prompt that tells the agent to stop when the tool is not there.
The Claude Code check, run against the job's output:
jq -e -s '(map(select(.type=="system" and .subtype=="init"))[0]) as $i
| (($i.mcp_server_errors // []) | length) == 0
and ([$i.mcp_servers[]? | select(.name=="valorbrain" and .status=="connected")] | length) == 1' \
run.jsonl > /dev/null
Against the output of our test it exits 1. Against a hand-written stream with the server connected it exits 0. We did not run the whole script on a CI runner. One caveat from the guide: a remote server with a cached tool list can show up as pending in system/init and connect on the first call. On a machine that keeps that cache, the check fails the run.
A 15-minute drill
Plant four markers, then ask the job what it has.
- In your user-level instruction file:
The canary word for user rules is HERON. - In the project instruction file, committed:
The canary word for project rules is OTTER. - In an interactive session on your laptop, say
Remember that the canary word for this project is MARTEN.and close the session. - Leave the MCP server the job depends on configured the way you configured it the first time.
Run the job's exact command where the job runs, with this prompt:
List every canary word you were given and the file or source each one came from.
Then list the MCP servers you can call and three tools from each.
If you have no canary word or no MCP server, say so. Do not guess.
Run the same prompt on the laptop and put the two answers side by side. From the documentation, a CI runner returns OTTER only, a --bare Claude Code run returns none unless you passed the file, and the server from step 4 is missing wherever it was added from the command line. The drill shows what your versions and your setup do, which is the part the documentation cannot tell you.
Where last night's result can live
- A file the job commits. A
STATE.mdrewritten every night. It works for one job on one repository. It puts a commit in the history every night, two jobs racing on the file conflict, and a vendor-scheduled task pushes to its own branch, so the next run only sees it after someone merges. - The CI cache or an artifact. No commit in the history. It is tied to that workflow on that CI, and caches get evicted.
- The issue tracker. The job searches its own open issues before opening one, which already prevents the same issue five times if the prompt says to search. It is the right place for what a person has to fix, and a poor place for the job's working state: what it checked, what it could not settle, what it ruled out.
- A record outside the runner that every run reads at start. A memory server, a database, a ticket the job owns. It outlives the runner, and a person or another agent reads the same record. In exchange, it is one more service the job depends on, which is why the previous section exists.
Standing rules stay in the committed instruction file. The record is for what changes from one run to the next.
What ValorBrain does and does not do
In ValorBrain, that record is task_state, a ledger on the server that the agent writes over MCP. The runner has nothing @valorbrain/connect installs: no hooks, no rules block, no saved credential. The job needs the MCP entry with the token from a secret, plus a few lines in its prompt:
## Before you start
- Call `memory_prepare` with this task as the message. If the tool is not available, stop and say so. Do not continue from the repository alone.
- Read the open ledger `nightly-triage`: what the last run verified and what it left open.
## Before you finish
- `task_state` with `session: "nightly-triage"`: a `ledger_checkpoint` for what you verified tonight, a `ledger_open_question` for each thing you could not settle, and `ledger_next`.
- Do not open an issue the ledger says is already open.
Name the ledger after the job. Without session, the call writes to the default ledger of the calling credential and agent. With the name, every run of that job, from any runner or harness, reads and writes the same one. On the MCP entry, X-Source-Agent: nightly-triage makes every run show up as the same agent, and X-Run-Kind: routine keeps what the job writes out of other agents' feeds by default. A search still finds it, and the job's own runs always see it.
The guide in the docs was written that way, by a scheduled run, and it shows the three real ledger calls and what memory_prepare returned a minute later.
What it does not do, today:
- It does not start by itself on a runner. No hook is there. The agent calls
memory_preparebecause the prompt says so, and thesystem/initcheck is what catches the night the server did not load. - It does not make the agent obey the ledger. A run that reads "issue already open" and opens it again is a model failure the record makes visible, not one it prevents. We have not measured how often an unattended run follows those prompt lines.
- It does not replace the instruction file. Standing rules belong in the file the harness loads from the checkout.
- It does not schedule, run or sandbox anything. That is cron, your CI and the harness.
- It needs the network. A runner with a restricted network policy has to allow
mcpbrain.valor.digital.
What we ran: one claude -p call and two codex exec calls on our own machine, plus the jq checks against that output. We did not run a job on a CI runner, a vendor-scheduled task, bare mode or Cursor's CLI. Everything else about the harnesses is what each vendor's documentation said on November 29, 2026.
The full per-harness table, the script with both checks and the Codex and Cursor configs are in the guide: Headless and scheduled agent runs: what a cron or CI agent starts with.
ValorBrain works over MCP, in Claude Code, Codex, Cursor and any compatible client. The free plan needs no card: valorbrain.com.br.
Sources, read on November 29, 2026: Claude Code, Run Claude Code programmatically, CLI reference, MCP, MCP in the Agent SDK, Memory, Cloud scheduled tasks and GitHub Actions; Codex, Non-interactive mode, Scheduled tasks, Memories and MCP; Cursor, Headless CLI, MCP in the CLI and Automations. The tests are from November 29, 2026, with Claude Code 2.1.329 and codex-cli 0.156.1.
Next step
Less starting over. More continuity
Bring a real project. In one conversation we map where context gets lost between the people and agents on your team, and where to start.