Note: This file is specific to Claude Code. An identical AGENTS.md file is also maintained following the AGENTS.md standard for cross-tool compatibility with Cursor, GitHub Copilot, and other AI coding assistants. Both files contain the same content and should be kept synchronized.
THIS IS THE CODEV SOURCE REPOSITORY - WE ARE SELF-HOSTED
This project IS Codev itself, and we use our own methodology for development. All new features and improvements to Codev should follow the SPIR protocol defined in codev/protocols/spir/protocol.md.
This repository has a dual nature that's important to understand:
-
codev/- This is OUR instance of Codev- This is where WE (the Codev project) keep our specs, plans, reviews, and resources
- When working on Codev features, you work in this directory
- Example:
codev/specs/1-test-infrastructure.mdis a feature spec for Codev itself
-
codev-skeleton/- This is the template for OTHER projects- This is what gets copied to other projects when they install Codev
- Contains the protocol definitions, templates, and agents
- Does NOT contain specs/plans/reviews (those are created by users)
- Think of it as "what Codev provides" vs "how Codev uses itself"
When to modify each:
- Modify
codev/: When implementing features for Codev (specs, plans, reviews, our architecture docs) - Modify
codev-skeleton/: When updating protocols, templates, or agents that other projects will use
To release a new version, tell the AI: Let's release v1.6.0. The AI follows the RELEASE protocol (codev/protocols/release/protocol.md). Release candidate workflow and local testing procedures are documented there. For local testing shortcuts, see codev/resources/testing-guide.md.
To test changes locally before publishing to npm:
# From packages/codev directory:
cd packages/codev
# 1. Build and create tarball (Tower stays up during this)
npm run build
npm pack
# 2. Install (Tower stays up — running process already loaded old code)
npm install -g ./cluesmith-codev-*.tgz
# 3. Restart (only this step needs downtime)
af tower stop && af tower start- Install while Tower is running — it doesn't affect the running process
- Do NOT stop Tower before installing — unnecessary downtime
- Do NOT delete the tarball — keep it for debugging if restart fails
- Do NOT build between stop and start
- Do NOT use
npm link— it breaks global installs
When making changes to UI code (tower, dashboard, terminal), you MUST test using Playwright before claiming the fix works. See codev/resources/testing-guide.md for Playwright patterns and Tower regression prevention.
New to Codev? See the Cheatsheet for philosophies, concepts, and tool reference.
You are working in the Codev project itself, with multiple development protocols available:
Available Protocols:
- SPIR: Multi-phase development with consultation -
codev/protocols/spir/protocol.md - ASPIR: Autonomous SPIR (no human gates on spec/plan) -
codev/protocols/aspir/protocol.md - AIR: Autonomous Implement & Review for small features -
codev/protocols/air/protocol.md - TICK: Amendment workflow for existing specs -
codev/protocols/tick/protocol.md - EXPERIMENT: Disciplined experimentation -
codev/protocols/experiment/protocol.md - MAINTAIN: Codebase maintenance (code hygiene + documentation sync) -
codev/protocols/maintain/protocol.md
Key locations:
- Protocol details:
codev/protocols/(Choose appropriate protocol) - Project tracking: GitHub Issues (source of truth for all projects)
- Specifications go in:
codev/specs/ - Plans go in:
codev/plans/ - Reviews go in:
codev/reviews/
GitHub Issues are the source of truth for project tracking.
- Issues with the
speclabel have approved specifications - Issues with the
planlabel have approved plans - Active builders are tracked via
codev/projects/<id>/status.yaml(managed by porch) - The workspace overview Work view shows builders, PRs, and backlog derived from GitHub + filesystem state
When to use which:
- Starting work: Check GitHub Issues for priorities and backlog
- During implementation: Use
porch status <id>for detailed phase status - After completion: Close the GitHub Issue when PR is merged
🚨 CRITICAL: Two human approval gates exist:
- conceived → specified: AI creates spec, but ONLY the human can approve it
- committed → integrated: AI can merge PRs, but ONLY the human can validate production
AI agents must stop at conceived after writing a spec, and stop at committed after merging.
🚨 CRITICAL: Approved specs/plans need YAML frontmatter and must be committed to main.
When the architect creates and approves a spec or plan before spawning a builder, it must have YAML frontmatter marking it as approved and validated, and be committed to main. Porch always runs the full protocol from specify — but when it finds an existing artifact with this metadata, it skips that phase as a no-op. If no spec/plan exists, porch drives the builder to create one.
Frontmatter format:
---
approved: 2026-01-29
validated: [gemini, codex, claude]
---Responsiveness is paramount. The user should never wait for you. Use run_in_background: true for any operation that takes more than ~5 seconds.
| Task Type | Expected Duration | Action |
|---|---|---|
| Running tests | 10-300s | run_in_background: true |
| Consultations (consult) | 60-250s | run_in_background: true |
| E2E test suites | 60-600s | run_in_background: true |
| npm install/build | 5-60s | run_in_background: true |
| Quick file reads/edits | <5s | Run normally |
Critical: Using & at the end of the command does NOT work - you MUST set the run_in_background parameter.
- Bug reported as a GitHub Issue
- Fix is isolated (< 300 LOC net diff)
- No spec/plan artifacts needed
- Single builder can fix independently
BUGFIX uses GitHub Issues as source of truth. See codev/protocols/bugfix/protocol.md.
- Small features (< 300 LOC) fully described in a GitHub Issue
- No architectural decisions needed
- No spec/plan artifacts — review goes in the PR body
- Would be overkill for full SPIR/ASPIR ceremony
AIR uses GitHub Issues as source of truth. Two phases: Implement → Review. See codev/protocols/air/protocol.md.
- Amendments to an existing SPIR spec that is already
integrated - Small scope (< 300 lines of new/changed code)
- Clear requirements that extend existing functionality
TICK modifies spec/plan in-place and creates a new review file. Cannot be used for greenfield work.
- Creating a new feature from scratch (no existing spec to amend)
- New protocols or protocol variants
- Major changes to existing protocols
- Complex features requiring multiple phases
- Architecture changes
- Same as SPIR but without human approval gates on spec and plan
- Trusted, low-risk work where spec/plan review can be deferred to PR
- Builder runs autonomously through Specify → Plan → Implement → Review
- Human approval still required at the PR gate before merge
ASPIR is identical to SPIR except spec-approval and plan-approval gates are removed. See codev/protocols/aspir/protocol.md.
- Testing new approaches or techniques
- Evaluating models or libraries
- Proof-of-concept work
- Research spikes
- Removing dead code and unused dependencies
- Quarterly codebase maintenance
- Before releases (clean slate for shipping)
- Syncing documentation (arch.md, lessons-learned.md, CLAUDE.md/AGENTS.md)
- README typos or minor documentation fixes
- Small bug fixes in templates
- Dependency updates
- When asked to build NEW FEATURES FOR CODEV: Start with the Specification phase
- Create exactly THREE documents per feature: spec, plan, and review (all with same filename)
- Follow the SPIR phases: Specify → Plan → Implement → Review
- Use multi-agent consultation by default unless user says "without consultation"
project-root/
├── codev/
│ ├── protocols/ # Development protocols
│ │ ├── spir/ # Multi-phase development with consultation
│ │ ├── tick/ # Fast autonomous implementation
│ │ ├── experiment/ # Disciplined experimentation
│ │ └── maintain/ # Codebase maintenance (code + docs)
│ ├── maintain/ # MAINTAIN protocol runtime artifacts
│ │ └── .trash/ # Soft-deleted files (gitignored, 30-day retention)
│ ├── projects/ # Active project state (managed by porch)
│ ├── specs/ # Feature specifications (WHAT to build)
│ ├── plans/ # Implementation plans (HOW to build)
│ ├── reviews/ # Reviews and lessons learned from each feature
│ └── resources/ # Reference materials
│ ├── arch.md # Architecture documentation (updated during MAINTAIN)
│ ├── testing-guide.md # Local testing, Playwright, regression prevention
│ └── lessons-learned.md # Extracted wisdom from reviews (generated during MAINTAIN)
├── .claude/
│ └── agents/ # AI agent definitions (custom project agents)
├── AGENTS.md # Universal AI agent instructions (AGENTS.md standard)
├── CLAUDE.md # This file (Claude Code-specific, identical to AGENTS.md)
└── [project code]
- npm install / npm run build / npm test → always run from
packages/codev/ - E2E tests →
packages/codev/tests/e2e/ - Unit tests →
packages/codev/tests/unit/ - Never run npm commands from the repository root unless explicitly told to.
Use sequential numbering with descriptive names (no leading zeros):
- Specification:
codev/specs/42-feature-name.md - Plan:
codev/plans/42-feature-name.md - Review:
codev/reviews/42-feature-name.md
CRITICAL: Keep Specs and Plans Separate
- Specs define WHAT to build (requirements, acceptance criteria)
- Plans define HOW to build (phases, files to modify, implementation details)
- Each document serves a distinct purpose and must remain separate
DEFAULT BEHAVIOR: Consultation is ENABLED by default with:
- Gemini 3 Pro (gemini-3-pro-preview) for deep analysis
- GPT-5.4 Codex (gpt-5.4-codex) for coding and architecture perspective
To disable: User must explicitly say "without multi-agent consultation"
CRITICAL CONSULTATION CHECKPOINTS (DO NOT SKIP):
- After writing implementation code → STOP → Consult GPT-5 and Gemini Pro
- After writing tests → STOP → Consult GPT-5 and Gemini Pro
- ONLY THEN present results to user for evaluation
cmap is shorthand for "consult multiple agents in parallel in the background."
When the user says "cmap the PR" or "cmap spec 42", this means:
- Run a 3-way parallel review (Gemini, Codex, Claude)
- Run all three in the background (
run_in_background: true) - Return control to the user immediately
- Retrieve results later with
TaskOutputwhen needed
Always run consultations in parallel using separate Bash tool calls in the same message, not sequentially.
IMPORTANT: Never guess CLI commands. Use the /af skill to check the quick reference before running agent farm commands. Common mistakes to avoid:
- There is NO
codev towercommand — useaf tower start/af tower stop - There is NO
restartsubcommand — stop then start - When unsure about syntax, check the docs below first
Codev provides five CLI tools. For complete reference documentation, see:
- Overview - Quick start and summary of all tools
- codev - Project management (init, adopt, doctor, update, tower)
- af - Agent Farm orchestration (start, spawn, status, cleanup, send, etc.)
- porch - Protocol orchestrator (status, run, approve, pending)
- consult - AI consultation (general, protocol, stats)
- team - Team coordination (list, message, update, add)
The Architect-Builder pattern enables parallel AI-assisted development:
- Architect (human + primary AI): Creates specs and plans, reviews work
- Builders (autonomous AI agents): Implement specs in isolated git worktrees
For detailed commands, configuration, and architecture, see:
codev/resources/commands/agent-farm.md- Full CLI referencecodev/resources/arch.md- Terminal architecture, state managementcodev/resources/workflow-reference.md- Stage-by-stage workflow
When a worktree already exists for a project:
- Use
af spawn XXXX --resume - If
--resumefails → ASK THE USER - Only destroy if the user explicitly says to
NEVER run without EXPLICIT user request:
git worktree remove(with or without --force)git branch -Don builder branchesaf cleanupfollowed by fresh spawn
You are NOT qualified to judge what's expendable. It is NEVER your call to delete a worktree.
ALL af commands (af spawn, af send, af status, af workspace, af cleanup) MUST be run from the repository root on the main branch.
- NEVER run
af spawnfrom inside a builder worktree — builders will get nested inside that worktree, breaking everything - NEVER run
af workspace startfrom a worktree — there is no separate workspace per worktree - NEVER
cdinto a worktree to run af commands - The only exception is
porchcommands that need worktree context (e.g.porch approvefrom a builder's worktree)
What happened: On 2026-02-21, af spawn was run from inside a builder's worktree. All new builders were nested inside that worktree, af send couldn't find them, and af status showed "not active in tower". Multiple builders had to be killed and respawned.
Commit all local changes before af spawn. Builders work in git worktrees branched from HEAD — uncommitted specs, plans, and codev updates are invisible to the builder. The spawn command enforces this (override with --force).
af workspace start # Start the workspace
af spawn 42 --protocol spir # Spawn builder for SPIR project
af spawn 42 --protocol spir --soft # Spawn builder (soft mode)
af spawn 42 --protocol bugfix # Spawn builder for a bugfix
af spawn 42 --protocol tick --amends 30 # TICK amendment to spec 30
af status # Check all builders
af cleanup --project 0042 # Clean up after merge
af open file.ts # Open file in annotation viewer (NOT system open)IMPORTANT: When the user says af open, always run the af open command — do NOT substitute the system open command.
Agent Farm is configured via af-config.json at the project root. Created during codev init or codev adopt. Override via CLI: --architect-cmd, --builder-cmd, --shell-cmd.
Porch drives SPIR, TICK, and BUGFIX protocols via a state machine with phase transitions, gates, and multi-agent consultations.
porch init spir 0073 "feature-name" --worktree .builders/0073
porch status 0073
porch run 0073
porch approve 0073 spec-approval # Human only
porch pending # List pending gatesState is stored in codev/projects/<id>-<name>/status.yaml, managed automatically by porch. See codev/resources/protocol-format.md for protocol definition format.
THIS IS A CRITICAL SECURITY REQUIREMENT - NO EXCEPTIONS
git add -A # ABSOLUTELY FORBIDDEN
git add . # ABSOLUTELY FORBIDDEN
git add --all # ABSOLUTELY FORBIDDENMANDATORY APPROACH - ALWAYS ADD FILES EXPLICITLY:
git add codev/specs/42-feature.md
git add src/components/TodoList.tsxBEFORE EVERY COMMIT: Run git status, add each file explicitly by name.
[Spec 42] Initial specification draft
[Spec 42][Phase: user-auth] feat: Add password hashing
[Bugfix #42] Fix: URL-encode username before API call
spir/42-feature-name/phase-name
builder/bugfix-42-description
DO NOT SQUASH MERGE - Always use regular merge commits:
gh pr merge <number> --merge # CORRECTIndividual commits document the development process. Squashing loses this valuable history.
Use tokei for measuring codebase size: tokei -e "tests/lib" -e "node_modules" -e ".git" -e ".builders" -e "dist" .
BEFORE writing ANY code, run these checks:
# Check if there's already a PR for this
gh pr list --search "XXXX"
# Check GitHub Issues for status
gh issue list --search "XXXX"
# Check if implementation already exists
git log --oneline --all | grep -i "feature-name"If existing work exists: READ it first, TEST if it works, IDENTIFY specific bugs, FIX minimally.
If you've been debugging the same issue for 15+ minutes:
- STOP coding immediately
- Consult external models (GPT-5, Gemini) with specific questions
- Ask the user if you're on the right path
- Consider simpler approaches - you're probably overcomplicating it
Warning signs you're in a rathole:
- Making incremental fixes that don't work
- User telling you you're overcomplicating it (LISTEN TO THEM)
- Trying multiple approaches without understanding why none work
- Not understanding the underlying technology
Before implementing, you MUST understand:
- The protocol/API - Read docs, don't guess
- The module system - ESM vs CommonJS vs UMD vs globals
- What already exists - Check the codebase and git history
- The spec's assumptions - Verify they're actually true
- ALWAYS check
codev/protocols/spir/protocol.mdfor detailed phase instructions - Use provided templates from
codev/protocols/spir/templates/ - Document all deviations from the plan with reasoning
- Create atomic commits for each phase completion
- Maintain >90% test coverage where possible
Remember: Context drives code. When in doubt, write more documentation rather than less.