Agent harness optimizer

From oyi77/1ai-skills · View interactive version

Agent harness optimizer is an AI agent skill from the GitHub repository oyi77/1ai-skills. Use when agent harness optimization patterns for token efficiency, memory persistence, session management, and cross-harness parity. Use when optimizing agent performance, reducing token costs,.

How to use this skill

Skill file

Overview

Agent harness optimization is the practice of tuning the runtime environment that surrounds an AI agent -- model selection, prompt structure, hook configuration, memory persistence, and session management -- to maximize output quality while minimizing token cost and latency. Derived from real-world patterns across 10+ months of daily agentic work, these techniques apply to any harness: Claude Code, Cursor, OpenCode, Codex, Gemini, and beyond.

Anti-Rationalization Table

| Rationalization | Reality |

|---|---|

| "I'll figure it out as I go" | A structured approach saves time and reduces errors. Follow the workflow in this skill rather than improvising. |

| "I already know this topic" | Familiarity breeds shortcuts. Use the checklist to verify you haven't missed critical steps. |

| "This doesn't apply to my situation" | The patterns here generalize across contexts. Adapt, don't skip — the underlying principles hold. |

| "One more tool will fix it" | Adding complexity rarely solves process gaps. Master the core workflow first. |

When to Use

Trigger phrases:

When NOT to Use

Process

  1. Gather requirements and constraints from the user
  2. Validate prerequisites (tools, permissions, data)
  3. Execute the core operation with error handling
  4. Verify output meets quality standards
  5. Report results and log for future reference

1. Token Optimization Audit

Assess current token spend across three vectors:

Model Selection Routing

System Prompt Slimming

Background Process Isolation

2. Memory Persistence via Hooks

Implement session-persistent memory using hook-based save/load:

SessionStart Hook (Load)

# On session start, load prior context
# Read project memory, notepad, and recent session summary
cat .omc/project-memory.json 2>/dev/null
cat .omc/notepad.md 2>/dev/null

PreToolUse Hook (Capture)

# Capture tool calls and prompts for pattern extraction
echo "$(date +%s)|$TOOL_NAME|$INPUT_PREVIEW" >> .omc/session-trace.log

PostToolUse/Stop Hook (Save)

# On session end, persist learnings
# Save key decisions, patterns learned, errors encountered
# Keep under 2000 chars to avoid context bloat on next load

Memory File Structure

.omc/
  project-memory.json    # Persistent project context (conventions, stack, decisions)
  notepad.md             # Working memory (auto-pruned after 7 days)
  session-trace.log      # Tool call log for pattern extraction
  state/                 # Mode-specific state (autopilot, ralph, etc.)

3. Session Management

Manage agent sessions with structured lifecycle commands:

Branch -- Create isolated work contexts per task

Search -- Query prior session history

Export -- Extract session artifacts

Compact -- Reduce active context size

Metrics -- Track session efficiency

4. Hook Runtime Controls

Configure hook behavior at runtime without editing files:

# Set strictness profile
export ECC_HOOK_PROFILE=minimal    # Only critical hooks (security, error)
export ECC_HOOK_PROFILE=standard   # Default -- lint, typecheck, memory
export ECC_HOOK_PROFILE=strict     # All hooks including style, docs

# Disable specific hooks temporarily
export ECC_DISABLED_HOOKS="pre:bash:tmux-reminder,post:edit:typecheck"

# Cap SessionStart context size
export ECC_SESSION_START_MAX_CHARS=4000

# Disable SessionStart context for low-context setups
export ECC_SESSION_START_CONTEXT=off

# Suppress cost warnings but keep other context/scope warnings
export ECC_CONTEXT_MONITOR_COST_WARNINGS=off

Hook Profile Design Principles

5. Cross-Harness Parity

Ensure agent behavior is consistent across harnesses:

| Concern | Claude Code | Cursor | OpenCode | Codex | Gemini |

|---------|-------------|--------|----------|-------|--------|

| Rules location | ~/.claude/rules/ | .cursorrules | opencode.json | AGENTS.md | System prompt |

| Hooks | Native hook system | File watchers | Plugin events | None | None |

| Skills/Commands | Plugin + slash commands | Custom instructions | Plugins + commands | Markdown only | Prompt-only |

| Memory | .claude/ directory | .cursor/ | .opencode/ | Project root | External store |

| MCP | Native support | Limited | Plugin-based | None | None |

Parity Checklist

6. Continuous Learning from Sessions

Feed session patterns back into the system:

Observation Capture (automatic via hooks)

Pattern Detection (background analysis)

Evolution Path

Observation -> Instinct (0.3) -> Validated Instinct (0.7) -> Skill (0.9)

Common Rationalizations

| Rationalization | Reality |

|---|---|

| "The model is expensive so the harness does not matter" | Harness optimization typically reduces tokens 40-60% with no quality loss |

| "Hooks slow down my workflow" | A well-tuned hook profile adds under 2 seconds and catches errors that cost minutes to debug later |

| "Cross-harness support is not needed -- I only use Claude Code" | Team members and CI pipelines may use different harnesses; parity prevents drift |

| "Memory persistence is overkill for small projects" | Even small projects benefit from remembering past decisions to avoid re-debating settled questions |

| "System prompt length does not matter with 200K context" | Longer system prompts increase latency, cost, and the chance the model ignores key instructions |

Red Flags

Verification

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.