Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (selftune) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
selftune — Skill Observability & Continuous Improvement CLI
Observe real sessions, detect missed triggers, grade execution quality, and automatically evolve skill descriptions toward the language real users actually use.
Works with Claude Code, Codex, and OpenCode.
Observe → Detect → Diagnose → Propose → Validate → Deploy → Watch → RepeatInstall
npx selftune@latest doctorOr install globally:
npm install -g selftune
selftune doctorRequires Bun or Node.js 18+ with tsx.
Why
Agent skills are static, but users are not. When a skill undertriggers — when someone says "make me a slide deck" and the pptx skill doesn't fire — that failure is invisible. The user concludes "AI doesn't follow directions" rather than recognizing the skill description doesn't match how real people talk.
selftune closes this feedback loop.
What It Does
| Capability | Description |
|---|---|
| Session telemetry | Captures per-session process metrics across all three platforms |
| False negative detection | Surfaces queries where a skill should have fired but didn't |
| Eval set generation | Converts hook logs into trigger eval sets with real usage as ground truth |
| Session grading | 3-tier evaluation (Trigger / Process / Quality) using the agent you already have |
| Skill evolution | Proposes improved descriptions, validates them, deploys with audit trail |
| Post-deploy monitoring | Watches evolved skills for regressions, auto-rollback on pass rate drops |
Quick Start
1. Initialize
npx selftune@latest initThe init command auto-detects your agent environment (Claude Code, Codex, or OpenCode), resolves the CLI path, determines the LLM mode, and writes config to ~/.selftune/config.json. All subsequent commands read from this config.
Use --agent claude_code|codex|opencode to override detection, --llm-mode agent|api to override LLM mode, or --force to reinitialize.
4. Install hooks (Claude Code)
If init reports hooks are not installed, merge the entries from skill/settings_snippet.json into ~/.claude/settings.json. Replace /PATH/TO/ with the absolute path to this repository.
5. Verify setup
selftune doctorDoctor checks log file health, hook installation, schema validity, and config status.
Platform-Specific Notes
Claude Code — Hooks capture telemetry automatically after installation. Zero configuration once hooks are in settings.json.
Codex — Use the wrapper for real-time capture or the batch ingestor for historical logs:
selftune wrap-codex -- <your codex args>
selftune ingest-codexOpenCode — Backfill historical sessions from SQLite:
selftune ingest-opencodeAll platforms write to the same shared JSONL log schema at ~/.claude/.
Commands
selftune <command> [options]| Command | Purpose |
|---|---|
init |
Auto-detect agent environment, write ~/.selftune/config.json |
grade --skill <name> |
Grade a session (3-tier: trigger, process, quality) |
evals --skill <name> |
Generate eval set from real usage logs |
evals --list-skills |
Show logged skills and query counts |
evolve --skill <name> --skill-path <path> |
Analyze failures, propose and deploy improved description |
rollback --skill <name> --skill-path <path> |
Restore pre-evolution description |
watch --skill <name> --skill-path <path> |
Monitor post-deploy pass rates, detect regressions |
doctor |
Health checks on logs, hooks, config, and schema |
ingest-codex |
Batch ingest Codex rollout logs |
ingest-opencode |
Backfill historical OpenCode sessions from SQLite |
wrap-codex -- <args> |
Real-time Codex wrapper with telemetry |
No separate API key required — grading and evolution use whatever agent CLI you already have installed. Set ANTHROPIC_API_KEY to use the API directly instead.
See skill/Workflows/ for detailed step-by-step guides for each command.
How It Works
Telemetry Capture
Claude Code (hooks): OpenCode (hooks):
UserPromptSubmit → prompt-log.ts message.* → opencode-prompt-log.ts
PostToolUse → skill-eval.ts tool.execute.after → opencode-skill-eval.ts
Stop → session-stop.ts session.idle → opencode-session-stop.ts
│ │
└──────────┬─────────────────────────┘
▼
Shared JSONL Log Schema (~/.claude/)
├── all_queries_log.jsonl
├── skill_usage_log.jsonl
└── session_telemetry_log.jsonl
Codex (wrapper/ingestor — hooks not yet available):
codex-wrapper.ts (real-time tee of JSONL stream)
codex-rollout.ts (batch ingest from rollout logs)
│
└──→ Same shared JSONL schemaEval & Grading
selftune evals cross-references the two query logs:
Positives = skill_usage_log entries for target skill
Negatives = all_queries_log entries NOT in positives
selftune grade reads:
session_telemetry_log → process metrics (tool calls, errors, turns)
transcript JSONL → what actually happened
expectations → what should have happenedEvolution Loop
selftune evolve:
1. Load eval set (or generate from logs)
2. Extract failure patterns (missed queries grouped by invocation type)
3. Generate improved description via LLM
4. Validate against eval set (must improve, <5% regression)
5. Deploy updated SKILL.md + PR + audit trail
selftune watch:
Monitor pass rate over sliding window of recent sessions
Alert (or auto-rollback) on regression > thresholdArchitecture
cli/selftune/
├── index.ts CLI entry point (command router)
├── init.ts Agent detection, config bootstrap
├── types.ts, constants.ts Shared interfaces and constants
├── observability.ts Health checks (doctor command)
├── utils/ JSONL, transcript parsing, LLM calls, schema validation
├── hooks/ Claude Code + OpenCode telemetry capture
├── ingestors/ Codex adapters + OpenCode backfill
├── eval/ False negative detection, eval set generation
├── grading/ 3-tier session grading (agent or API mode)
├── evolution/ Failure extraction, proposal, validation, deploy, rollback
└── monitoring/ Post-deploy regression detection
skill/
├── SKILL.md Routing table (~120 lines)
├── settings_snippet.json Claude Code hook config template
├── references/ Domain knowledge (logs, grading methodology, taxonomy)
└── Workflows/ Step-by-step guides (1 per command)Dependencies flow forward only: shared → hooks/ingestors → eval → grading → evolution → monitoring. Enforced by lint-architecture.ts.
Config persists at ~/.selftune/config.json (written by init, read by all commands via skill workflows).
See ARCHITECTURE.md for the full domain map and module rules.
Log Schema
Three append-only JSONL files at ~/.claude/:
| File | Record type | Key fields |
|---|---|---|
all_queries_log.jsonl |
QueryLogRecord |
timestamp, session_id, query, source? |
skill_usage_log.jsonl |
SkillUsageRecord |
timestamp, session_id, skill_name, query, triggered |
session_telemetry_log.jsonl |
SessionTelemetryRecord |
timestamp, session_id, tool_calls, bash_commands, skills_triggered, errors_encountered |
evolution_audit_log.jsonl |
EvolutionAuditEntry |
timestamp, proposal_id, action, details, eval_snapshot? |
The source field identifies the platform: claude_code, codex, or opencode.
Development
make check # lint + architecture lint + all tests
make lint # biome check + architecture lint
make test # bun testZero runtime dependencies. Uses Bun built-ins only.
Tips
- Run
selftune initfirst — everything else reads from the config it writes. - Let logs accumulate over several days before running evals — more diverse real queries = more reliable signal.
- All hooks are silent (exit 0) and take <50ms. Negligible overhead.
- Logs are append-only JSONL. Safe to delete to start fresh, or archive old files.
- Use
--max 75to increase eval set size once you have enough data. - Use
--seed 123for a different random sample of negatives. - Use
--dry-runwithevolveto preview proposals without deploying. - The
doctorcommand checks log health, hook presence, config status, and schema validity.
Milestones
| Version | Scope | Status |
|---|---|---|
| v0.1 | Hooks, ingestors, shared schema, eval generation | Done |
| v0.2 | Session grading, grader skill | Done |
| v0.3 | Evolution loop (propose, validate, deploy, rollback) | Done |
| v0.4 | Post-deploy monitoring, regression detection | Done |
| v0.5 | Agent-first skill restructure, init command, config bootstrap |
Done |