#22089: feat: persist default /usage mode via agents.defaults.usage
size: S
Cluster:
Compaction Enhancements and Features
## Summary
- Add `agents.defaults.usage` to agent defaults config schema and types.
- Wire session initialization so new sessions (including `/new` resets) use the configured usage default when no per-session `/usage` override exists.
- Preserve existing `/new` per-session `/usage` override behavior by carrying prior `responseUsage` when present.
- Add regression coverage in `initSessionState` for config-backed defaults and override precedence.
## Validation
- `pnpm test src/auto-reply/reply/session.test.ts`
- `pnpm test src/config/sessions.test.ts`
- `pnpm check` (format + tsgo + lint)
## Notes
This is intentionally scoped to one issue and keeps `/usage` slash-command behavior intact while making default usage mode persistent from `openclaw.json`.
Closes #22083.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds persistent `agents.defaults.usage` configuration to control the default `/usage` mode across sessions. The implementation correctly wires the config schema, types, and help text, and includes comprehensive test coverage for the happy paths.
**Critical issue found:**
- When `/new` is triggered on an existing session without a prior `/usage` override, the config default is ignored and `"off"` is used instead. This breaks the main feature of this PR - making the usage default persistent from config.
<h3>Confidence Score: 2/5</h3>
- This PR has a critical logical error that prevents the main feature from working correctly
- The implementation contains a bug in the reset logic that breaks the config default behavior - when users trigger `/new` on existing sessions without prior overrides, the config default is bypassed. The rest of the implementation (schema, types, tests for other scenarios) is solid, but this bug undermines the core functionality
- Pay close attention to `src/auto-reply/reply/session.ts:261` - the logic error will cause incorrect behavior for the main use case
<sub>Last reviewed commit: fdac13f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22140: feat(config): add usageDefault to agent defaults for persistent /us...
by Mellowambience · 2026-02-20
85.3%
#17109: fix: preserve responseUsage across session resets
by Limitless2023 · 2026-02-15
80.7%
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
76.6%
#8477: TUI: persist session token totals when usage metadata is missing
by LarHope · 2026-02-04
76.3%
#22701: fix(reply): make usage footer reflect full turn usage and avoid tra...
by artwalker · 2026-02-21
75.0%
#10998: fix(agents): pass session thinking/reasoning levels to session_stat...
by wony2 · 2026-02-07
74.5%
#13412: fix(sessions): refresh allowAgents permissions after gateway restart
by arun-dev-des · 2026-02-10
74.4%
#15793: fix(sessions): gracefully handle stale cross-agent session file paths
by lxcong · 2026-02-13
74.3%
#15982: fix: pass agentId to resolveSessionFilePath in reply flow (NX-003)
by automagik-genie · 2026-02-14
73.8%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
73.3%