agentleFS
suyashb734suyashb734/cliagents/CLAUDE.md

cliagents

CLAUDE.md19 starsChanged 7 months agoMITView on GitHub

A Node.js server that wraps CLI-based AI agents (Claude Code, Gemini CLI, Codex, etc.) and exposes them via HTTP REST API and WebSocket. For repo-local coding policy and stable agent guidance, start with AGENTS.md. Keep architecture notes, API details, and broader project documentation here and under docs/. Single unified database: data/cliagents.db

  • Sends data out

The file

We split this CLAUDE.md into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All errors follow a standardized format:

    line 167

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

cliagents

A Node.js server that wraps CLI-based AI agents (Claude Code, Gemini CLI, Codex, etc.) and exposes them via HTTP REST API and WebSocket.

For repo-local coding policy and stable agent guidance, start with AGENTS.md. Keep architecture notes, API details, and broader project documentation here and under docs/.

Quick Start

# Start server
npm start
# Server at http://localhost:4001
# WebSocket at ws://localhost:4001/ws

Architecture

┌─────────────────────────────────────────────────────────┐
│                Application Layer                         │
│              (HTTP REST + WebSocket)                     │
├─────────────────────────────────────────────────────────┤
│              Session Management Layer                    │
│         (SessionManager - handles lifecycle)             │
├─────────────────────────────────────────────────────────┤
│                 Adapter Layer                            │
│    ClaudeCodeAdapter    │    GeminiCliAdapter           │
├─────────────────────────────────────────────────────────┤
│                CLI Processes                             │
│     claude --resume      │    gemini -r latest          │
└─────────────────────────────────────────────────────────┘

Key Files

FilePurpose
src/index.jsMain entry point, exports
src/server/index.jsHTTP/WebSocket server
src/core/session-manager.jsSession lifecycle management
src/core/adapter.jsBase adapter class
src/adapters/claude-code.jsClaude Code CLI wrapper
src/adapters/gemini-cli.jsGemini CLI wrapper
src/database/db.jsUnified database (SQLite)
src/database/schema.sqlDatabase schema (8 tables)
src/routes/memory.jsShared memory REST endpoints
src/orchestration/handoff.jsAgent-to-agent task delegation
src/utils/gemini-config.jsGemini config.yaml manager (generation params)
src/services/transcriptionService.jsWhisper audio transcription

Database Schema

Single unified database: data/cliagents.db

┌─────────────────────────────────────────────────────────────┐
│                      cliagents.db (Unified)                  │
├─────────────────────────────────────────────────────────────┤
│  ORCHESTRATION       │  SHARED MEMORY       │  TRACING      │
│  ├── terminals       │  ├── artifacts       │  ├── traces   │
│  ├── inbox           │  ├── findings        │  └── spans    │
│  └── annotations     │  └── context         │               │
└─────────────────────────────────────────────────────────────┘

Tables

TablePurpose
terminalsRegistered CLI agent sessions
inboxMessage queue for inter-agent communication
tracesOrchestration traces for observability
spansIndividual operations within a trace
annotationsFile-based annotations (workspace_id, file_path)
artifactsCode, files, outputs from agents (task_id, key)
findingsInsights, bugs, issues from agents (task_id, severity)
contextConversation summaries for agent handoff

API Endpoints

GET  /health                 - Health check
GET  /openapi.json           - OpenAPI 3.0 specification
GET  /adapters               - List available adapters (includes available models)
POST /sessions               - Create new session
GET  /sessions               - List all sessions
GET  /sessions/:id           - Get session info
GET  /sessions/:id/status    - Get session status (running/stable/error)
POST /sessions/:id/interrupt - Interrupt active process
POST /sessions/:id/messages  - Send message (streaming with SSE)
POST /sessions/:id/files     - Upload files to session working directory
GET  /sessions/:id/files     - List files in session working directory
DELETE /sessions/:id         - Terminate session
POST /ask                    - One-shot ask (auto session)

# Shared Memory (Multi-Agent Collaboration)
POST   /orchestration/memory/artifacts           - Store an artifact
GET    /orchestration/memory/artifacts/:taskId   - Get all artifacts for a task
GET    /orchestration/memory/artifacts/:taskId/:key - Get specific artifact
DELETE /orchestration/memory/artifacts/:taskId/:key - Delete artifact

POST   /orchestration/memory/findings            - Store a finding
GET    /orchestration/memory/findings/:taskId    - Get all findings for a task
GET    /orchestration/memory/findings/by-id/:id  - Get finding by ID
DELETE /orchestration/memory/findings/:id        - Delete finding

POST   /orchestration/memory/context             - Store context
GET    /orchestration/memory/context/:taskId     - Get context for a task

GET    /orchestration/memory/tasks/:taskId       - Get complete memory for a task
DELETE /orchestration/memory/tasks/:taskId       - Clear all memory for a task

GET    /orchestration/memory/stats               - Get memory statistics
POST   /orchestration/memory/cleanup             - Clean up old entries

Session Options (POST /sessions)

{
  "adapter": "claude-code",     // or "gemini-cli"
  "model": "claude-sonnet-4-5-20250514",  // model selection
  "systemPrompt": "You are a helpful assistant",
  "workDir": "/tmp/project",
  "jsonSchema": {"type": "object", ...},  // Claude only - structured output
  "allowedTools": ["Read", "Write"],      // restrict available tools

  // Generation parameters (Gemini only - writes to ~/.gemini/config.yaml)
  "temperature": 0.7,           // 0.0-2.0
  "top_p": 0.9,                 // 0.0-1.0
  "top_k": 40,                  // integer
  "max_output_tokens": 8192     // integer (also works for Claude via env var)
}

Generation Parameters

ParameterClaudeGeminiNotes
temperature❌✅Controls randomness (0.0-2.0)
top_p❌✅Nucleus sampling threshold
top_k❌✅Top-k sampling
max_output_tokens✅✅Claude: via CLAUDE_CODE_MAX_OUTPUT_TOKENS env var; Gemini: via config.yaml
jsonSchema✅❌Structured JSON output enforcement

Message Options (POST /sessions/:id/messages)

{
  "message": "Your prompt here",
  "stream": true,           // Enable SSE streaming
  "timeout": 120000,        // Custom timeout in ms
  "jsonSchema": {...},      // Per-message schema override (Claude)
  "allowedTools": [...]     // Per-message tools override
}

File Upload (POST /sessions/:id/files)

{
  "files": [
    { "name": "data.txt", "content": "Hello", "encoding": "utf8" },
    { "name": "image.png", "content": "base64...", "encoding": "base64" }
  ]
}

Error Response Format

All errors follow a standardized format:

{
  "error": {
    "code": "session_not_found",
    "message": "The specified session was not found",
    "type": "session_not_found",
    "param": null
  }
}

Error codes include:

  • invalid_request_error (400) - Malformed request
  • missing_parameter (400) - Required parameter missing
  • session_not_found (404) - Session doesn't exist
  • adapter_not_found (404) - Unknown adapter
  • adapter_unavailable (503) - CLI not installed
  • timeout_error (504) - Request timed out
  • cli_error (500) - CLI process error
  • internal_error (500) - Server error

Usage Examples

One-shot ask (simplest)

curl -X POST http://localhost:4001/ask \
  -H "Content-Type: application/json" \
  -d '{"message": "What is 2+2?", "adapter": "claude-code"}'

Session-based (preserves context)

# Create session
curl -X POST http://localhost:4001/sessions \
  -d '{"adapter": "claude-code"}'
# Returns: {"sessionId": "abc123", ...}

# Send messages (context preserved)
curl -X POST http://localhost:4001/sessions/abc123/messages \
  -d '{"message": "My name is Suyash"}'

curl -X POST http://localhost:4001/sessions/abc123/messages \
  -d '{"message": "What is my name?"}'
# Returns: "Your name is Suyash" ✓

Integration with AI-Twin

This server is designed to work with the AI-Twin learning loop:

┌────────────────────────────────────────────────────────────┐
│ PROMPT TO AGENT                                            │
├────────────────────────────────────────────────────────────┤
│ Task: Book a flight on google.com/flights                  │
│                                                            │
│ ## PAST LEARNINGS FOR google.com:                          │
│ - Search box: role=combobox, aria-label contains "Search"  │
│ - Cookie consent popup appears first                       │
│                                                            │
│ Screenshot attached. What's next?                          │
└────────────────────────────────────────────────────────────┘
ComponentResponsibility
Neo4jStores learnings, workflows, patterns
AI-BrowserQueries Neo4j, builds prompts, executes actions
Agent ServerTranslates CLI calls, no knowledge of learnings
Agent (Claude/Gemini)Receives learnings as prompt context

Session Management

  • Sessions auto-timeout after 30 minutes of inactivity
  • Max 10 concurrent sessions (oldest evicted if exceeded)
  • Context preserved via CLI resume flags:
    • Claude: --resume <sessionId>
    • Gemini: -r latest

Configuration

const server = new AgentServer({
  port: 3001,
  sessionTimeout: 30 * 60 * 1000,  // 30 min
  maxSessions: 10,
  claudeCode: {
    timeout: 60000,
    skipPermissions: true
  },
  geminiCli: {
    timeout: 60000,
    yoloMode: true,
    model: 'gemini-2.5-flash'
  }
});

Testing

# Start server first
npm start

# Run tests (in another terminal)
npm test

Test files:

  • tests/run-all.js - Main automated test suite (health, adapters, sessions, streaming, context)
  • tests/test-file-context.js - File context preservation tests
  • tests/test-screenshot-context.js - Screenshot/image context tests
  • examples/test-basic.js - Basic usage example

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.