Skip to main content

Architecture Overview

4.1 Overall Architecture

4.2 Session Startup Flow

These two platforms’ Hook systems automatically trigger session-start.py at session start, no need to manually enter /start. Users can describe tasks immediately after opening the terminal. Optionally run /start for a more detailed context report.
When you enter /start (or when the Claude Code Hook fires automatically), here’s what happens behind the scenes:
session-start.py is a SessionStart Hook that fires automatically at the start of each new session, ensuring the AI always begins with full context.

4.3 Spec Injection Mechanism

Automatic spec injection is a Claude Code exclusive feature, relying on the Hook system (PreToolUse intercepting Task tool calls). Cursor, Codex, OpenCode, and other platforms require manually loading specs via commands (e.g., /before-backend-dev).
inject-subagent-context.py is the core engine of Trellis. When the main Agent invokes a sub-Agent (e.g., Implement), this Hook automatically intercepts and injects context. Workflow:

JSONL Configuration Format Explained

JSONL (JSON Lines) files define which files each Agent needs to read. Each line is a JSON object:
Field descriptions: Three types of JSONL files: Practical example (implement.jsonl for a backend task):
Injection timing and control:
  • implement Agent: injects implement.jsonl + prd.md + info.md
  • check Agent: injects check.jsonl + prd.md (to understand intent)
  • check Agent ([finish] marker): lightweight injection of finish-work.md + prd.md
  • debug Agent: injects debug.jsonl + codex-review-output.txt (if available)
  • research Agent: injects project structure overview + research.jsonl (optional)

4.4 Quality Control Loop (Ralph Loop)

Ralph Loop is a Claude Code exclusive quality control mechanism, relying on the SubagentStop Hook. Cursor and other platforms require manually running /check-backend (/trellis-check-backend) or /check-frontend for code checks.
Ralph Loop is based on the Ralph Wiggum technique, automatically verifying when the Check Agent finishes its work.
Two verification modes: Mode A — Programmatic verification (recommended, configured in worktree.yaml):
Ralph Loop runs each command in sequence; all must return 0 to pass. Mode B — Completion Markers (fallback when no verify config): Markers are generated from check.jsonl reason fields. For example:
Generated markers: TYPECHECK_FINISH, LINT_FINISH. The Check Agent must include all markers in its output to stop. State tracking: Ralph Loop tracks iteration count via .trellis/.ralph-state.json:
  • Resets automatically on task switch
  • 30-minute timeout auto-reset
  • Force pass at 5 iterations (prevents infinite loops)

4.5 Complete Agent System

Trellis includes 6 built-in Agents, each with different roles, tools, and responsibilities: Agent Collaboration Flow (Multi-Agent Pipeline):
Dispatch Agent Timeout Configuration: