openclaw-workspace-audit
Workspace Audit
Audit OpenClaw workspace documents for redundancy, compliance, conflicts, and token efficiency. Propose targeted fixes without losing meaning or breaking agent behavior.
Scope
Auditable files (all workspace-relative):
| File | Role | Loaded | Token impact |
|---|---|---|---|
AGENTS.md |
Operating instructions | Every session (system prompt) | HIGH — always injected |
SOUL.md |
Persona/tone | Every session (system prompt) | HIGH — always injected |
USER.md |
User profile | Every session (system prompt) | HIGH — always injected |
TOOLS.md |
Local tool notes | Every session (system prompt) | HIGH — always injected |
IDENTITY.md |
Agent identity | Every session (system prompt) | MEDIUM — small file |
HEARTBEAT.md |
Heartbeat tasks | Each heartbeat poll | LOW — only on heartbeat |
BOOT.md |
Startup checklist | Gateway restart (hooks) | LOW — only on boot |
MEMORY.md |
Long-term memory | Main session only | HIGH — main session |
memory/*.md |
Daily logs | On-demand via memory tools | LOW — not auto-injected |
Not in scope: ~/.openclaw/openclaw.json, ~/.openclaw/skills/, session transcripts, OS/host security (use healthcheck skill for those).
Core rules
- Read-only by default. Never modify files without explicit approval.
- Propose, don't execute. Show exact diffs/rewrites and wait for go-ahead.
- Preserve semantics. Every removal must prove the meaning is retained or the content is genuinely dead.
- Numbered choices for every decision point so user can reply with a digit.
- No auto-scheduling. Only offer cron scheduling after audit completes.
Workflow
Phase 0: Pre-flight
- Confirm the workspace path (default: repo root from runtime metadata).
- Read each file and record: exists / missing / line count / estimated char count.
- Present a summary table with file sizes and token estimates (~4 chars/token).
- Ask which audit scope to run (numbered):
- Full audit — all files, all checks
- Token diet — focus on reducing token consumption of always-injected files
- Memory cleanup — focus on
MEMORY.md+memory/hygiene - Compliance check — format/spec issues only
- Single file — user picks one file to audit
Phase 1: Format compliance
For each file, compare against the official template at:
/opt/homebrew/lib/node_modules/openclaw/docs/reference/templates/<FILE>.md
Check:
- AGENTS.md: Has required sections (First Run, Every Session, Memory, Safety)? Uses correct memory file paths (
memory/YYYY-MM-DD.md)? ReferencesSOUL.md,USER.md,MEMORY.mdcorrectly? - SOUL.md: Defines persona boundaries? Includes continuity guidance? Avoids duplicating AGENTS.md operating instructions?
- USER.md: Has Name, Timezone, Notes? Avoids embedding secrets or API keys?
- TOOLS.md: Contains only environment-specific notes (not general skill instructions)? Avoids duplicating skill SKILL.md content?
- IDENTITY.md: Has Name, Creature, Vibe, Emoji fields? Avatar path valid?
- HEARTBEAT.md: Short enough to avoid token burn? Tasks are actionable, not stale?
- BOOT.md: Short, explicit startup instructions? Uses message tool for outbound?
- MEMORY.md: Only loaded in main session? Contains curated long-term info, not raw daily logs?
- memory/*.md: Follows
YYYY-MM-DD.mdnaming? No timestamp filenames? No stale files older than configured retention?
Report each finding as: ✅ Pass / ⚠️ Warning / ❌ Fail with one-line explanation.
Phase 2: Redundancy & dead content
Scan for:
- Cross-file duplication — Same rule/instruction appearing in multiple files (e.g., safety rules in both AGENTS.md and SOUL.md).
- Internal duplication — Repeated content within a single file.
- Dead references — Mentions of tools, paths, files, or projects that no longer exist. Verify by checking filesystem.
- Obsolete rules — Instructions tied to old OpenClaw versions or deprecated features. Cross-check against current docs at
/opt/homebrew/lib/node_modules/openclaw/docs/. - Stale memory entries —
MEMORY.mditems superseded by newer entries, or daily memory files with content already distilled intoMEMORY.md.
For each finding, report:
- What: the duplicated/dead content (quote it)
- Where: file + line range
- Why it's removable: brief justification
- Risk if removed: what breaks (if anything)
Phase 3: Token efficiency
Calculate and report:
- Per-file char/token estimate for always-injected files.
- Total system prompt overhead from workspace files (sum of AGENTS + SOUL + USER + TOOLS + IDENTITY + HEARTBEAT if present + MEMORY if main session).
- Reduction opportunities ranked by token savings:
- Verbose explanations that can be compressed
- Examples/templates that can move to reference files
- Comments/notes that are self-documenting and add no instruction value
- Markdown formatting overhead (excessive headers, tables where bullets suffice)
Present a before/after comparison: current tokens vs projected tokens after proposed changes.
Phase 4: Cross-file conflict detection
Check for:
- Contradictory instructions — e.g., AGENTS.md says "always ask before external actions" but SOUL.md says "be bold with internal ones" (not a conflict) vs actual contradictions.
- Role bleeding — Operating instructions in SOUL.md (should be in AGENTS.md), persona rules in AGENTS.md (should be in SOUL.md), tool-specific notes in AGENTS.md (should be in TOOLS.md).
- Memory policy conflicts — Different memory rules in AGENTS.md vs actual MEMORY.md structure.
- Group chat rules — Conflicting engagement rules across files.
Phase 5: Report & remediation
Produce a structured report:
## Audit Report — [date]
### Summary
- Files audited: N
- Total workspace tokens: ~XXXK
- Issues found: N (X critical, Y warnings, Z info)
### Critical issues (must fix)
...
### Warnings (should fix)
...
### Optimization opportunities
| Change | File | Token savings | Risk |
|--------|------|--------------|------|
| ... | ... | ~NNN tokens | Low/Med/High |
### Recommended actions (numbered)
1. ...
2. ...
3. Skip / do nothing
After presenting the report, offer (numbered):
- Apply all safe changes — execute low-risk fixes with user approval per file
- Apply critical only — fix only ❌ items
- Export plan — write remediation plan to a file for later
- Do nothing — report only
Phase 6: Execute (if approved)
For each approved change:
- Show the exact edit (old → new) before applying.
- Apply via
edittool (surgical edits, not full rewrites). - After all edits, re-calculate token counts and show the delta.
Phase 7: Memory cleanup (if scope includes memory)
For memory/ directory:
- List all files with dates and sizes.
- Identify files older than 30 days that have NOT been distilled into
MEMORY.md. - Identify files with naming violations (timestamps, slugs instead of
YYYY-MM-DD.md). - Propose archival or deletion (never auto-delete — always ask).
For MEMORY.md:
- Check for entries superseded by newer facts.
- Check for entries that are purely narrative (no actionable conclusion).
- Propose condensation where possible.
Anti-patterns to flag
AGENTS.mdover 300 lines (official template is ~150 lines; bloat hurts every session)SOUL.mdcontaining operating instructions (belongs in AGENTS.md)TOOLS.mdcontaining general skill documentation (belongs in skill SKILL.md files)MEMORY.mdcontaining raw daily logs (belongs inmemory/YYYY-MM-DD.md)HEARTBEAT.mdover 30 lines (token burn on every heartbeat)- Secrets/API keys in any workspace file (should be in
~/.openclaw/or env vars) memory/files with non-date filenames (violates convention)- Duplicate safety rules across AGENTS.md and SOUL.md
Token budget reference
From official docs (bootstrapMaxChars default: 20,000 per file; bootstrapTotalMaxChars default: 150,000 total):
| File | Recommended max | Rationale |
|---|---|---|
| AGENTS.md | ~4,000 chars (~1K tokens) | Injected every session |
| SOUL.md | ~2,000 chars (~500 tokens) | Injected every session |
| USER.md | ~1,500 chars (~375 tokens) | Injected every session |
| TOOLS.md | ~3,000 chars (~750 tokens) | Injected every session |
| IDENTITY.md | ~500 chars (~125 tokens) | Small by design |
| HEARTBEAT.md | ~500 chars (~125 tokens) | Runs often |
| MEMORY.md | ~8,000 chars (~2K tokens) | Main session only |
These are soft targets, not hard limits. The goal is awareness, not enforcement.
Memory writes
After a completed audit, if the user opts in, append a dated summary to memory/YYYY-MM-DD.md:
- Files audited and their sizes
- Key findings (issues found, tokens saved)
- Actions taken
- Any deferred items
Append-only. Never overwrite existing entries. Redact sensitive details.
Scheduling
After a completed audit, offer to schedule periodic re-audits via cron (numbered):
- Monthly audit reminder (recommended)
- Weekly audit reminder
- No scheduling
Use stable cron name: workspace-audit:periodic. Check for existing job before creating.