openclaw - 💡(How to fix) Fix Feature Request: Expose user message in agent:bootstrap hook context for query-conditioned context compression [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#60509Fetched 2026-04-08 02:50:13
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

The agent:bootstrap hook event currently provides workspaceDir, cfg, sessionKey, and bootstrapFiles in its context, but does not include the incoming user message. Adding the user message (or at minimum a query/topic string) would enable powerful context compression techniques that can reduce injected workspace token counts by 90-97%.

Root Cause

The agent:bootstrap hook event currently provides workspaceDir, cfg, sessionKey, and bootstrapFiles in its context, but does not include the incoming user message. Adding the user message (or at minimum a query/topic string) would enable powerful context compression techniques that can reduce injected workspace token counts by 90-97%.

Code Example

context: {
  bootstrapFiles: WorkspaceBootstrapFile[],
  workspaceDir: string,
  cfg: OpenClawConfig,
  sessionKey: string,
}

---

context: {
  bootstrapFiles: WorkspaceBootstrapFile[],
  workspaceDir: string,
  cfg: OpenClawConfig,
  sessionKey: string,
  userMessage?: string,  // The incoming user message that triggered this agent run
}
RAW_BUFFERClick to expand / collapse

Summary

The agent:bootstrap hook event currently provides workspaceDir, cfg, sessionKey, and bootstrapFiles in its context, but does not include the incoming user message. Adding the user message (or at minimum a query/topic string) would enable powerful context compression techniques that can reduce injected workspace token counts by 90-97%.

Motivation

Workspace bootstrap files (AGENTS.md, SOUL.md, MEMORY.md, TOOLS.md, etc.) are injected into the context window on every inference call. For a workspace with substantial memory and tool notes, this can easily reach 35KB+ of static content per turn.

Tools like SMELT (Schema-Aware Markdown Compilation for Efficient Local Token Inference) can perform query-conditioned selective emission — scoring workspace content against the actual user query and returning only relevant sections. In testing on a production OpenClaw workspace:

QueryRaw contextAfter SMELTReduction
Targeted question35KB1-2KB93-97%
Broad question35KB2-3KB90-93%

This translates directly to:

  • Lower API costs (fewer input tokens per call)
  • Faster TTFT (less context to process)
  • Better model attention (less irrelevant context to wade through)
  • Reduced compaction frequency (smaller system prompts = more room for conversation)

Current Limitation

The agent:bootstrap event context includes:

context: {
  bootstrapFiles: WorkspaceBootstrapFile[],
  workspaceDir: string,
  cfg: OpenClawConfig,
  sessionKey: string,
}

Without the user message, hooks can only apply static compression (Layer 2 semantic compilation), which yields only ~3% savings. The big wins (90%+) come from Layer 4 query-conditioned retrieval, which requires knowing what the user is asking about.

Proposed Change

Add the user message text to the agent:bootstrap event context:

context: {
  bootstrapFiles: WorkspaceBootstrapFile[],
  workspaceDir: string,
  cfg: OpenClawConfig,
  sessionKey: string,
  userMessage?: string,  // The incoming user message that triggered this agent run
}

This would allow bootstrap hooks to:

  1. Run query-conditioned retrieval on workspace files
  2. Replace bootstrapFiles[].content with compressed versions
  3. Dramatically reduce context size while preserving relevant information

Implementation Notes

  • The field should be optional (undefined for heartbeats, gateway startup, etc.)
  • For the first message in a session, this is straightforward
  • For subsequent messages, the bootstrap files are already in context from the system prompt — but if OpenClaw re-injects them per turn, the same optimization applies
  • Privacy consideration: the user message is already visible to the model; exposing it to a local hook running in the same Gateway process adds no new attack surface

Alternatives Considered

  • External proxy between OpenClaw and the API provider: Works but fragile and adds latency
  • Static compression only (no query conditioning): Only ~3% savings, not impactful
  • Moving workspace files to tool-based retrieval: Would work but loses the "always available" property of bootstrap context

References

extent analysis

TL;DR

Adding the user message to the agent:bootstrap event context can enable powerful context compression techniques, reducing injected workspace token counts by 90-97%.

Guidance

  • Modify the agent:bootstrap event context to include the userMessage field, allowing hooks to perform query-conditioned retrieval on workspace files.
  • Update bootstrap hooks to utilize the userMessage field for compression, replacing bootstrapFiles[].content with compressed versions.
  • Verify the effectiveness of the compression by measuring the reduction in context size and its impact on API costs, TTFT, and model attention.
  • Consider the optional nature of the userMessage field, handling cases where it may be undefined (e.g., heartbeats, gateway startup).

Example

context: {
  bootstrapFiles: WorkspaceBootstrapFile[],
  workspaceDir: string,
  cfg: OpenClawConfig,
  sessionKey: string,
  userMessage?: string,  // The incoming user message that triggered this agent run
}

Notes

The proposed change requires careful consideration of privacy implications, although the user message is already visible to the model. The implementation should handle cases where the userMessage field is undefined.

Recommendation

Apply the proposed change by adding the userMessage field to the agent:bootstrap event context, allowing for query-conditioned retrieval and significant context compression. This change can lead to substantial reductions in API costs, improved TTFT, and better model attention.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature Request: Expose user message in agent:bootstrap hook context for query-conditioned context compression [1 participants]