Agent skill

Loop Engineering

by huytieu in huytieu/COG-second-brain

Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns.

MITAuto-check passedAgent Workflows

Install Loop Engineering

skills CLI
$ npx skills add huytieu/COG-second-brain --skill loop-engineering -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install huytieu/COG-second-brain loop-engineering --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/huytieu/COG-second-brain.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/loop-engineering .claude/skills/loop-engineering && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
loop-engineering
GitHub stars
1.3k
Token cost
~1.5k tokens
SKILL.md length
747 words
Files
1
Skills in repo
37
Repo updated
First seen
Licence
MIT

At a glance

Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns.

  • Works in 4 steps: The loop in one or two lines (what… → The verifier (the mechanical pass/fail). → The termination conditions (verifier… → …
  • Tasks that involve Autonomous loops
  • SKILL.md covers Why loops, The COG loop, Termination conditions (use… and Verification first (COG's…, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Loop Engineering is an agent skill from huytieu/COG-second-brain. Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns. Invoke when designing or debugging a skill that iterates (search-verify-retry, scan-until-dry, fetch-retry-gate).

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Agent Workflows, covering Autonomous loops and Context engineering. The repository describes itself as: Self-evolving second brain with 35 AI skills, 10 agents, and people CRM. Closed-loop harness: a V-model verification lifecycle where the worker never grades its own homework… The licence is MIT.

When your agent uses it

  • Tasks that involve Autonomous loops
  • Tasks that involve Context engineering

Example prompts

  • “/loop-engineering”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. The loop in one or two lines (what repeats).
  2. The verifier (the mechanical pass/fail).
  3. The termination conditions (verifier plus safety exits).
  4. The pattern(s) from the table above.

What it can do on your machine

Read from SKILL.md and the folder at commit 36ac9d7. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Loop Engineering loads about 1.5k tokens when it runs. Until then it costs about 74 tokens; SKILL.md has 747 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~74
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from huytieu/COG-second-brain at commit 36ac9d7, republished under its MIT licence (© huytieu). 747 words, ~1,511 tokens.

Download SKILL.mdSave it as .claude/skills/loop-engineering/SKILL.md (or your agent's skills folder).
name
loop-engineering
description
Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns. Invoke when designing or debugging a skill that iterates (search-verify-retry, scan-until-dry, fetch-retry-gate).
roles
all

COG Loop Engineering

TL;DR: Some COG skills are not one-shot prompts. They are loops: act, observe, verify, decide whether to continue. This skill is the shared vocabulary those skills use. The iron rule: trust deterministic checks, never the agent's own "looks done" self-report. Every loop must declare its verifier, its stopping conditions, and which pattern it follows.

This is a reference and design aid, not a content-generating workflow. Skills that loop (daily-brief, knowledge-consolidation, url-dump, weekly-checkin, and research/triage skills like auto-research and scout) link here instead of restating the rules. Invoke it directly when you are building or fixing an iterative skill.

Why loops

A chain runs fixed steps: A then B then C. A loop is dynamic: the agent takes an action, reads real feedback (a fetched page, a date stamp, a file count), reasons about it, and repeats until a goal is met or a stop condition fires. Most knowledge-work that "keeps going until good enough" is a loop, and COG benefits from naming the loop explicitly rather than hoping a single prompt nails it.

The COG loop

   ┌──────────────────────────────────────────────┐
   │  1. Gather    pull context (vault + sources)   │
   │  2. Act       one step: search / fetch / scan  │
   │  3. Observe   read the real result             │
   │  4. Verify    run the deterministic check      │
   │  5. Update    write progress to a vault file   │
   │  6. Decide    continue?  → loop                │
   │               stop?      → finish + report     │
   └──────────────────────────────────────────────┘

Step 4 is the load-bearing one. A loop without a verifier is just a chain that repeats.

Termination conditions (use layers, never one)

A robust loop needs several exits so it always halts:

ExitWhat it isExample
Deterministic verifierA mechanical pass/fail that confirms the goal"Publication date is within 7 days"
Hard iteration capMax passes, no matter what"Stop after 5 searches per topic"
Budget guardMax time / tool calls / tokens"Stop after 20 fetches total"
No-progress detectionRecent passes changed nothing"2 searches in a row found nothing new"
Human escalationHand a stuck loop back to the user"Asked twice, still unclear: ask the user"

Pick the verifier plus at least one safety exit (cap or budget) for every loop. No-progress detection is what stops the quiet infinite loops that a cap alone misses.

Verification first (COG's rule, applied to loops)

COG is verification-first: no hallucinations, sources required. Inside a loop that means:

  • Prefer mechanical checks. A date comparison, a source count, a "required field is non-empty", a "file marked consolidated" check cannot be gamed and cannot be hallucinated.
  • Reserve judgment-based checks for the genuinely unquantifiable (is this theme actually new? is this summary faithful?). When you must use judgment, state confidence and link evidence.
  • Never accept the agent's own "I think this is complete." That is the single most common way loops produce confident garbage.
Show full SKILL.md (337 more words)Show less

In-loop context management

Long loops fill the window with old tool output and start to drift ("context rot"). Counter it:

  • Externalize state to the vault. Write progress to the output file as you go. The vault file is the memory; the conversation is scratch.
  • Compact and prune. Summarize finished passes into a line or two. Drop raw page text once you have extracted what you need.
  • Isolate sub-agents. In agent_mode: team, give each worker only the slice it needs and take back only its conclusion, so one subtask runs in a clean window. Never paste one worker's raw output into the next worker's prompt.

Named patterns

PatternShapeWhere COG uses it
Act-observe (ReAct)reason → act → observe → repeatbase of every COG loop
Reflect-retry (Reflexion)on failure, write the lesson, retry differentlyurl-dump / scout fetch retries, daily-brief re-search
Plan-execute-verifyplan steps, run them, verify eachknowledge-consolidation passes
Evaluator-optimizergenerate, score against criteria, repeat until it passesdaily-brief item verify, url-dump quality gate
Orchestrator-workerssplit into subtasks, run in fresh windows, synthesizeteam-mode scans, auto-research threads, team-brief
Loop-until-drykeep going until K passes in a row surface nothing newknowledge-consolidation theme extraction
Human-in-the-loopescalate or ask when the loop is stuck or the call is the user'sweekly-checkin reflection, onboarding

Failure modes and fixes

FailureFix
Context overflow / driftcompact, prune, externalize to vault, isolate sub-agents
Silent infinite loopno-progress detection plus a hard cap
Hallucinated successtrust the deterministic verifier, never self-report
Compounding errorsverify early and every pass, not only at the end
Cost blowupbudget guard, and stop at "good enough", not "perfect"
Goal driftkeep the goal and stop conditions written at the top of the loop's state

How skills use this

A skill's ## Loop Engineering section should be short and concrete. It names:

  1. The loop in one or two lines (what repeats).
  2. The verifier (the mechanical pass/fail).
  3. The termination conditions (verifier plus safety exits).
  4. The pattern(s) from the table above.

It does not restate this skill. It points here.

© huytieu, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/loop-engineering of huytieu/COG-second-brain.

Open the folder on GitHubat commit 36ac9d7

Compare with similar skills

Loop Engineering next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Loop Engineering compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Loop Engineering this skillhuytieu/COG-second-brain1.3k—~1.5kAutomated safety check: PassMIT
Harness Engineering10xChengTu/harness-engineering1021 repos~1kAutomated safety check: PassNone
Harness Long-Running Task LoopChachamaru127/claude-code-harness3.2k—~2.3kAutomated safety check: NotesMIT
Session Handoffdavila7/claude-code-templates32k2 repos~1.6kAutomated safety check: PassMIT
Harness Engineeringmagnus919/agent-skills111—~3.5kAutomated safety check: PassMIT
Agents Best PracticesDenisSergeevitch/agents-best-practices2.4k—~7.4kAutomated safety check: PassMIT

Similar skills

  • Harness Engineering

    10xChengTu/harness-engineering

    Set up and improve harness engineering (AGENTS.md, docs/, lint rules, eval systems, project-level prompt engineering) for AI-agent-friendly codebases.

    102 GitHub starsUsed in 1 repo~1k tokens
    Agent WorkflowsAuto-check passed
  • Harness Long-Running Task Loop

    Chachamaru127/claude-code-harness

    Repeats a long task as a series of scheduled wake-ups, each re-entering with fresh context and calling harness-work for one task per cycle.

    3.2k GitHub stars~2.3k tokensUpdated 2 days ago
    Agent WorkflowsAuto-check: notes
  • Session Handoff

    davila7/claude-code-templates

    Creates comprehensive handoff documents for seamless AI agent session transfers.

    32k GitHub starsUsed in 2 repos~1.6k tokens
    Agent WorkflowsAuto-check passed
  • Harness Engineering

    magnus919/agent-skills

    Design, build, diagnose, and evolve agent harnesses: instructions, tools, execution environments, durable state, context management, verification, recovery, and bounded autonomous loops.

    111 GitHub stars~3.5k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • Agents Best Practices

    DenisSergeevitch/agents-best-practices

    A skill your agent uses when designing, generating an MVP blueprint for, auditing, troubleshooting, refactoring, or explaining an agentic harness for any domain.

    2.4k GitHub stars~7.4k tokensUpdated 3 days ago
    AI & LLM EngineeringAuto-check passed
  • Agent Refocusing

    mvschwarz/openrig

    Re-grounds a long-running agent in the current product outcome by running a path-based trace to the root of its topology and work trees.

    5.5k GitHub stars~399 tokensUpdated today
    Agent WorkflowsAuto-check passed

More from huytieu/COG-second-brain

All 37 skills in this repo
  • Voice Baseline

    huytieu/COG-second-brain

    Measure your own writing corpus for the words and sentence shapes you over-use, so an agent writing in your voice stops amplifying your tics into a style.

    1.3k GitHub stars~957 tokensUpdated 5 days ago
    Auto-check passed
  • Daily Journal

    huytieu/COG-second-brain

    A passive daily work journal that Claude keeps FOR you so you never have to write it yourself.

    1.3k GitHub stars~1.3k tokensUpdated 5 days ago
    Auto-check passed
  • Editorial Illustrations

    huytieu/COG-second-brain

    Generate meaning-carrying editorial data-illustrations in the monotykamary / Linear aesthetic (near-black grayscale, Inter display + mono labels, hairline framed figures) with a single coral accent.

    1.3k GitHub stars~2.4k tokensUpdated 5 days ago
    Auto-check passed
  • Knowledge Consolidation

    huytieu/COG-second-brain

    Build frameworks from scattered insights across all braindumps and notes

    1.3k GitHub starsUsed in 1 repo~2.9k tokens
    Auto-check passed
  • Release Video

    huytieu/COG-second-brain

    Turn a product release (the list of shipped items plus real screen recordings) into a motion recap video and one explained demo per feature, with sound effects tied to on-screen motion and a…

    1.3k GitHub stars~1.7k tokensUpdated 5 days ago
    Auto-check passed
  • Onboarding

    huytieu/COG-second-brain

    Personalize COG for your workflow - creates profile, interests, and watchlist files with guided setup (run this first!)

    1.3k GitHub starsUsed in 1 repo~3.1k tokens
    Auto-check passed

Categories

Questions about Loop Engineering

What does Loop Engineering do?

Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns. Loop Engineering is an agent skill from huytieu/COG-second-brain. Shared loop-engineering reference for COG skills - the agent loop, deterministic verifiers, termination conditions, in-loop context management, and named patterns.

When should I use Loop Engineering?

Loop Engineering fits situations like: tasks that involve Autonomous loops; tasks that involve Context engineering.

How do I install Loop Engineering in Claude Code?

Run `npx skills add huytieu/COG-second-brain --skill loop-engineering -a claude-code`. Or copy the skill folder (skills/loop-engineering in huytieu/COG-second-brain) into .claude/skills/loop-engineering in your project. Claude Code loads it when a task matches its description.

How do I install Loop Engineering in Codex?

Run `npx skills add huytieu/COG-second-brain --skill loop-engineering -a codex`. Or copy the skill folder (skills/loop-engineering in huytieu/COG-second-brain) into .agents/skills/loop-engineering in your project. Codex loads it when a task matches its description.

Can I use Loop Engineering in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add huytieu/COG-second-brain --skill loop-engineering -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/loop-engineering, .gemini/skills/loop-engineering, .github/skills/loop-engineering and .opencode/skills/loop-engineering in your project.

What does Loop Engineering need to run?

SKILL.md names no scripts, command-line tools or credentials: Loop Engineering is instructions for the agent only.

Does Loop Engineering access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Loop Engineering safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Loop Engineering use?

Loop Engineering is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Loop Engineering use?

About 1.5k tokens (SKILL.md is roughly 6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Loop Engineering?

Skills that share tags, products or a category with Loop Engineering: Harness Engineering (10xChengTu/harness-engineering, 102 stars), Harness Long-Running Task Loop (Chachamaru127/claude-code-harness, 3.2k stars), Session Handoff (davila7/claude-code-templates, 32k stars) and Harness Engineering (magnus919/agent-skills, 111 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Loop Engineering?

huytieu (a GitHub user) maintains it in huytieu/COG-second-brain, which has 1,260 GitHub stars. The repository holds 37 skills in this directory. The repository was last updated on October 2, 2026.

Source: huytieu/COG-second-brain on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.