An OpenClaw owner wants each `/new` to save the old conversation and every command logged: which bundled hooks do this, and what do they record?
answer
- two shipped hooks, no code to write
- openclaw hooks list, then enable
- an excerpt, not a summary
- memory/ dated file; logs/commands.log
- only /new, /reset and /stop are logged
basics
~10 sEnable the bundled session-memory and command-logger hooks with openclaw hooks enable. session-memory saves the last 15 user and assistant messages to memory/YYYY-MM-DD-HHMM.md; command-logger appends one JSON line per /new, /reset or /stop to logs/commands.log.
solid answer
~40 sOn the Gateway host run `openclaw hooks list`, then `openclaw hooks enable session-memory` and `openclaw hooks enable command-logger`; in the default `hybrid` reload mode they load without a restart. `session-memory` listens to `command:new`, `command:reset` and `session:auto-reset` and, in the background, writes a filtered excerpt of the ended session (by default the last 15 user and assistant messages, not a model-written summary) to `<workspace>/memory/YYYY-MM-DD-HHMM.md`. `command-logger` subscribes to the `command` family and appends `timestamp`, `action`, `sessionKey`, `senderId` and `source` to `<stateDir>/logs/commands.log`. Core emits only `/new`, `/reset` and `/stop` as command events, and the log is never rotated. `openclaw onboard` normally turns `session-memory` on unless you pass `--skip-hooks` or have already set its entry.
code
json · 11 lines{
"hooks": {
"internal": {
"enabled": true,
"entries": {
"session-memory": { "enabled": true, "messages": 25 },
"command-logger": { "enabled": true }
}
}
}
}go deeper
Recall the two hook names, the enable command, and where each writes: a dated file under memory/ and logs/commands.log in the state directory.
Explain which events each hook listens to, why the memory file is an excerpt rather than a summary, why it can appear a moment after /new, and which commands the logger never sees.
Talk about verifying the side effect instead of trusting the report, the allowlist effect of named entries, log retention with no rotation, and the privacy of sender identifiers.
Weigh what the owner gains from automatic memory files and an audit log against the private data both accumulate, and set a retention and access policy before turning them on.
## The two hooks for this job OpenClaw ships five **bundled hooks**: small handlers that run inside the Gateway process when an event fires, ready to enable without writing a plugin. Two of them cover "save the old conversation on `/new`" and "log every command": | Hook | Subscribes to | Writes | Defaults | | --- | --- | --- | --- | | `session-memory` | `command:new`, `command:reset`, `session:auto-reset` | `<workspace>/memory/YYYY-MM-DD-HHMM.md` | last `15` messages, timestamp file name | | `command-logger` | the whole `command` family | `<stateDir>/logs/commands.log`, one JSON line per event | no rotation, no chat confirmation | `<stateDir>` is normally `~/.openclaw`, and the workspace is the agent's resolved workspace folder. ## Turning them on 1. On the **Gateway host**, with the same profile as the running Gateway, run `openclaw hooks list` and `openclaw hooks info session-memory` to see their status and requirements. 2. Run `openclaw hooks enable session-memory` and `openclaw hooks enable command-logger`. Each writes `hooks.internal.entries.<name>.enabled = true` and sets `hooks.internal.enabled = true` in local config. 3. In the default `hybrid` reload mode the running Gateway picks up the change; with reload mode `off`, run `openclaw gateway restart`. 4. Verify the side effect, not the report: send `/new` in a conversation you can safely reset, then `tail -n 5 ~/.openclaw/logs/commands.log` and look in the workspace `memory/` folder. Two details about defaults. `openclaw onboard` normally enables `session-memory` unless you pass `--skip-hooks`, have set that entry explicitly, or have switched internal hooks off. And once any named entry exists, the enabled names form an **allowlist**: hooks you have not named stop loading, so check what was already selected before adding the first entry. ## What session-memory saves - **When**: on an authorized `/new` or `/reset` (soft reset included) and on an automatic daily or idle rollover, which emits `session:auto-reset`. Expiry is checked when the next turn arrives; nothing is written at midnight while the session sits idle. - **What**: a filtered excerpt of recent user and assistant text, set by the `messages` option (default `15`). It leaves out slash-command text, tool messages and silent reply markers. It is **not** a full transcript and **not** a model-written summary. - **Where**: `<workspace>/memory/YYYY-MM-DD-HHMM.md`, with a numeric suffix if the name is taken. Dates follow `agents.defaults.userTimezone`, then `TZ`, then the host clock. - **Naming**: `llmSlug: true` sends the conversation to the configured model to choose a descriptive file name; it falls back to the timestamp on failure. Leave it off to avoid the extra model call. - **Timing**: the snapshot is taken before the reset closes the window, then written in the background. `/new` returns before the file exists; wait for `Session context saved to ...` in the Gateway log. - **Exclusions**: incognito sessions never produce these files. - **Bounds**: capture scans at most 4,096 messages and 8 MiB of the departing session, so a very long conversation is never copied wholesale. - **Failure**: if the transcript cannot be read, the file can record that the content was unavailable instead of silently skipping the reset. Because the files land in `memory/`, they become part of what the agent's memory search can find later; how that search is configured is a separate memory subject. ## What command-logger records - One JSON line per emitted command event with `timestamp`, `action`, `sessionKey`, `senderId` and `source`; a missing sender or source becomes `unknown`. - Core emits `/new`, `/reset` and `/stop` only. `/model`, `/compact` or `/status` produce no line, and plugins may emit further actions. - The handler awaits the append and logs write errors. It sends nothing to chat. - It **never rotates** the file. Plan retention yourself. ## The other bundled hooks - `boot-md` runs the workspace `BOOT.md` through an agent run on `gateway:startup`, so it waits for the next Gateway start and can make model calls. - `bootstrap-extra-files` adds matching `AGENTS.md`, `SOUL.md` and similar files to context on `agent:bootstrap`. - `compaction-notifier` adds notices around compaction. ## Privacy and retention Both artifacts hold private data: session keys and sender identifiers in `commands.log`, conversation text in `memory/`. Raising `messages` saves more context per reset but also copies more private text into the workspace, where anything that can read the workspace can read it. Restrict file permissions on the Gateway host, decide how long to keep them, and disable a hook with `openclaw hooks disable <name>` when you no longer want its records. Disabling leaves the hook's files and its earlier output in place.
- Why might the memory file be missing right after `/new` returns?`session-memory` captures the departing conversation before the reset, then writes the file in the background; manual resets do not wait for the write or for an optional `llmSlug` model call. Wait for `Session context saved to ...` in the Gateway log, and check the resolved agent workspace rather than assuming the default one.
- Does `command-logger` capture `/model` or `/compact`?No. It logs emitted command events, and core emits them only for `/new`, `/reset` and `/stop`. A model change surfaces as a `session:patch` event instead, which `command-logger` does not subscribe to. Plugins may emit additional command actions, which would be logged.
- What does `llmSlug: true` cost you?Conversation text is sent to the configured model, or the one named by the entry's `model` option, to pick a descriptive file name. That is an extra model call per reset and another place the text travels. If the call fails the hook falls back to the timestamp name.
- session-memory writes a model-generated summary of the whole conversation.
- command-logger records every slash command a user types.
- commands.log is rotated automatically, so retention needs no thought.
- session-memory saves nothing on a daily or idle rollover, only on /new.
- Incognito sessions are saved by session-memory like any other session.
- Enabling boot-md makes it run BOOT.md on the already running Gateway.