Comprehensive guide for integrating selftune into any project structure. selftune makes your agent skills self-improving — it watches real sessions, learns how you work, and evolves skill descriptions to match automatically. Supports Claude Code, Codex, OpenCode, and OpenClaw.
The fastest path for most projects:
# 1. Initialize selftune (auto-detects agent and workspace type)
selftune init
# 2. Verify everything is working
selftune doctor
# 3. Refresh source-truth telemetry
selftune sync
# 4. Inspect health
selftune statusselftune init now detects your workspace structure (single-skill, multi-skill,
or monorepo) and suggests the appropriate template. See the sections below for
project-specific setup.
For Claude Code, hooks provide low-latency local signal:
- prompt logging
- best-effort skill-use hints
- session-stop telemetry
But the authoritative view is now source-truth sync:
- Claude transcripts
- Codex rollout logs
- OpenCode history
- OpenClaw session history
Run selftune sync before trusting status, dashboard, watch, or evolve,
especially on polluted hosts or after large batches of agent activity.
If your primary ~/.claude is modified by another system or routing layer,
keep using selftune's sandbox harness as the clean regression environment while
treating host-machine sync output as the real-world proof source.
A project with one SKILL.md file and straightforward hooks.
Structure:
my-project/
skill/
SKILL.md
cli/selftune/
hooks/
prompt-log.ts
skill-eval.ts
session-stop.ts
auto-activate.ts
Setup:
- Run
selftune init. It will detect the single skill automatically. - Merge
templates/single-skill-settings.jsoninto~/.claude/settings.json. Replace/PATH/TOwith the absolute path to your selftune installation. - Run
selftune doctorto verify local install health. - Run
selftune syncafter real sessions to rebuild source-truth telemetry.
Template: templates/single-skill-settings.json
What you get:
- Prompt logging on every user query
- Skill evaluation on every
Readtool use - Session telemetry on session stop
- Auto-activation suggestions when metrics are low
Important: the hooks are convenience signals for Claude Code only. The
authoritative usage view still comes from selftune sync.
A project with multiple SKILL.md files. Activation rules route queries to
the correct skill for evaluation.
Structure:
my-project/
skills/
auth/SKILL.md
deploy/SKILL.md
monitoring/SKILL.md
cli/selftune/
hooks/
prompt-log.ts
skill-eval.ts
session-stop.ts
auto-activate.ts
skill-change-guard.ts
evolution-guard.ts
Setup:
- Run
selftune init. It will detect multiple skills and suggest the multi-skill template. - Merge
templates/multi-skill-settings.jsoninto~/.claude/settings.json. - Copy
templates/activation-rules-default.jsonto~/.selftune/activation-rules.jsonand customize rule thresholds if needed. - Run
selftune doctor. - Run
selftune syncafter sessions to rebuild the repaired/source-truth overlay.
Template: templates/multi-skill-settings.json
Differences from single-skill:
- Includes
evolution-guard.tsinPreToolUsehooks to protect active evolutions - Activation rules (
activation-rules.json) control which suggestions fire - Each skill gets independent eval/grade/evolve cycles
- Workflow discovery becomes useful once telemetry accumulates: run
selftune workflowsto find repeated multi-skill chains andselftune workflows save <workflow-id|index>to codify them into## Workflowsin the relevant SKILL.md
Activation Rules:
selftune ships with four default activation rules (see cli/selftune/activation-rules.ts):
| Rule ID | Trigger | Suggestion |
|---|---|---|
post-session-diagnostic |
>2 unmatched queries in session | selftune last |
grading-threshold-breach |
Session pass rate < 60% | selftune evolve |
stale-evolution |
No evolution in >7 days + pending false negatives | selftune evolve |
regression-detected |
Monitoring snapshot shows regression | selftune rollback |
Rules fire at most once per session (tracked via session state files in ~/.selftune/).
To disable a rule, set "enabled": false in your activation-rules.json.
A project with package.json workspaces, pnpm-workspace.yaml, or lerna.json.
Each package can have its own skill.
Structure:
my-monorepo/
package.json # { "workspaces": ["packages/*"] }
packages/
core/
skill/SKILL.md
api/
skill/SKILL.md
web/
skill/SKILL.md
cli/selftune/
hooks/
Setup:
- Run
selftune initfrom the monorepo root. It detects the workspace structure. - Use the
templates/multi-skill-settings.jsontemplate (monorepos are multi-skill). - Each package's
SKILL.mdis independently tracked for eval and grading. - Run
selftune doctor. - Run
selftune syncto refresh usage/telemetry from actual session history.
Tips:
- Run
selftune initfrom the monorepo root, not from individual packages. - Skill paths are stored as absolute paths in telemetry, so cross-package analysis works.
- Use
selftune status --skill <name>to check per-skill metrics.
Using selftune with OpenAI Codex instead of Claude Code.
Setup:
- Run
selftune init --agent codex. - Codex does not support Claude Code hooks. Use the wrapper approach:
# Wrap codex sessions for real-time telemetry
selftune wrap-codex -- codex <your-args>- Or batch-ingest existing sessions:
selftune ingest-codex --dir /path/to/codex/sessionsLimitations:
- No real-time hook-based telemetry (Codex has no hook system)
- Eval and grading work the same way once sessions are ingested
- Auto-activation suggestions are not available (no
UserPromptSubmithook)
After wrapping or ingesting Codex activity, run selftune sync before
trusting status/evolution decisions.
Using selftune with OpenCode.
Setup:
- Run
selftune init --agent opencode. - OpenCode stores sessions in a SQLite database. Import them:
selftune ingest-opencodeThe default database path is ~/.local/share/opencode/opencode.db.
Override with --db /path/to/opencode.db.
Limitations:
- Same as Codex: no real-time hooks, batch ingest only
- Session format differs; selftune normalizes on import
After import, run selftune sync before checking status, watch, or evolve.
Using selftune with OpenClaw. This is the richest integration path — OpenClaw supports cron-based autonomous evolution, hot-reloading of evolved skills, and isolated session execution.
Setup (batch ingest):
- Run
selftune init --agent openclaw. - Import existing sessions:
selftune ingest-openclawThis scans ~/.openclaw/agents/*/sessions/*.jsonl for all agent sessions.
Use --since 2026-02-01 to limit scope. Use --dry-run to preview.
- Run
selftune doctorto verify logs are healthy. - Run
selftune syncso all imported sessions flow into the repaired/source-truth overlay.
Options:
| Flag | Description |
|---|---|
--agents-dir <path> |
Override default ~/.openclaw/agents/ directory |
--since <date> |
Only ingest sessions modified after this date (YYYY-MM-DD) |
--dry-run |
Preview what would be ingested without writing to logs |
--force |
Re-ingest all sessions, ignoring the marker file |
--verbose / -v |
Show per-session progress during ingestion |
Skill detection: OpenClaw doesn't explicitly log skill triggers. selftune
infers triggers by detecting SKILL.md file reads and matching tool call names
against known skill names from OpenClaw's skill directories.
Multi-agent support: If you run multiple OpenClaw agents, selftune scans
all directories under ~/.openclaw/agents/ automatically.
OpenClaw autonomous cron loop (optional):
OpenClaw users can also register selftune jobs with OpenClaw's Gateway Scheduler
for fully autonomous evolution. See the Automation section below
and skill/Workflows/Cron.md for details.
Using selftune across multiple agent platforms (e.g., Claude Code + Codex + OpenClaw).
Setup:
- Run
selftune initon each agent platform:- On the Claude Code machine:
selftune init --agent claude_code - On the Codex machine:
selftune init --agent codex - On the OpenClaw machine:
selftune init --agent openclaw
- On the Claude Code machine:
- Each agent writes telemetry to
~/.selftune/in a shared format. - Merge telemetry for cross-agent analysis:
# Ingest Codex sessions alongside Claude Code telemetry
selftune ingest-codex --dir /path/to/sessions
# Ingest OpenClaw sessions
selftune ingest-openclaw
# View combined dashboard
selftune dashboardShared telemetry format:
All agents produce the same JSONL log format (session_telemetry_log.jsonl,
skill_usage_log.jsonl, all_queries_log.jsonl). The source field in each
record identifies the originating agent.
Tips:
- Use
selftune statusto see aggregated metrics across agents. - Grading and evolution work on the merged dataset.
- Keep
~/.selftune/config.jsonagent-specific on each machine.
selftune sync is the source-truth telemetry command. It replays Claude
transcripts, Codex rollout logs, OpenCode history, and OpenClaw sessions into
the canonical JSONL logs, then rebuilds the repaired skill-usage overlay.
Run it before trusting status, dashboard, watch, or evolve.
Flags:
| Flag | Description |
|---|---|
--since <date> |
Only sync sessions modified on/after this date (YYYY-MM-DD) |
--dry-run |
Show summary without writing files |
--force |
Ignore per-source markers and rescan everything |
--no-claude |
Skip Claude transcript replay |
--no-codex |
Skip Codex rollout ingest |
--no-opencode |
Skip OpenCode ingest |
--no-openclaw |
Skip OpenClaw ingest |
--no-repair |
Skip rebuilt skill-usage overlay |
--projects-dir <dir> |
Override Claude transcript directory (default: ~/.claude/projects) |
--codex-home <dir> |
Override Codex home directory (default: ~/.codex) |
--openclaw-agents-dir <dir> |
Override OpenClaw agents directory |
selftune uses Claude Code hooks for real-time telemetry. Here is the full hook chain:
| Hook Event | Script | Purpose |
|---|---|---|
UserPromptSubmit |
prompt-log.ts |
Log every user query to all_queries_log.jsonl |
UserPromptSubmit |
auto-activate.ts |
Evaluate activation rules and show suggestions |
PreToolUse (Write/Edit) |
skill-change-guard.ts |
Prevent unreviewed changes to SKILL.md files |
PreToolUse (Write/Edit) |
evolution-guard.ts |
Block changes that conflict with active evolutions |
PostToolUse (Read) |
skill-eval.ts |
Track which skills are triggered by queries |
Stop |
session-stop.ts |
Capture end-of-session telemetry |
All hooks:
- Exit code 0 on success (non-blocking by design)
- Write to stderr for advisory messages (shown to Claude as system messages)
- Have 5-15 second timeouts to avoid blocking the agent
- Fail open: errors are silently caught, never interrupting the session
Portable hook dispatch: Instead of hardcoding absolute paths to hook scripts
in settings.json, use selftune hook <name>:
selftune hook prompt-log
selftune hook session-stop
selftune hook skill-eval
selftune hook auto-activate
selftune hook skill-change-guard
selftune hook evolution-guardThis lets you write selftune hook prompt-log (or npx selftune hook prompt-log)
in your hook configuration, which resolves the correct script path at runtime.
selftune is designed to run unattended on any machine. The core automation loop is centered on one command:
selftune orchestrate
selftune orchestrate runs source-truth sync first, selects candidate skills,
deploys validated low-risk description changes autonomously, and watches recent
deployments with auto-rollback enabled.
Fastest path:
selftune init --enable-autonomyRun selftune schedule to generate or install ready-to-use snippets for your platform.
The simplest path. Install it directly:
selftune schedule --install --format cronOr inspect the raw crontab first with selftune schedule --format cron.
For macOS machines that need scheduling to survive reboots and sleep/wake:
selftune schedule --install --format launchdRun selftune schedule --format launchd for raw plist output without installing it.
For systemd-based servers:
selftune schedule --install --format systemdIf you use OpenClaw, selftune cron setup registers jobs directly with
OpenClaw's Gateway Scheduler. This provides isolated sessions per cron run
and an autonomous orchestrated loop without manual scheduler setup.
selftune cron setup # register autonomous jobs
selftune cron setup --dry-run # preview first
selftune cron list # check registered jobsSee skill/Workflows/Cron.md for the full OpenClaw cron reference.
Run selftune doctor and address each failing check:
| Check | Fix |
|---|---|
| Config missing | Run selftune init |
| Hooks not installed | Merge the appropriate template into ~/.claude/settings.json |
| Log directory missing | Run selftune init --force |
| Stale config | Run selftune init --force to regenerate |
- Verify hooks are in
~/.claude/settings.json:cat ~/.claude/settings.json | grep selftune
- Check that paths in settings.json point to actual files.
- Ensure
bunis on PATH (hooks usebun run). - Check hook timeouts: if a hook exceeds its timeout, Claude Code skips it silently.
- Check that log files exist:
ls -la ~/.claude/*_log.jsonl
- Verify the hooks are running by checking stderr output during a session.
- Run
selftune lastafter a session to see if data was captured.
- Rules fire at most once per session. Start a new session to see suggestions again.
- Check
~/.selftune/session-state-*.jsonfor session state. - If using PAI alongside selftune, PAI takes priority for skill-level suggestions (selftune defers to avoid duplicate nags).
-
Verify OpenClaw agents directory exists:
ls ~/.openclaw/agents/ -
Check that sessions are stored as
.jsonlfiles under each agent'ssessions/directory. -
Use
--verboseto see per-session progress:selftune ingest-openclaw --verbose -
Use
--forceto re-ingest all sessions if the marker file is stale. -
If using a custom agents directory:
selftune ingest-openclaw --agents-dir /custom/path
System cron / launchd / systemd:
- Verify
selftuneis on PATH in the cron environment (cron has a minimal PATH). - Use absolute paths if needed:
which selftuneto find the binary. - Check cron logs:
grep selftune /var/log/syslog(Linux) or Console.app (macOS).
OpenClaw cron:
- Verify jobs are registered:
selftune cron list - Check OpenClaw cron status:
openclaw cron list - Newly created jobs may require a Gateway restart (known OpenClaw bug).
- Verify timezone is correct:
selftune cron setup --tz <your-timezone> - Check if cron is blocked by Docker sandbox mode (OpenClaw issue #29921).
- Preview what would run:
selftune cron setup --dry-run
- Each agent should have its own
~/.selftune/config.jsonwith the correctagent_type. - Telemetry logs are append-only and use the
sourcefield to distinguish agents. - If logs are on different machines, copy the
.jsonlfiles into a shared directory and re-run analysis.
If selftune init detects the wrong workspace type:
- Use
--forceto reinitialize. - The detection scans for
SKILL.mdfiles and monorepo markers (package.jsonworkspaces,pnpm-workspace.yaml,lerna.json). - Directories named
node_modules,.git,dist,build,.next, and.cacheare always excluded from the scan.