Openclaw Exec Truncate

Domain-aware output truncation for exec tool — compresses git diff/log, grep, ls, and build output to reduce token consumption

Install

openclaw plugins install clawhub:openclaw-exec-truncate

exec-truncate

Domain-aware output truncation for the OpenClaw exec tool.

Installs as an OpenClaw plugin. Intercepts exec / bash output, detects the command domain from output patterns, and compresses verbose output — git diffs, logs, grep results, directory listings, and build logs — down to their informative core.

# before
+import { defineConfig } from 'vite'                 # 2,847 lines of diff
+import { defineConfig } from 'vite'
...
+export default defineConfig({                       # +2,840 more lines
# after
+import { defineConfig } from 'vite'
  ... [2845 lines truncated by exec-truncate] ...
+export default defineConfig({

Token savings: 20–40% on typical git/build/grep output.


Supported Domains

DomainDetectsWhat it does
gitDiffdiff --git, index [hash]Additions-only head+tail; skips unchanged context lines
gitLog40-char hash + Author:One line per commit: hash7 | subject
grepfile:line:colStrips absolute paths; deduplicates identical matches
lsdrwxr-xr-x perms formatIcon + abbreviated size + name; strips perms/owner/time
builderror, Error, warning keywordsStrips ANSI, progress bars; keeps errors and warnings

Installation

openclaw plugins install exec-truncate
openclaw gateway restart

Or add to your openclaw.json:

{
  "plugins": {
    "entries": [
      { "module": "exec-truncate" }
    ]
  }
}

Uninstallation

Via OpenClaw CLI (recommended)

openclaw plugins uninstall exec-truncate
openclaw gateway restart

Via Uninstall Script

If the CLI is not available, use the bundled uninstall script:

cd /path/to/openclaw-exec-truncate
./uninstall.sh

Options:

  • --force: Skip confirmation prompt
  • Environment variable OPENCLAW_CONFIG_PATH: Override config location (default: ~/.openclaw/openclaw.json)

The uninstall script will:

  1. Find your OpenClaw config automatically
  2. Back up the config before modification
  3. Remove the exec-truncate entry from plugins.entries
  4. Verify removal succeeded
  5. Show backup location for recovery

Configuration

Defaults work out of the box. Override per domain in openclaw.json:

{
  "plugins": {
    "entries": [
      { "module": "exec-truncate" }
    ]
  },
  "skills": {
    "entries": {
      "exec-truncate": {
        "config": {
          "enabled": true,
          "gitDiff": { "headLines": 80, "tailLines": 20 },
          "gitLog": { "maxLines": 50 },
          "grep": { "maxMatches": 50 },
          "ls": { "maxEntries": 100 },
          "build": { "headLines": 10, "tailLines": 30 }
        }
      }
    }
  }
}
OptionDefaultDescription
enabledtrueMaster kill switch
gitDiff.headLines80Addition lines to keep at start
gitDiff.tailLines20Addition lines to keep at end
gitLog.maxLines50Max commit summary lines
grep.maxMatches50Max grep result lines
ls.maxEntries100Max directory entry lines
build.headLines10Build output lines to keep at start
build.tailLines30Error/warning lines to keep at end

Behavior

  • Small outputs pass through unchanged. Outputs under 200 characters are not truncated.
  • Detection is output-based, not command-based. The plugin reads the output content and identifies the domain from patterns — no command metadata required.
  • The MARKER... [N lines truncated by exec-truncate] ... — appears whenever lines are omitted, so you always know truncation happened.
  • All domains can be disabled individually via domain.enabled: false.

Testing

npm install
npm test        # 25 tests — truncation functions + hook integration

Architecture

tool_result_persist (synchronous hook)
  └── message.content
        ├── string → used directly
        └── array  → text parts joined, filtered to type:"text"
              ├── < 200 chars → returned unchanged
              ├── domain detected? → apply domain truncation
              └── no domain → returned unchanged

Changelog

  • 1.0.0 — Initial release. 5 domains: gitDiff, gitLog, grep, ls, build.

Built with OpenClaw Plugin SDK.