skip to content

In OpenClaw, what does injecting the workspace bootstrap files cost on every run, and what happens when one exceeds bootstrapMaxChars?

level: seniorimportance: should knowfreq 6%

answer

  1. characters, not tokens
  2. per file and in total
  3. a separate small cap for one file
  4. the middle goes missing
  5. raw versus injected sizes

basics

~20 s

By default, bootstrap files are injected into the system prompt on every run, so their size is paid each turn. Each file is capped by agents.defaults.bootstrapMaxChars (20000) and all together by bootstrapTotalMaxChars (60000); USER.md has a fixed 4,000 cap. Oversized files lose their middle.

solid answer

~30 s

With the default `contextInjection: "always"`, `AGENTS.md`, `SOUL.md`, `IDENTITY.md`, `USER.md`, a pending `BOOTSTRAP.md` and `MEMORY.md` go into Project Context on every run, so each character costs context on each turn, softened by prefix caching. In 2026.9.9 each file is limited by `agents.defaults.bootstrapMaxChars` (20000 characters), the set by `bootstrapTotalMaxChars` (60000), spent in prompt order, and `USER.md` by a fixed 4,000 that `bootstrapMaxChars` can only lower. An oversized file keeps its head and tail around a `[...truncated, read <file> for full content...]` marker, and the prompt gets a generic truncation notice; the disk copy is untouched. `/context list` shows raw versus injected sizes.

code

json · 8 lines
json
{
  "agents": {
    "defaults": {
      "bootstrapMaxChars": 12000,
      "bootstrapTotalMaxChars": 36000
    }
  }
}

go deeper

for a junior

Know that the workspace files are pasted into the prompt every run, that large ones get cut, and that /context list shows what was actually injected.

for a middle

Name the two keys and their defaults, the separate USER.md cap, and that truncation keeps head and tail around a marker rather than the start alone.

for a senior

Explain how prompt order spends the shared total, why later files starve first, and how you diagnose with /context and doctor before deciding to shrink or raise limits.

for a principal

Treat bootstrap size as a standing per-turn cost: set a team budget for each file, decide what moves to skills or on-demand memory, and when raising limits is justified.

## What gets injected, and how often OpenClaw builds its own system prompt for every agent run. Part of that prompt is **Project Context**: the workspace bootstrap files `AGENTS.md`, `SOUL.md`, `IDENTITY.md`, `USER.md`, `BOOTSTRAP.md` (only while a brand-new workspace's ritual is pending) and `MEMORY.md` when present, in that order. On the default embedded runtime, `agents.defaults.contextInjection` is `"always"`, so these files ride along on **every run**, not just the first message of a session. Some sessions get fewer: sub-agent sessions keep only `AGENTS.md`, cron sessions drop `MEMORY.md` and `BOOTSTRAP.md`, and group or channel sessions omit root `MEMORY.md`. The **cost** is therefore a recurring one. Every character injected is input the model reads on each turn and context it cannot use for the conversation. OpenClaw places this stable content above an internal prompt-cache boundary so backends that cache prompt prefixes can reuse it across turns, which softens the price but does not remove the context-window cost. ## The three limits The budgets are counted in **characters**, not tokens. | Limit | Key | Default in 2026.9.9 | |---|---|---| | Per file | `agents.defaults.bootstrapMaxChars` | 20000 | | All files together | `agents.defaults.bootstrapTotalMaxChars` | 60000 | | `USER.md` only | fixed cap | 4,000 | - Per-agent overrides exist as `agents.entries.*.bootstrapMaxChars` and `agents.entries.*.bootstrapTotalMaxChars`. - The `USER.md` cap is deliberate: `bootstrapMaxChars` can **lower** it but never raise it. - At a rough four characters per token, the 60,000-character total is on the order of 15,000 tokens per run. ## How a file is cut When one file is over its limit, OpenClaw does not simply keep the start. 1. It keeps a **head** and a **tail** of the file, splitting the remaining room roughly 75 to 25, and puts a marker between them: `[...truncated, read SOUL.md for full content...]` plus a count of what was kept. 2. For `AGENTS.md` it uses a policy-aware variant: a head, a short digest of heading and list lines from the cut middle, and a tail, so rules buried in the middle are less likely to vanish entirely. 3. The prompt also gets one built-in notice that some bootstrap files were truncated and should be read directly. That notice is not configurable and deliberately omits per-file names. 4. The file on disk is untouched; only the injected copy is shortened. ## Order and the shared budget The total budget is spent **in prompt order**. That has consequences: - `AGENTS.md`, `SOUL.md` and `IDENTITY.md` come first; with defaults, three full 20,000-character files can use the whole 60,000 total. - Whatever comes later (`USER.md`, `BOOTSTRAP.md`, `MEMORY.md`) gets only what remains, and is clamped further if little is left. - Once fewer than 64 characters remain, OpenClaw stops adding files and logs a warning. - A missing `AGENTS.md`, `SOUL.md` or `IDENTITY.md` costs only a short `[MISSING] Expected at: <path>` marker; an absent `USER.md` or `MEMORY.md` is simply omitted, and blank files are skipped. ### A worked example With defaults, in a private main session, suppose `AGENTS.md` is 26,000 characters, `SOUL.md` 8,000, `IDENTITY.md` 1,000, `USER.md` 3,500 and `MEMORY.md` 30,000. 1. `AGENTS.md` is cut to 20,000 by the per-file limit; 40,000 of the total remain. 2. `SOUL.md`, `IDENTITY.md` and `USER.md` fit whole; 27,500 remain. 3. `MEMORY.md` is cut to 20,000 by the per-file limit, leaving 7,500 unused; two files carry truncation markers and the prompt gets one generic notice. If `AGENTS.md` and `SOUL.md` had each been 20,000 and `IDENTITY.md` 20,000 too, nothing at all would be left for `USER.md` and `MEMORY.md`. ## Diagnosing and fixing - `/context list` shows each injected file with raw and injected sizes and whether it was truncated; `/context detail` adds per-tool schema and per-skill sizes. Per-file details also appear in `/status`, `openclaw doctor` and logs. - Shrink before you raise: move detail out of `AGENTS.md` into skills or on-demand files, keep `SOUL.md` short, and keep `USER.md` to directives. `openclaw doctor` names the `USER.md` cap and recommends compacting when it bites. - Raise `bootstrapMaxChars` or `bootstrapTotalMaxChars` only deliberately, knowing each extra character is paid on every run. - In the embedded runtime, `contextInjection: "continuation-skip"` skips eligible continuation turns after a full-bootstrap turn, and `"never"` turns injection off; the latter also removes the agent's persona and rules. These are OpenClaw's own knobs. Context budgeting as a general discipline, and what compaction does to a long session, are separate subjects.

  • Can you let USER.md grow past 4,000 characters by raising bootstrapMaxChars?
    No. `USER.md` has a deliberate fixed 4,000-character cap; `agents.defaults.bootstrapMaxChars` and the per-agent override can only lower it. When the cap bites, `openclaw doctor` says so and recommends compacting: drop stale superseded entries and move durable facts or detailed notes into the memory files.
  • Why does the model not know which bootstrap file was truncated?
    The in-prompt notice is built in, not configurable, and deliberately generic: it says some bootstrap files were truncated and to read them directly. The truncated file itself carries a marker naming it, while per-file names and raw versus injected counts go to `/context`, `/status`, doctor and logs.
  • Which limit bites first when AGENTS.md, SOUL.md and IDENTITY.md are all large?
    The total budget is spent in prompt order, so three files at the 20,000-character default can exhaust the 60,000 total and leave `USER.md` and `MEMORY.md` clamped or skipped; below 64 remaining characters OpenClaw stops adding files.

  • Truncation keeps the first bootstrapMaxChars characters and drops the end.
  • The bootstrap limits are counted in tokens.
  • Raising bootstrapMaxChars lets USER.md grow past 4,000 characters.
  • A truncated bootstrap file is shortened on disk as well.
  • Bootstrap files are read once per session and cost nothing afterwards.

Assumes OpenClaw 2026.9.9 defaults: bootstrapMaxChars 20000, bootstrapTotalMaxChars 60000 and the fixed 4,000-character USER.md cap.