Skip to content

feat(skills): compact skill paths with ~ to reduce prompt tokens#14776

Merged
steipete merged 2 commits intoopenclaw:mainfrom
bitfish3:feat/compact-skill-paths
Feb 18, 2026
Merged

feat(skills): compact skill paths with ~ to reduce prompt tokens#14776
steipete merged 2 commits intoopenclaw:mainfrom
bitfish3:feat/compact-skill-paths

Conversation

@bitfish3
Copy link

@bitfish3 bitfish3 commented Feb 12, 2026

Problem

Skill <location> tags in the system prompt use absolute paths like:

/Users/alice/.bun/install/global/node_modules/openclaw/skills/github/SKILL.md

Each path costs ~24 tokens. For a workspace with 90+ skills, this adds up to a significant chunk of the system prompt budget.

Solution

Add a compactSkillPaths() helper that replaces the home directory prefix with ~:

~/.bun/install/global/node_modules/openclaw/skills/github/SKILL.md

This is applied in buildWorkspaceSkillSnapshot and buildWorkspaceSkillsPrompt before passing skills to formatSkillsForPrompt.

Why this is safe

  • Models understand ~ — Claude, GPT-4, Gemini all resolve ~/ to the home directory
  • The read tool resolves ~ — OpenClaw's file read tool already handles tilde expansion
  • System prompt already instructs path resolution — the skills section tells the model to "resolve it against the skill directory"
  • No behavioral change — skills still load and execute identically

Impact

  • ~5–6 tokens saved per skill (home dir prefix like /Users/username~)
  • ~400–600 tokens total for a typical 90-skill workspace
  • ~3–4% reduction in system prompt size

Test

Added skills.compact-skill-paths.test.ts covering:

  • Home directory paths are compacted to ~/...
  • Paths outside home directory are preserved as-is

Greptile Overview

Greptile Summary

This PR introduces compactSkillPaths() in src/agents/skills/workspace.ts and applies it when building the skills prompt/snapshot so skill <location> tags replace the user’s home directory prefix with ~/ to save system-prompt tokens.

The core runtime change is isolated to prompt formatting (the Skill objects used for loading/frontmatter parsing remain untouched), but the newly added test file has issues that will prevent it from reliably validating the behavior across environments.

Confidence Score: 3/5

  • Mostly safe change, but tests need fixes before merge.
  • The production code change is small and limited to prompt formatting, but the new unit test likely fails to run due to an incorrect import path and the second test doesn’t actually assert the claimed behavior, reducing confidence in regression coverage.
  • src/agents/skills.compact-skill-paths.test.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: S labels Feb 12, 2026
@rmdmattingly
Copy link

CI failing (check): oxfmt formatting issue in src/agents/skills/workspace.ts.

Fix: run  ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND  No package.json (or package.yaml, or package.json5) was found in "/Users/raysopenclaw/.openclaw/workspace-dev-deploy". (oxfmt --write) and commit/push. Then CI should go green.

@rmdmattingly
Copy link

CI failing due to oxfmt formatting (real, not flaky): src/agents/skills/workspace.ts in run 21954976637.

Patch (oxfmt-only) that makes pnpm format:check pass:

diff --git a/src/agents/skills/workspace.ts b/src/agents/skills/workspace.ts
index 24d543a..05afcaf 100644
--- a/src/agents/skills/workspace.ts
+++ b/src/agents/skills/workspace.ts
@@ -287,7 +287,10 @@ export function buildWorkspaceSkillsPrompt(
     (entry) => entry.invocation?.disableModelInvocation !== true,
   );
   const remoteNote = opts?.eligibility?.remote?.note?.trim();
-  return [remoteNote, formatSkillsForPrompt(compactSkillPaths(promptEntries.map((entry) => entry.skill)))]
+  return [
+    remoteNote,
+    formatSkillsForPrompt(compactSkillPaths(promptEntries.map((entry) => entry.skill))),
+  ]
     .filter(Boolean)
     .join("\n");
 }

Fix locally with: pnpm exec oxfmt --write src/agents/skills/workspace.ts then push + re-run CI.

@rmdmattingly
Copy link

CI failure is from formatting:

  • check job fails at pnpm format:check (oxfmt) on src/agents/skills/workspace.ts.

Suggested fix: run pnpm format (or pnpm format:fix / oxfmt without --check) and push the resulting formatting-only change, then re-run CI.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { buildWorkspaceSkillsPrompt } from "./skills.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken test import path

buildWorkspaceSkillsPrompt is imported from ./skills.js, but under src/agents/ the entrypoint is skills.ts (and this repo doesn’t appear to have a skills.js alongside the test). This will fail module resolution in Vitest/TS (can’t run the new test). Update the import to the correct module (e.g. the existing src/agents/skills.ts entrypoint).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/skills.compact-skill-paths.test.ts
Line: 5:5

Comment:
**Broken test import path**

`buildWorkspaceSkillsPrompt` is imported from `./skills.js`, but under `src/agents/` the entrypoint is `skills.ts` (and this repo doesn’t appear to have a `skills.js` alongside the test). This will fail module resolution in Vitest/TS (can’t run the new test). Update the import to the correct module (e.g. the existing `src/agents/skills.ts` entrypoint).

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +59 to +62
it("preserves paths outside home directory", async () => {
// Skills outside ~ should keep their absolute paths
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-compact-"));
const skillDir = path.join(workspaceDir, "skills", "ext-skill");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test doesn’t match intent

This test claims it “preserves paths outside home directory”, but it creates the workspace under os.tmpdir() (which may or may not be under os.homedir() depending on platform) and never asserts that the <location> path stayed absolute vs compacted. As written it only checks that a <location>...SKILL.md</location> tag exists, so it won’t catch regressions in the compaction/preservation behavior.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/skills.compact-skill-paths.test.ts
Line: 59:62

Comment:
**Test doesn’t match intent**

This test claims it “preserves paths outside home directory”, but it creates the workspace under `os.tmpdir()` (which may or may not be under `os.homedir()` depending on platform) and never asserts that the `<location>` path stayed absolute vs compacted. As written it only checks that a `<location>...SKILL.md</location>` tag exists, so it won’t catch regressions in the compaction/preservation behavior.

How can I resolve this? If you propose a fix, please make it concise.

mac26ai and others added 2 commits February 18, 2026 01:34
Replace absolute home directory prefix with ~ in skill <location> tags
injected into the system prompt. Models understand ~ expansion and the
read tool resolves it, so this is a safe, backward-compatible change.

Saves ~5-6 tokens per skill path. For a workspace with 90+ skills,
this reduces system prompt size by ~400-600 tokens.

Changes:
- Add compactSkillPaths() helper in workspace.ts
- Apply in buildWorkspaceSkillSnapshot and buildWorkspaceSkillsPrompt
- Add test for path compaction behavior

Before: /Users/alice/.bun/install/global/node_modules/openclaw/skills/github/SKILL.md
After:  ~/.bun/install/global/node_modules/openclaw/skills/github/SKILL.md
@steipete steipete force-pushed the feat/compact-skill-paths branch from 2eb081d to 97444f7 Compare February 18, 2026 00:35
@steipete steipete merged commit 7694900 into openclaw:main Feb 18, 2026
3 checks passed
@steipete
Copy link
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm lint && pnpm build && pnpm test (build currently fails on pre-existing TS2722 in src/media-understanding/runner.entries.ts)
  • Land commit: 97444f7
  • Merge commit: 7694900

Thanks @bitfish3!

@HenryLoenwind
Copy link
Contributor

That's still a whole lot of tokens for those paths. Wouldn't it make sense to (on systems that support it*) add a symlink <openclawdir>/skills -> /node_modules/openclaw/skills`

/Users/alice/.bun/install/global/node_modules/openclaw/skills/github/SKILL.md
         vvv
~/.bun/install/global/node_modules/openclaw/skills/github/SKILL.md
         vvv
../skills/github/SKILL.md

and

/usr/local/lib/node_modules/openclaw/skills/github/SKILL.md
         vvv
../skills/github/SKILL.md

*) macOS, Linux, Windows w/ admin

sypherin pushed a commit to sypherin/openclaw that referenced this pull request Feb 18, 2026
treygoff24 pushed a commit to treygoff24/openclaw that referenced this pull request Feb 18, 2026
jun-planfit pushed a commit to planfit/openclaw that referenced this pull request Feb 19, 2026
anschmieg pushed a commit to anschmieg/openclaw that referenced this pull request Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments