infinite-agentic-loop-claude

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Infinite Agentic Loop Claude Skill

Infinite Agentic Loop Claude Skill

Skill by ara.so — AI Agent Skills collection.
Skill by ara.so — AI Agent Skills 合集。

Overview

概述

The Infinite Agentic Loop is an experimental pattern that orchestrates multiple AI agents in parallel using Claude Code. It enables continuous, iterative generation of content (UI components, code, designs) where each iteration builds upon previous work while maintaining uniqueness and spec compliance.
Key Features:
  • Parallel sub-agent deployment for simultaneous generation
  • Progressive sophistication across iterations
  • Wave-based management for large batches
  • Custom Claude Code slash command system
  • Specification-driven generation
Infinite Agentic Loop是一种实验性模式,借助Claude Code实现多个AI代理的并行编排。它支持持续、迭代式的内容生成(UI组件、代码、设计),每次迭代都基于之前的成果构建,同时保持独特性并符合规范要求。
核心特性:
  • 并行部署子代理以实现同步生成
  • 迭代过程中逐步提升复杂度
  • 基于批次的大规模任务管理
  • 自定义Claude Code斜杠命令系统
  • 基于规范驱动的生成

Installation

安装

  1. Clone the repository:
bash
git clone https://github.com/disler/infinite-agentic-loop.git
cd infinite-agentic-loop
  1. Verify Claude Code installation:
bash
claude --version
  1. Check project configuration: The project includes
    .claude/settings.json
    and
    .claude/commands/infinite.md
    which define permissions and commands.
  2. Start Claude Code:
bash
claude
  1. 克隆仓库:
bash
git clone https://github.com/disler/infinite-agentic-loop.git
cd infinite-agentic-loop
  1. 验证Claude Code安装:
bash
claude --version
  1. 检查项目配置: 项目包含
    .claude/settings.json
    .claude/commands/infinite.md
    文件,用于定义权限和命令。
  2. 启动Claude Code:
bash
claude

Core Command: /project:infinite

核心命令:/project:infinite

The infinite agentic loop is triggered via a custom slash command:
bash
/project:infinite <spec_file> <output_dir> <count>
Parameters:
  • spec_file
    : Path to specification markdown file (e.g.,
    specs/invent_new_ui_v3.md
    )
  • output_dir
    : Directory where iterations will be saved
  • count
    : Number of iterations to generate, or "infinite" for continuous mode
无限代理循环通过自定义斜杠命令触发:
bash
/project:infinite <spec_file> <output_dir> <count>
参数说明:
  • spec_file
    : 规范markdown文件路径(例如:
    specs/invent_new_ui_v3.md
  • output_dir
    : 迭代成果保存目录
  • count
    : 生成的迭代次数,或使用"infinite"启用持续生成模式

Usage Patterns

使用模式

1. Single Generation (Testing/Development)

1. 单次生成(测试/开发)

bash
/project:infinite specs/invent_new_ui_v3.md src 1
Use this when:
  • Testing a new specification
  • Validating the setup
  • Generating a single proof-of-concept
bash
/project:infinite specs/invent_new_ui_v3.md src 1
适用场景:
  • 测试新规范
  • 验证环境配置
  • 生成单个概念验证成果

2. Small Batch (5 Iterations)

2. 小批量生成(5次迭代)

bash
/project:infinite specs/invent_new_ui_v3.md src_new 5
Deploys 5 parallel sub-agents simultaneously. Ideal for:
  • Rapid prototyping
  • Exploring design variations
  • Quick iteration cycles
bash
/project:infinite specs/invent_new_ui_v3.md src_new 5
同时部署5个并行子代理,适合:
  • 快速原型开发
  • 探索设计变体
  • 短周期迭代

3. Large Batch (20 Iterations)

3. 大批量生成(20次迭代)

bash
/project:infinite specs/invent_new_ui_v3.md src_new 20
Manages 20 iterations in coordinated batches of 5 agents. Best for:
  • Production-scale generation
  • Building component libraries
  • Comprehensive exploration of design space
bash
/project:infinite specs/invent_new_ui_v3.md src_new 20
以5个代理为一组协同管理20次迭代,最适用于:
  • 生产级内容生成
  • 构建组件库
  • 全面探索设计空间

4. Infinite Mode

4. 无限模式

bash
/project:infinite specs/invent_new_ui_v3.md infinite_src_new/ infinite
Continuous generation in waves until context limits. Use for:
  • Maximum variation generation
  • Long-running exploration
  • Building extensive libraries
bash
/project:infinite specs/invent_new_ui_v3.md infinite_src_new/ infinite
分批次持续生成直至达到上下文限制,用于:
  • 生成最大多样性的内容
  • 长期探索性生成
  • 构建大规模资源库

Creating Specification Files

创建规范文件

Specifications drive the generation. Create a markdown file in the
specs/
directory:
markdown
undefined
规范是生成过程的核心驱动,在
specs/
目录下创建markdown文件:
markdown
undefined

UI Component Specification

UI组件规范

Objective

目标

Generate unique, creative UI components that demonstrate modern design patterns.
生成独特、富有创意的UI组件,展现现代设计模式。

Requirements

要求

  • Must be self-contained HTML file
  • Include inline CSS and JavaScript
  • Responsive design
  • Accessibility compliant (ARIA labels)
  • No external dependencies
  • 必须是独立的HTML文件
  • 包含内联CSS和JavaScript
  • 响应式设计
  • 符合无障碍标准(ARIA标签)
  • 无外部依赖

Constraints

约束

  • Each iteration must be visually distinct
  • Maximum file size: 50KB
  • Must work in all modern browsers
  • 每次迭代的视觉效果必须独特
  • 文件大小上限:50KB
  • 需兼容所有现代浏览器

Creative Directions

创意方向

  • Explore different color palettes
  • Experiment with layout patterns
  • Try various interaction models
  • Incorporate subtle animations
undefined
  • 探索不同配色方案
  • 尝试多种布局模式
  • 测试各类交互模型
  • 融入微妙动画效果
undefined

Configuration

配置

.claude/settings.json

.claude/settings.json

json
{
  "allow_file_operations": true,
  "allow_shell_commands": true,
  "max_tokens": 200000,
  "commands_directory": ".claude/commands"
}
json
{
  "allow_file_operations": true,
  "allow_shell_commands": true,
  "max_tokens": 200000,
  "commands_directory": ".claude/commands"
}

Custom Command Structure (.claude/commands/infinite.md)

自定义命令结构(.claude/commands/infinite.md)

markdown
undefined
markdown
undefined

Infinite Agentic Loop Command

Infinite Agentic Loop命令

Command: /project:infinite

命令:/project:infinite

Implementation Steps:

实现步骤:

  1. Parse arguments (spec, output_dir, count)
  2. Read and analyze specification file
  3. Scan output directory for existing iterations
  4. Determine next iteration number
  5. Deploy sub-agents in parallel
  6. Monitor and coordinate generation
  7. Validate uniqueness and spec compliance
undefined
  1. 解析参数(spec, output_dir, count)
  2. 读取并分析规范文件
  3. 扫描输出目录中的已有迭代成果
  4. 确定下一次迭代编号
  5. 并行部署子代理
  6. 监控并协调生成过程
  7. 验证内容独特性与规范符合性
undefined

Working Code Examples

工作代码示例

Example 1: Basic Specification-Driven Generation

示例1:基础规范驱动生成

html
<!-- Generated iteration: ui_component_001.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interactive Card Component</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Segoe UI', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .card {
            background: white;
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            max-width: 400px;
            transition: transform 0.3s ease;
        }
        .card:hover { transform: translateY(-10px); }
    </style>
</head>
<body>
    <div class="card" role="article" aria-label="Interactive component">
        <h1>Iteration 001</h1>
        <p>Unique gradient-based card design</p>
    </div>
</body>
</html>
html
<!-- Generated iteration: ui_component_001.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Interactive Card Component</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Segoe UI', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .card {
            background: white;
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            max-width: 400px;
            transition: transform 0.3s ease;
        }
        .card:hover { transform: translateY(-10px); }
    </style>
</head>
<body>
    <div class="card" role="article" aria-label="Interactive component">
        <h1>Iteration 001</h1>
        <p>Unique gradient-based card design</p>
    </div>
</body>
</html>

Example 2: Custom Spec for API Documentation

示例2:API文档自定义规范

markdown
<!-- specs/api_docs_spec.md -->
markdown
<!-- specs/api_docs_spec.md -->

API Documentation Generator

API文档生成器

Objective

目标

Generate comprehensive API documentation pages with interactive examples.
生成包含交互式示例的全面API文档页面。

Technical Requirements

技术要求

  • OpenAPI 3.0 schema parsing
  • Syntax-highlighted code samples
  • Interactive request builder
  • Response visualization
  • 解析OpenAPI 3.0 schema
  • 语法高亮的代码示例
  • 交互式请求构建器
  • 响应可视化

Output Format

输出格式

Each iteration should produce:
  • api_docs_[number].html
    - Main documentation
  • Embedded JavaScript for interactivity
  • No external API calls (use mock data)
undefined
每次迭代需生成:
  • api_docs_[number].html
    - 主文档
  • 嵌入交互功能的JavaScript
  • 无外部API调用(使用模拟数据)
undefined

Example 3: Batch Processing Script

示例3:批量处理脚本

bash
#!/bin/bash
bash
#!/bin/bash

batch_generate.sh - Run multiple infinite loops in sequence

batch_generate.sh - 依次运行多个无限循环

SPECS=( "specs/ui_components.md" "specs/data_visualizations.md" "specs/form_patterns.md" )
for spec in "${SPECS[@]}"; do basename=$(basename "$spec" .md) echo "Generating from $spec..." claude << EOF /project:infinite $spec output/${basename}/ 10 EOF done
undefined
SPECS=( "specs/ui_components.md" "specs/data_visualizations.md" "specs/form_patterns.md" )
for spec in "${SPECS[@]}"; do basename=$(basename "$spec" .md) echo "Generating from $spec..." claude << EOF /project:infinite $spec output/${basename}/ 10 EOF done
undefined

Advanced Patterns

进阶模式

Pattern 1: Progressive Complexity

模式1:渐进式复杂度提升

Start with simple iterations and increase complexity:
bash
undefined
从简单迭代开始,逐步增加复杂度:
bash
undefined

Wave 1: Basic components

第一阶段:基础组件

/project:infinite specs/simple_ui.md wave1/ 5
/project:infinite specs/simple_ui.md wave1/ 5

Wave 2: Add interactions (reference wave1 in spec)

第二阶段:添加交互(规范中引用第一阶段成果)

/project:infinite specs/interactive_ui.md wave2/ 5
/project:infinite specs/interactive_ui.md wave2/ 5

Wave 3: Complex compositions

第三阶段:复杂组合

/project:infinite specs/complex_ui.md wave3/ 5
undefined
/project:infinite specs/complex_ui.md wave3/ 5
undefined

Pattern 2: Variation Exploration

模式2:变体探索

Generate variations on a theme:
markdown
<!-- specs/button_variations.md -->
生成同一主题的多种变体:
markdown
<!-- specs/button_variations.md -->

Creative Constraints

创意约束

Each iteration must:
  1. Use a different CSS animation
  2. Implement unique hover states
  3. Explore different shape paradigms (rounded, sharp, organic)
  4. Vary color psychology (calm, energetic, professional)
undefined
每次迭代必须:
  1. 使用不同的CSS动画
  2. 实现独特的悬浮状态
  3. 探索不同形状范式(圆角、尖锐、有机形态)
  4. 尝试不同色彩心理风格(沉稳、活力、专业)
undefined

Pattern 3: Cross-Pollination

模式3:交叉复用

Use outputs from one loop as inputs to another:
bash
undefined
将一个循环的输出作为另一个循环的输入:
bash
undefined

Generate base components

生成基础组件

/project:infinite specs/base_components.md components/ 10
/project:infinite specs/base_components.md components/ 10

Generate pages using those components (spec references components/)

使用这些组件生成页面(规范中引用components/目录)

/project:infinite specs/full_pages.md pages/ 5
undefined
/project:infinite specs/full_pages.md pages/ 5
undefined

Troubleshooting

故障排除

Issue: Command not found

问题:命令未找到

Solution: Ensure you're in the project directory and Claude Code is running:
bash
cd infinite-agentic-loop
claude
解决方案: 确保处于项目目录且Claude Code正在运行:
bash
cd infinite-agentic-loop
claude

Wait for prompt, then try /project:infinite

等待提示符出现后,再尝试执行/project:infinite

undefined
undefined

Issue: Iterations are too similar

问题:迭代成果过于相似

Solution: Enhance your specification with stronger creative constraints:
markdown
undefined
解决方案: 增强规范中的创意约束:
markdown
undefined

Uniqueness Requirements

独特性要求

  • Each iteration must use a different primary color family
  • Layout grid must vary (2-col, 3-col, masonry, etc.)
  • Typography scale must be distinct
undefined
  • 每次迭代必须使用不同的主色调系列
  • 布局网格需变化(2列、3列、瀑布流等)
  • 排版比例需独特
undefined

Issue: Context limit reached in infinite mode

问题:无限模式下达到上下文限制

Solution: This is expected. Review generated iterations and restart with refined specs:
bash
undefined
解决方案: 这是正常现象。查看已生成的迭代成果,使用优化后的规范重新启动:
bash
undefined

Analyze what was generated

分析已生成内容

ls -lh infinite_src_new/
ls -lh infinite_src_new/

Refine spec based on learnings

根据生成结果优化规范

vim specs/invent_new_ui_v3.md
vim specs/invent_new_ui_v3.md

Start fresh batch

启动新批次生成

/project:infinite specs/invent_new_ui_v3.md infinite_src_new_v2/ infinite
undefined
/project:infinite specs/invent_new_ui_v3.md infinite_src_new_v2/ infinite
undefined

Issue: Sub-agents generating errors

问题:子代理生成错误

Solution: Check
.claude/settings.json
permissions and validate spec file syntax:
bash
undefined
解决方案: 检查
.claude/settings.json
的权限设置,并验证规范文件语法:
bash
undefined

Validate JSON

验证JSON格式

cat .claude/settings.json | python -m json.tool
cat .claude/settings.json | python -m json.tool

Check spec file exists and is readable

检查规范文件是否存在且可读

cat specs/your_spec.md
undefined
cat specs/your_spec.md
undefined

Extending the Pattern

模式扩展

Global Command Installation

全局命令安装

Install the infinite command globally:
bash
mkdir -p ~/.claude/commands
cp .claude/commands/infinite.md ~/.claude/commands/
Now use
/infinite
from any Claude Code session.
将infinite命令安装为全局命令:
bash
mkdir -p ~/.claude/commands
cp .claude/commands/infinite.md ~/.claude/commands/
现在可在任意Claude Code会话中使用
/infinite
命令。

Multi-File Generation

多文件生成

Modify
.claude/commands/infinite.md
to generate sets of files:
markdown
undefined
修改
.claude/commands/infinite.md
以生成多文件集合:
markdown
undefined

Enhanced Output Structure

增强输出结构

For each iteration N, generate:
  • component_N.html (main file)
  • component_N.test.html (test file)
  • component_N.meta.json (metadata)
undefined
对于第N次迭代,生成:
  • component_N.html(主文件)
  • component_N.test.html(测试文件)
  • component_N.meta.json(元数据)
undefined

MCP Server Integration

MCP服务器集成

Create an MCP (Model Context Protocol) server for reusability:
javascript
// mcp-server.js
const { MCPServer } = require('@modelcontextprotocol/sdk');

const server = new MCPServer({
  name: 'infinite-agentic-loop',
  version: '1.0.0'
});

server.addTool({
  name: 'infinite_generate',
  description: 'Generate iterations using infinite agentic loop',
  parameters: {
    spec: { type: 'string', description: 'Specification file path' },
    output_dir: { type: 'string', description: 'Output directory' },
    count: { type: 'number', description: 'Number of iterations' }
  },
  execute: async ({ spec, output_dir, count }) => {
    // Implementation here
  }
});

server.start();
创建MCP(Model Context Protocol)服务器以实现复用:
javascript
// mcp-server.js
const { MCPServer } = require('@modelcontextprotocol/sdk');

const server = new MCPServer({
  name: 'infinite-agentic-loop',
  version: '1.0.0'
});

server.addTool({
  name: 'infinite_generate',
  description: 'Generate iterations using infinite agentic loop',
  parameters: {
    spec: { type: 'string', description: 'Specification file path' },
    output_dir: { type: 'string', description: 'Output directory' },
    count: { type: 'number', description: 'Number of iterations' }
  },
  execute: async ({ spec, output_dir, count }) => {
    // 实现代码
  }
});

server.start();

Best Practices

最佳实践

  1. Start Small: Test with count=1 before large batches
  2. Iterate on Specs: Refine specifications based on output quality
  3. Monitor Resources: Watch memory/CPU during large batches
  4. Version Control: Commit specs and generated outputs separately
  5. Document Learnings: Track what specification patterns work best
  1. 从小规模开始: 在大批量生成前先以count=1测试
  2. 迭代优化规范: 根据输出质量不断完善规范
  3. 监控资源: 大批量生成时关注内存/CPU使用情况
  4. 版本控制: 分别提交规范文件和生成成果
  5. 记录经验: 追踪哪些规范模式效果最佳

Resources

资源