Start here for normal use:
project-brain go "understand this project and suggest the next safe step" /path/to/repoIf --output is omitted, project-brain writes all generated artifacts under /path/to/repo/BRAIN/. That directory contains the generated AI_CONTEXT/, runtime memory/, reports/, tasks/, and generated docs/proposals. Pass --output /path/to/output to place the same layout somewhere else.
Use the guided console when the user should not remember command names:
project-brain console --target /path/to/repoRead these docs for release-candidate operation:
docs/installation.mddocs/first-analysis-5-min.mddocs/output-contract.mddocs/release-checklist.mddocs/user-test-script.md
npm install
npm run buildnpm run hooks:install
npm run lint
npm run typecheck
npm run verifyBefore opening the repo to public contributions, install the local gates:
npm run hooks:installThe repository now provides:
pre-commit: blocks staged secrets, weak local-only paths, and runsnpm run lintcommit-msg: blocks placeholder commit messages likewippre-push: runsnpm run verify:quick- GitHub CI: runs lint, typecheck, build, tests, smoke tests, and repository safety scan
- GitHub dependency review and security baseline workflows
For GitHub-side settings such as branch protection and secret scanning, follow docs/github-hardening.md.
Map an existing repository into structured onboarding docs:
project-brain map-codebase /path/to/repoStart with plain language instead of choosing a command manually:
project-brain start "quiero analizar y mejorar este proyecto" /path/to/repo
project-brain ask "identifica este proyecto" /path/to/repo
project-brain ask "dime que le falta criticamente" /path/to/repo
project-brain ask "revisa los cambios recientes" /path/to/repostart is the simple path for non-technical users. It runs cheap deterministic preflight first: doctor, codebase map, code graph, fact query, runbook, harness audit, and firewall. It does not run the model-heavy swarm unless you pass --with-swarm.
go is the preferred alias for beta users. Use status, resume, runbook, and fact-query before broad swarm analysis.
ask routes the request into the current best workflow and writes reports/ask_brief.md with artifacts and suggested next prompts.
Use new when there is no repository to analyze yet:
project-brain new ./my-new-projectFor non-interactive use:
project-brain new ./my-new-project \
--yes \
--name "Inventory SaaS" \
--problem "Track workshop inventory" \
--audience "small repair shops" \
--type saas-webapp \
--stack "Next.js + PostgreSQL" \
--features "inventory dashboard,order tracking" \
--auth yes \
--roles "owner,technician" \
--data "User,Workshop,InventoryItem,Order" \
--integrations "email,object storage"This writes directly into the new project directory:
AI_CONTEXT/PROJECT_CHARTER.mdAI_CONTEXT/REQUIREMENTS.mdAI_CONTEXT/PROJECT_BLUEPRINT.mdAI_CONTEXT/DECISIONS.mdAI_CONTEXT/MEMORY_BRIEF.mdAI_CONTEXT/RUNBOOK.mddocs/architecture_plan/BLUEPRINT.mddocs/architecture_plan/STATE.mdmemory/project_seed/project_seed.jsontasks/initial_backlog.mdCLAUDE.md
This command is context-only for now. It uses a guided blueprint pattern inspired by The Architect, adapted to Project Brain's persistent AI_CONTEXT layout.
Persist a stateful improvement plan:
project-brain plan-improvements /path/to/repo --trigger repository-change --output /path/to/outputThis writes:
docs/improvement_plan/SUMMARY.mddocs/improvement_plan/STATE.mddocs/improvement_plan/KNOWN_RISKS.mddocs/improvement_plan/ROADMAP.mddocs/improvement_plan/TRACKS.md
Generate a bounded architecture plan before restructuring:
project-brain architecture-plan /path/to/repo --output /path/to/outputThis writes:
docs/architecture_plan/BLUEPRINT.mddocs/architecture_plan/STATE.mddocs/architecture_plan/CLAUDE.mdmemory/architecture_plan/architecture_plan.json
Search the curated local context registry:
project-brain context-search "express observability" /path/to/repo --output /path/to/output
project-brain context-search "vitest testing" /path/to/repo --trust official --output /path/to/output
project-brain context-sources /path/to/repo --output /path/to/outputDiscover ecosystem repos from GitHub and feed them into the same local context registry:
project-brain ecosystem-radar /path/to/repo --output /path/to/output
project-brain ecosystem-radar /path/to/repo --bucket memory --limit 4 --output /path/to/output
project-brain ecosystem-radar /path/to/repo --seed-only --output /path/to/outputMaterialize one entry into reusable project context:
project-brain context-get node-express-api /path/to/repo --output /path/to/outputThis writes:
reports/context_search.mdreports/context_sources.mdreports/ecosystem_radar.mdmemory/context_registry/AI_CONTEXT/EXTERNAL_CONTEXT/<id>.md
If GITHUB_TOKEN is set, ecosystem-radar uses authenticated GitHub API requests. Without it, the command still works against public repositories but hits tighter rate limits.
This produces docs/codebase_map/ with:
SUMMARY.mdSTACK.mdINTEGRATIONS.mdARCHITECTURE.mdSTRUCTURE.mdCONVENTIONS.mdTESTING.mdCONCERNS.md
Persist local repo notes so future runs do not forget them:
project-brain annotate /path/to/repo "The payments area has risky legacy behavior" --output /path/to/output
project-brain annotate /path/to/repo --list --output /path/to/outputAnnotations are written to AI_CONTEXT/ANNOTATIONS.md and also appear in the generated codebase map summary.
Compute impact radius for a targeted set of files:
project-brain impact-radius /path/to/repo --files src/core/service.ts,src/api/router.ts --output /path/to/outputThis writes a persistent symbol-aware graph to memory/code_graph/code_graph_v2.json and an actionable review set to reports/impact_radius.md.
Build or refresh the code graph without running impact analysis:
project-brain code-graph /path/to/repo --output /path/to/outputThis now writes:
memory/code_graph/code_graph_v2.jsonmemory/knowledge_graph/repository_fact_graph.jsonreports/repository_fact_graph.md
The repository fact graph is intentionally factual only. It reuses verified discovery and code-graph relations, and does not add inferred or ambiguous edges.
Query compact factual memory without calling an AI model:
project-brain fact-query "swarm runtime token cache" /path/to/repo --output /path/to/outputThis writes:
reports/fact_query.mdAI_CONTEXT/fact_query/fact_query.json
Use this before giving another AI a broad task. It returns a short deterministic answer plus matching memory lines, graph nodes, graph edges, evidence refs, and unknowns.
Create a token-aware runbook before expensive analysis:
project-brain runbook "optimize analysis and cost" /path/to/repo --output /path/to/outputThis writes:
reports/runbook.mdAI_CONTEXT/runbook/runbook.json
The runbook orders cheap deterministic steps before model-heavy work: doctor, map, code graph, fact query, harness audit, firewall, bounded swarm, planning, resume.
Audit the agent harness before model-heavy analysis:
project-brain harness-audit /path/to/repo --output /path/to/outputThis writes:
reports/harness_audit.mdAI_CONTEXT/harness_audit/harness_audit.json
The harness audit is deterministic and model-free. It checks whether progressive memory exists before broad analysis: compact memory index, factual graph, filtered context query, execution controls, and deep analysis memory. This adapts the useful parts of memory-first and harness-optimization systems without making project-brain Claude-specific.
Review the latest git delta instead of naming files manually:
project-brain review-delta /path/to/repo --base HEAD~1 --head HEAD --output /path/to/outputreview-delta computes:
- changed files from git
- direct and transitive dependents
- related tests
- a minimal review set
Inspect the agent firewall before running a full cycle:
project-brain firewall /path/to/repo --trigger repository-change --output /path/to/outputThis writes:
reports/agent_firewall.mdmemory/firewall/agent_firewall.jsontasks/packets/*.md
project-brain analyze /path/to/repoWrite generated output outside the target repository:
project-brain analyze /path/to/repo --output /path/to/outputUse a longer Ollama timeout for local AI analysis:
project-brain analyze /path/to/repo --ollama-timeout 240000project-brain models now shows both Ollama residency and task profiles.
Default runtime split:
worker:qwen2.5-coder:7breviewer:deepseek-coder:6.7breasoning:llama3.1:8bplanner:kimi-k2.5:cloudsynthesizer:llama3.1:8b
Use that split to keep discovery, review, and day-to-day analysis cheap and local while reserving the planner for strategic or ambiguous asks.
Use bounded swarm only after deterministic memory and facts have been checked.
project-brain swarm "review risky areas without modifying files" /path/to/repo --output /path/to/output --preset cheap
project-brain swarm "review architecture risks" /path/to/repo --output /path/to/output --preset balanced
project-brain swarm "deep review of critical modules" /path/to/repo --output /path/to/output --preset thoroughcheap: fastest and most economical, smaller queue and lower timeout budget.balanced: recommended default for meaningful coverage.thorough: slower and more expensive, use only when cost/time is justified.
Version source docs, templates, contracts, and schemas.
Release and validation reports under reports/validation-*.md, reports/validation-results.json, reports/beta-readiness.md, and reports/release-candidate-*.md are deliberate versioned evidence. Ad hoc runtime reports such as reports/doctor.md remain ignored.
Do not version generated local runtime outputs:
.claude/.project-brain/runtime/AI_CONTEXT/doctor/reports/doctor.md
Use --output outside the target repository when validating real projects.
Frontend usability cycle:
project-brain analyze \
/path/to/frontend-repo \
--output /path/to/output \
--trigger repository-change \
--ollama-timeout 240000 \
--verboseWorkspace-wide analysis:
project-brain analyze \
/path/to/workspace \
--output /path/to/output \
--trigger repository-changeThe templates in prompts/context_templates/ are intended for external repositories. Use them when a coding agent needs high-quality context before proposing frontend, UX, architecture, or performance changes.
Recommended templates:
context_bootstrap_master.md: create or refreshAI_CONTEXT/from the real repository statefrontend_analysis.md: analyze operational frontend surfacesux_improvement.md: produce UX-focused improvement tasksarchitecture_review.md: review module boundaries and structural riskperformance_review.md: find low-risk performance wins
Recommended process:
- Run
project-brain map-codebaseagainst the target repository. - Run
project-brain analyzefor specialist-agent reports and proposals. - Run
project-brain review-deltawhen you need a bounded review surface for a recent change. - Collect the generated
AI_CONTEXT, codebase map, reports, and task artifacts. - Combine those artifacts with one of the prompt templates.
- Use the resulting context in the downstream coding agent.
project-brain init /path/to/repo
project-brain map-codebase /path/to/repo
project-brain annotate /path/to/repo "Known legacy hotspot" --output /path/to/output
project-brain code-graph /path/to/repo
project-brain impact-radius /path/to/repo --files src/core/service.ts
project-brain review-delta /path/to/repo
project-brain start "quiero analizar y mejorar este proyecto" /path/to/repo
project-brain ask "identifica este proyecto" /path/to/repo
project-brain ask "ayudame a definir el stack y el alcance" /path/to/repo
project-brain swarm "ayudame a mejorar este repo" /path/to/repo --preset cheap
project-brain swarm "ayudame a mejorar este repo" /path/to/repo --preset balanced
project-brain swarm "ayudame a mejorar este repo" /path/to/repo --preset thorough
project-brain swarm "ayudame a mejorar este repo" /path/to/repo --parallel 3
project-brain swarm "ayudame a mejorar este repo" /path/to/repo --parallel 3 --chunk-size 1
project-brain swarm "ayudame a mejorar este repo" /path/to/repo --parallel 3 --chunk-size 1 --task-timeout-ms 12000 --max-retries 1
project-brain swarm "ayudame a mejorar este repo" /path/to/repo --parallel 2 --chunk-size 1 --planner-timeout-ms 8000 --synthesis-timeout-ms 8000 --run-timeout-ms 30000 --max-queued-tasks 8
project-brain self-improve /path/to/repo
project-brain plan-improvements /path/to/repo --trigger repository-change
project-brain architecture-plan /path/to/repo --output /path/to/output
project-brain context-search "express observability" /path/to/repo
project-brain context-get node-express-api /path/to/repo
project-brain context-sources /path/to/repo
project-brain firewall /path/to/repo --trigger repository-change
project-brain doctor /path/to/repo
project-brain status /path/to/repo --output /path/to/output
project-brain agents /path/to/repo
project-brain weekly /path/to/repo
project-brain report /path/to/output
project-brain modelsproject-brain analyzes and proposes. It does not modify target code automatically. Generated patch proposals remain review-only, weakly corroborated proposals are downgraded to human review by the consensus gate, and the agent firewall classifies each task before execution into a bounded policy pack.
project-brain doctor is the environment and runtime health check inspired by orchestration-first tools like Agent Orchestrator.
It validates:
- Node runtime compatibility
gitavailability and target repo statusollamaavailability- model inventory and configured profiles
- local swarm readiness
config/models.json- built CLI artifact presence
- output-path writability
Artifacts land in reports/doctor.md and AI_CONTEXT/doctor/doctor.json.
Doctor reports now include suggested follow-up commands, prioritized from high to low.
project-brain status is the operational snapshot view inspired by the “single command status” idea from Agent Orchestrator, but adapted to artifact-based analysis instead of live agent sessions.
It summarizes:
- git repo and branch
- latest doctor state
- presence of swarm/improvement-plan/codebase-map/firewall/impact/ask artifacts
- artifact timestamps in the current output path
Artifacts land in reports/status.md and AI_CONTEXT/status/status.json.
Status reports also include suggested follow-up commands derived from the current artifact state.
project-brain resume is the state-recovery view for the control tower.
It reads the current output path, finds the latest useful artifact, identifies the stage where the project last stopped, and suggests the next command to continue from there.
Typical resume stages:
doctormap-codebaseaskswarmplan-improvementsreview-deltafirewall
Artifacts land in reports/resume.md and AI_CONTEXT/resume/resume.json.
project-brain ask now routes continuation prompts like continua con el proyecto or retoma donde nos quedamos into this recovery flow automatically.
If the next move is clear and bounded, ask will also execute one guided continuation step automatically instead of only suggesting it.
project-brain swarm is the first bounded delegation layer:
planner: splits the user intent into small tasksworker: scans scope and implementation detailsreviewer: stresses risks and weak spotsreasoning: turns findings into decisions and next stepssynthesizer: merges the delegated outputs into one report
Artifacts land in reports/swarm_run.md and AI_CONTEXT/swarm/swarm_run.json.
Use --preset cheap, --preset balanced, or --preset thorough before tuning low-level runtime flags manually.
If you do not pass --parallel, project-brain picks a bounded worker count from local CPU, load average, and free memory.
If you do not pass --chunk-size, project-brain picks a repo-slice size from repository size and then enqueues smaller scope chunks so local workers inspect only a few top-level areas at a time.
The worker queue is round-robin, so a short queue budget samples multiple parent tasks before going deeper into any single one.
If a worker exceeds --task-timeout-ms, the swarm retries or splits the scope chunk into smaller ones before giving up, capped by --max-retries.
Use --planner-timeout-ms, --synthesis-timeout-ms, and --run-timeout-ms to keep the whole run bounded, and --max-queued-tasks to stop the queue from growing beyond a fixed budget. When you do not pass --max-queued-tasks, project-brain derives queue pressure from CPU load and free memory. When those budgets are short enough, project-brain will also keep planner and synthesis on local Ollama models instead of reaching for a remote planner, and it will clamp auto-selected concurrency so the local run stays bounded.
If a single large scope like agents/ or core/ times out, the swarm now splits it into immediate child scopes such as agents/security_agent or core/orchestrator before retrying.
If the user intent names a path like core/swarm_runtime, the swarm now treats that as a scope hint and pulls the matching project area to the front of the queue.
If a local model returns labeled Markdown or plain text instead of strict JSON, the swarm now recovers summary, findings, recommendations, priorities, and next_steps before degrading to an empty result.
project-brain self-improve is a thin wrapper around the swarm with defaults tuned for local repo self-analysis:
chunk-size=1task-timeout-ms=12000planner-timeout-ms=8000synthesis-timeout-ms=8000run-timeout-ms=45000max-retries=1
parallelism and queue budget are left adaptive on purpose, so self-improve can shrink itself automatically when the machine is already under pressure. It also uses a source-first scope bias so the first queued chunks prefer product code areas over tests/ and top-level config files.
Use it when you want project-brain to inspect a repository, including itself, without hand-tuning the swarm flags first.
Use go as the main entry point when you do not want to remember individual
commands:
project-brain go "understand this project and recommend the next step" /path/to/repo --output /path/to/outputUse these deterministic commands before model-heavy work:
project-brain status /path/to/repo --output /path/to/output
project-brain runbook "what should I do next?" /path/to/repo --output /path/to/output
project-brain fact-query "known fact or module name" /path/to/repo --output /path/to/outputUse swarm presets only when memory/fact checks are insufficient:
project-brain swarm --preset cheap "inspect this module" /path/to/repo --output /path/to/output
project-brain swarm --preset balanced "review critical risks" /path/to/repo --output /path/to/output
project-brain swarm --preset thorough "deep review" /path/to/repo --output /path/to/outputPreset meanings:
cheap: fast/economic, fewer tasks.balanced: recommended default for better coverage.thorough: slower/costlier, maximum coverage.
The current memory stack is:
AI_CONTEXT/MEMORY_BRIEF.md: compact agent/human handoff.AI_CONTEXT/EXECUTIVE_SUMMARY.md: project status, risks, scopes, and next actions.memory/scopes/*.json: per-scope facts, coverage, freshness, and evidence.memory/knowledge_graph/repository_fact_graph.json: structural repository facts.preflightFacts: read-only factual preflight before ask/model flows.
Fresh and complete scope memory may reduce queued swarm work. Stale scope memory is reported as stale and is not used as current factual evidence.
Project Brain versions source documentation, templates, contracts, and curated
AI_CONTEXT/*.md memory files. Runtime diagnostics and local agent state are
generated per machine/session and are ignored by git.
Versioned examples:
AI_CONTEXT/*.mdcurated project memoryreports/templates/*.mdreport templatesdocs/**source documentation
Ignored runtime examples:
.claude/AI_CONTEXT/doctor/reports/doctor.md.project-brain/runtime/
Generated doctor output can include absolute local paths, local model inventory,
runtime versions, and branch-specific diagnostics. Use
reports/templates/doctor.md as the stable source contract instead of tracking
the generated report.