This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MagesticAI is a web-based AI task management and agent orchestration platform that builds software through coordinated AI agent sessions. It uses the Claude Agent SDK to run agents in isolated workspaces with security controls.
Project: MagesticAI Repository: https://github.com/dataseeek/MagesticAI Author: DataSeek Team License: AGPL-3.0
CRITICAL: All AI interactions use the Claude Agent SDK (claude-agent-sdk package), NOT the Anthropic API directly.
MagesticAI/
├── apps/
│ ├── backend/ # Python backend/CLI - ALL agent logic lives here
│ │ ├── core/ # Client, auth, security
│ │ ├── agents/ # Agent implementations
│ │ ├── spec_agents/ # Spec creation agents
│ │ ├── integrations/ # Graphiti, Linear, GitHub
│ │ └── prompts/ # Agent system prompts
│ ├── web-server/ # FastAPI backend for web UI (REST/WebSocket)
│ └── frontend-web/ # React web frontend (browser-based)
├── guides/ # Documentation
├── tests/ # Test suite
└── scripts/ # Build and utility scripts
When working with AI/LLM code:
- Look in
apps/backend/core/client.pyfor the Claude SDK client setup - Reference
apps/backend/agents/for working agent implementations - Check
apps/backend/spec_agents/for spec creation agent examples - NEVER use
anthropic.Anthropic()directly - always usecreate_client()fromcore.client
Frontend (Web):
- Built with React 19, TypeScript, Vite
- Browser-based UI accessible from any device
- Real-time updates via WebSocket
Requirements:
- Python 3.12+ (required for backend)
- Node.js (for frontend)
# Install all dependencies from root
npm run install:all
# Or install separately:
# Backend (from apps/backend/)
cd apps/backend && uv venv && uv pip install -r requirements.txt
# Frontend (from apps/frontend/)
cd apps/frontend && npm install
# Set up OAuth token
claude setup-token
# Add to apps/backend/.env: CLAUDE_CODE_OAUTH_TOKEN=your-tokencd apps/backend
# Create a spec interactively
python spec_runner.py --interactive
# Create spec from task description
python spec_runner.py --task "Add user authentication"
# Force complexity level (simple/standard/complex)
python spec_runner.py --task "Fix button" --complexity simple
# Run autonomous build
python run.py --spec 001
# List all specs
python run.py --listcd apps/backend
# Review changes in isolated worktree
python run.py --spec 001 --review
# Merge completed build into project
python run.py --spec 001 --merge
# Discard build
python run.py --spec 001 --discardcd apps/backend
# Run QA manually
python run.py --spec 001 --qa
# Check QA status
python run.py --spec 001 --qa-status# Install test dependencies (required first time)
cd apps/backend && uv pip install -r ../../tests/requirements-test.txt
# Run all tests (use virtual environment pytest)
apps/backend/.venv/bin/pytest tests/ -v
# Run single test file
apps/backend/.venv/bin/pytest tests/test_security.py -v
# Run specific test
apps/backend/.venv/bin/pytest tests/test_security.py::test_bash_command_validation -v
# Skip slow tests
apps/backend/.venv/bin/pytest tests/ -m "not slow"
# Or from root
npm run test:backendpython apps/backend/validate_spec.py --spec-dir apps/backend/specs/001-feature --checkpoint all# 1. Bump version on your branch (creates commit, no tag)
node scripts/bump-version.js patch # 2.8.0 -> 2.8.1
node scripts/bump-version.js minor # 2.8.0 -> 2.9.0
node scripts/bump-version.js major # 2.8.0 -> 3.0.0
# 2. Push and create PR to main
git push origin your-branch
gh pr create --base main
# 3. Merge PR → GitHub Actions automatically:
# - Creates tag
# - Builds all platforms
# - Creates release with changelog
# - Updates READMESee RELEASE.md for detailed release process documentation.
Spec Creation (spec_runner.py) - Dynamic 3-8 phase pipeline based on task complexity:
- SIMPLE (3 phases): Discovery → Quick Spec → Validate
- STANDARD (6-7 phases): Discovery → Requirements → [Research] → Context → Spec → Plan → Validate
- COMPLEX (8 phases): Full pipeline with Research and Self-Critique phases
Implementation (run.py → agent.py) - Multi-session build:
- Planner Agent creates subtask-based implementation plan
- Coder Agent implements subtasks (can spawn subagents for parallel work)
- QA Reviewer validates acceptance criteria
- QA Fixer resolves issues in a loop
Core Infrastructure:
- core/client.py - Claude Agent SDK client factory with security hooks and tool permissions
- core/security.py - Dynamic command allowlisting based on detected project stack
- core/auth.py - OAuth token management for Claude SDK authentication
- agents/ - Agent implementations (planner, coder, qa_reviewer, qa_fixer)
- spec_agents/ - Spec creation agents (gatherer, researcher, writer, critic)
Memory & Context:
- integrations/graphiti/ - Graphiti memory system (mandatory)
queries_pkg/graphiti.py- Main GraphitiMemory classqueries_pkg/client.py- LadybugDB client wrapperqueries_pkg/queries.py- Graph query operationsqueries_pkg/search.py- Semantic search logicqueries_pkg/schema.py- Graph schema definitions
- graphiti_config.py - Configuration and validation for Graphiti integration
- graphiti_providers.py - Multi-provider factory (OpenAI, Anthropic, Azure, Ollama, Google AI)
- agents/memory_manager.py - Session memory orchestration
Workspace & Security:
- cli/worktree.py - Git worktree isolation for safe feature development
- context/project_analyzer.py - Project stack detection for dynamic tooling
- magestic_ai_tools.py - Custom MCP tools integration
BMad Method Integration:
- integrations/bmad/ - BMad Method scale-adaptive intelligence
complexity_detector.py- 5-level complexity detection (0-4)track_config.py- Three-track planning (Quick Flow, Standard, Enterprise)session_config.py- Session segmentation configurationcontext_shard.py- Context sharding for token optimizationsession_spawner.py- Per-story session orchestrationpersonas/- BMad-style agent personas (Sarah, Winston, Alex, Jordan)subagents/- Specialized analysis sub-agentsrequirements_analyst.py- Requirements validationcodebase_analyzer.py- Codebase explorationtechnical_evaluator.py- Technical decision evaluation
Integrations:
- linear_updater.py - Optional Linear integration for progress tracking
- runners/github/ - GitHub Issues & PRs automation
| Prompt | Purpose |
|---|---|
| planner.md | Creates implementation plan with subtasks |
| coder.md | Implements individual subtasks |
| coder_recovery.md | Recovers from stuck/failed subtasks |
| qa_reviewer.md | Validates acceptance criteria |
| qa_fixer.md | Fixes QA-reported issues |
| spec_gatherer.md | Collects user requirements |
| spec_researcher.md | Validates external integrations |
| spec_writer.md | Creates spec.md document |
| spec_critic.md | Self-critique using ultrathink |
| complexity_assessor.md | AI-based complexity assessment |
Each spec in .magestic-ai/specs/XXX-name/ contains:
spec.md- Feature specificationrequirements.json- Structured user requirementscontext.json- Discovered codebase contextimplementation_plan.json- Subtask-based plan with status trackingqa_report.md- QA validation resultsQA_FIX_REQUEST.md- Issues to fix (when rejected)
MagesticAI uses git worktrees for isolated builds. All branches stay LOCAL until user explicitly pushes:
main (user's branch)
└── magestic-ai/{spec-name} ← spec branch (isolated worktree)
Key principles:
- ONE branch per spec (
magestic-ai/{spec-name}) - Parallel work uses subagents (agent decides when to spawn)
- NO automatic pushes to GitHub - user controls when to push
- User reviews in spec worktree (
.worktrees/{spec-name}/) - Final merge: spec branch → main (after user approval)
Workflow:
- Build runs in isolated worktree on spec branch
- Agent implements subtasks (can spawn subagents for parallel work)
- User tests feature in
.worktrees/{spec-name}/ - User runs
--mergeto add to their project - User pushes to remote when ready
Workflow for contributions:
- Create feature branch from develop:
git checkout -b fix/my-fix develop - Make changes and commit with sign-off:
git commit -s -m "fix: description" - Push to your branch:
git push origin fix/my-fix - Create PR targeting
develop:gh pr create --base develop
Verify before PR:
# Ensure only your commits are included
git log --oneline origin/develop..HEADThree-layer defense:
- OS Sandbox - Bash command isolation
- Filesystem Permissions - Operations restricted to project directory
- Command Allowlist - Dynamic allowlist from project analysis (security.py + project_analyzer.py)
Security profile cached in .magestic-ai-security.json.
CRITICAL: MagesticAI uses the Claude Agent SDK for ALL AI interactions. Never use the Anthropic API directly.
Client Location: apps/backend/core/client.py
The create_client() function creates a configured ClaudeSDKClient instance with:
- Multi-layered security (sandbox, permissions, security hooks)
- Agent-specific tool permissions (planner, coder, qa_reviewer, qa_fixer)
- Dynamic MCP server integration based on project capabilities
- Extended thinking token budget control
Example usage in agents:
from core.client import create_client
# Create SDK client (NOT raw Anthropic API client)
client = create_client(
project_dir=project_dir,
spec_dir=spec_dir,
model="claude-sonnet-4-5-20250929",
agent_type="coder",
max_thinking_tokens=None # or 5000/10000/16000
)
# Run agent session
response = client.create_agent_session(
name="coder-agent-session",
starting_message="Implement the authentication feature"
)Why use the SDK:
- Pre-configured security (sandbox, allowlists, hooks)
- Automatic MCP server integration (Context7, Linear, Graphiti, Puppeteer)
- Tool permissions based on agent role
- Session management and recovery
- Unified API across all agent types
Where to find working examples:
apps/backend/agents/planner.py- Planner agentapps/backend/agents/coder.py- Coder agentapps/backend/agents/qa_reviewer.py- QA reviewerapps/backend/agents/qa_fixer.py- QA fixerapps/backend/spec_agents/- Spec creation agents
Graphiti Memory (Mandatory) - integrations/graphiti/
MagesticAI uses Graphiti as its primary memory system with embedded LadybugDB (no Docker required):
- Graph database with semantic search - Knowledge graph for cross-session context
- Session insights - Patterns, gotchas, discoveries automatically extracted
- Multi-provider support:
- LLM: OpenAI, Anthropic, Azure OpenAI, Ollama, Google AI (Gemini)
- Embedders: OpenAI, Voyage AI, Azure OpenAI, Ollama, Google AI
- Modular architecture: (
integrations/graphiti/queries_pkg/)graphiti.py- Main GraphitiMemory classclient.py- LadybugDB client wrapperqueries.py- Graph query operationssearch.py- Semantic search logicschema.py- Graph schema definitions
Configuration:
- Set provider credentials in
apps/backend/.env(see.env.example) - Required env vars:
GRAPHITI_ENABLED=true,ANTHROPIC_API_KEYor other provider keys - Memory data stored in
.magestic-ai/specs/XXX/graphiti/
Usage in agents:
from integrations.graphiti.memory import get_graphiti_memory
memory = get_graphiti_memory(spec_dir, project_dir)
context = memory.get_context_for_session("Implementing feature X")
memory.add_session_insight("Pattern: use React hooks for state")Status: ✅ Complete (Branch: bmad-method, awaiting PR to develop)
MagesticAI integrates BMad Method's scale-adaptive intelligence, specialized agents, and architecture-first workflows. All 6 milestones implemented.
-
5-Level Complexity Detection (
integrations/bmad/complexity_detector.py)- Level 0: Trivial (single atomic change, 1 story)
- Level 1: Simple (small feature, 1-10 stories)
- Level 2: Standard (medium project, 5-15 stories)
- Level 3: Complex (complex system, 12-40 stories, architecture required)
- Level 4: Enterprise (40+ stories, full planning)
- Detection: > 80% accuracy using keyword + story count estimation
-
Three-Track Planning (
integrations/bmad/track_config.py)- Quick Flow (3 phases): Discovery → Tech Spec → Validate
- Standard (6-7 phases): Adds Requirements, Context, Spec, Plan (+ Architecture for Level 3+)
- Enterprise (9 phases): Adds Security, DevOps phases
-
Architecture-First Planning (
agents/architect.py)- Architecture phase between requirements and implementation (Level 3+)
- Database schema design (ERD)
- API endpoint specifications (OpenAPI)
- Technical decision records (ADRs)
- Mermaid diagram generation (ERD, C4, sequence)
-
Story-Based Planning (
agents/planner.py)- User stories with acceptance criteria (not generic subtasks)
- Technical context (architecture references, stack, dependencies)
- Story points and priority
- Backward compatible with old subtask format
-
Agent Personas (
integrations/bmad/personas/)- Sarah (Planner): Staff PM, ruthlessly prioritizes
- Winston (Architect): Principal Architect, security-conscious
- Alex (Coder): Senior Developer, ultra-succinct
- Jordan (QA): Lead QA Engineer, detail-oriented
-
Session Segmentation (
integrations/bmad/session_*.py)- Per-story sessions with minimal context
- Context sharding (loads only relevant architecture sections)
- 98.9% token reduction (50,000 chars → 529 chars avg)
- Opt-in via settings UI or
BMAD_SESSION_SEGMENTATIONenv var
-
Sub-Agents Framework (
integrations/bmad/subagents/)- RequirementsAnalyst: Validates requirements (80% completeness, 100% clarity)
- CodebaseAnalyzer: Explores structure, detects tech stack, finds relevant files
- TechnicalEvaluator: Assesses risks, evaluates decisions, recommends best practices
Enable Session Segmentation:
# Option 1: Environment variable
export BMAD_SESSION_SEGMENTATION=true
# Option 2: Frontend UI toggle
# Settings > Agent Settings > BMad Session SegmentationUsing Sub-Agents:
from integrations.bmad.subagents.examples import SubAgentInvoker
invoker = SubAgentInvoker(project_dir, spec_dir)
# Before planning
req_analysis = invoker.analyze_requirements(requirements_text)
# Before implementation
code_analysis = invoker.find_relevant_files(task_description)
# For architecture decisions
eval_result = invoker.evaluate_decision(decision_text)Documentation:
- Implementation Summary:
_bmad/IMPLEMENTATION_SUMMARY.md - Sub-Agents Guide:
apps/backend/integrations/bmad/subagents/README.md - Planning Documents:
_bmad/plan.md,prd.md,architecture.md,epics.md
Testing:
# Test sub-agents
cd apps/backend
python3 -m integrations.bmad.subagents.test_subagents
# Run examples
python3 -m integrations.bmad.subagents.examplesCRITICAL: Always use i18n translation keys for all user-facing text in the frontend.
The frontend uses react-i18next for internationalization. All labels, buttons, messages, and user-facing text MUST use translation keys.
Translation file locations:
apps/frontend/src/shared/i18n/locales/en/*.json- English translationsapps/frontend/src/shared/i18n/locales/fr/*.json- French translations
Translation namespaces:
common.json- Shared labels, buttons, common termsnavigation.json- Sidebar navigation items, sectionssettings.json- Settings page contentdialogs.json- Dialog boxes and modalstasks.json- Task/spec related contentonboarding.json- Onboarding wizard contentwelcome.json- Welcome screen content
Usage pattern:
import { useTranslation } from 'react-i18next';
// In component
const { t } = useTranslation(['navigation', 'common']);
// Use translation keys, NOT hardcoded strings
<span>{t('navigation:items.githubPRs')}</span> // ✅ CORRECT
<span>GitHub PRs</span> // ❌ WRONGWhen adding new UI text:
- Add the translation key to ALL language files (at minimum:
en/*.jsonandfr/*.json) - Use
namespace:section.keyformat (e.g.,navigation:items.githubPRs) - Never use hardcoded strings in JSX/TSX files
IMPORTANT: NEVER create debugging or analysis files in the project root directory.
For temporary debugging files, analysis documents, or troubleshooting guides:
- Use the system temp directory:
/tmp/ - Or use the Claude Code scratchpad directory for your session
- These files should NOT be committed to the repository
Examples of files to keep out of project root:
TASK_*.md- Task debugging analysis documentsINIT_*.md- Initialization troubleshooting guidesDEBUG_*.md- Debug session notesANALYSIS_*.md- Code analysis documents- Any other temporary troubleshooting documentation
Where to put debugging documentation:
# Option 1: System temp directory
/tmp/task-001-debug-analysis.md
# Option 2: Claude Code scratchpad (session-specific)
# Use the scratchpad directory provided in your session context
# Option 3: If it's permanent documentation, put it in guides/
guides/troubleshooting/specific-issue.mdException: Only add permanent troubleshooting documentation to guides/ directory if it's meant to be version-controlled and shared with all developers.
MagesticAI is a browser-based web interface. This enables:
- Remote access from any device with a browser
- Server-based deployments
- Headless operation with web UI control
apps/
├── web-server/ # FastAPI backend (Python) - REST API + WebSocket
└── frontend-web/ # React frontend (TypeScript/Vite) - Browser UI
# Terminal 1: Start the backend server
cd apps/web-server
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python -m server.main
# Note: Token is printed to console and saved to ~/.magestic-ai/.token
# Terminal 2: Start the frontend dev server
cd apps/frontend-web
npm install
npm run devAccess the web UI at http://localhost:3100 (or your server IP for remote access).
Backend (apps/web-server/.env):
APP_HOST=0.0.0.0 # Listen on all interfaces
APP_PORT=3101 # API server port
APP_DEBUG=true # Enable Swagger docs at /docs
# APP_API_TOKEN=xxx # Optional: Set fixed token (auto-generated if not set)Frontend (apps/frontend-web/.env):
VITE_API_BASE_URL=/api # API base (proxied to backend)
VITE_WS_BASE_URL=ws://your-server:3101 # WebSocket URL for remote deployments
VITE_API_URL=http://localhost:3101 # Backend URL for Vite proxyFor remote deployments:
- Ensure ports 3101 (backend) and 3100 (frontend dev) are accessible
- Set
VITE_WS_BASE_URLto your server's WebSocket URL - Access via
http://YOUR_SERVER_IP:3100
For production, build the frontend (npm run build) and serve from apps/web-server/static/.
When APP_DEBUG=true:
- Swagger UI:
http://localhost:3101/docs - ReDoc:
http://localhost:3101/redoc
See apps/web-server/README.md and apps/frontend-web/README.md for detailed documentation.
| Issue | Solution |
|---|---|
| "Claude Code not installed" | Hard refresh browser (Ctrl+Shift+R) |
| UI blocked/frozen | Check browser console for errors, restart servers |
| Can't add projects | Use project discovery dropdown or enter custom path |
| API errors | Verify token in ~/.magestic-ai/.token |
| Git Repository Required keeps appearing | Click "Skip for now" or initialize git; state persists in localStorage |
| Usage shows NaN | Backend reads stats from ~/.claude/stats-cache.json |
| New Task button not working | Ensure TaskCreationWizard is imported in App.tsx |
| Terminal 500 error | Check PTYManager creates sessions with UUID (don't pass id=None) |
| File editor 404/TypeError | Backend file routes return raw data, frontend extracts .entries or .content |
| Themes not changing | Ensure CSS theme variables exist in index.css with @theme block |
| Folder tree not expanding | FileTree needs onLoadChildren prop for lazy loading subdirectories |
| Task creation fails | Add POST endpoint at /api/projects/{id}/tasks in projects.py |
| Task start 404 | Mount execution.router at /api/tasks prefix (not /api/execution) in main.py |
| Task start 422 | Frontend must send {} body even when options are undefined (Pydantic needs JSON body for defaults) |
| Terminal resize 422 | Backend endpoint must use Pydantic model for { cols, rows } body, not query params |
| Task stuck with "Stream closed" | Ensure permission_mode="bypassPermissions" is set in all ClaudeAgentOptions AND magestic-ai MCP tools are in permissions allow list (see APP_TOOLS in models.py) |
| Frontend shows task "stuck" but agent is working | File sync issue - worktree files not syncing to main spec dir. Fixed in agent_service.py with periodic sync every 3 seconds |
| Roadmap/Changelog 500 error | FastAPI Path shadowing pathlib.Path - use from pathlib import Path as FilePath at top of route files |
| Roadmap progress stuck at 0% | Roadmap generation was not implemented - see roadmap_service.py for the service pattern |
| Task options not applied (model/thinking) | Frontend saves to requirements.json["metadata"] but phase_config.py reads task_metadata.json. Fixed: projects.py now writes task_metadata.json on task creation |
| "Failed to parse insights JSON" in logs | Empty SDK response in insight_extractor.py. Fixed with empty response validation and brace-matching fallback |
API Response Wrapping:
- Frontend
api-client.tswraps all responses in{ success: true, data: <response> } - Backend endpoints should return raw data objects, NOT wrapped in
{success, data} - Exception: Error responses should return
{ success: false, error: "message" }
React useEffect Dependencies:
- Avoid using object references (like
selectedProject) as dependencies - they change on every render - Use primitive values (like
selectedProjectId) instead - Use refs (
useRef) to access state in effects without triggering re-runs
localStorage for Persistent UI State:
- Use localStorage for UI state that should survive page refresh (e.g., skipped dialogs)
- Initialize state with lazy initializer:
useState(() => loadFromStorage()) - Update localStorage in state setter callback
File Routes:
/api/files/list?path=...- List directory by absolute path (returns{path, entries, parent})/api/files/read?path=...- Read file by absolute path (returns{path, content, size, modified, language})/api/files/discover?base_path=...- Discover projects in directory
Theme System (Tailwind v4):
- CSS theme variables defined in
apps/frontend-web/src/index.css - Light mode:
:root { --background: ...; --foreground: ...; } - Dark mode:
.dark { --background: ...; } - Color themes:
[data-theme="ocean"],[data-theme="forest"], etc. - Tailwind v4 uses
@theme { --color-background: hsl(var(--background)); }to map CSS vars - App.tsx applies themes via
document.documentElement.classList.add('dark')andsetAttribute('data-theme', theme)
Lazy Loading File Trees:
- FileTree component should accept
onLoadChildren: (path: string) => Promise<FileNode[]> - Load children on folder expand, not upfront
- Cache loaded children in component state to avoid refetching
Worktree File Synchronization:
- Agent writes files to worktree:
.magestic-ai/worktrees/tasks/{spec-id}/.magestic-ai/specs/{spec-id}/ - Frontend reads from main spec:
.magestic-ai/specs/{spec-id}/ agent_service.pysyncs files every 3 seconds during task execution (_sync_worktree_files()method)- Synced files:
implementation_plan.json,build-progress.txt,context.json,qa_report.md,spec.md,requirements.json - Final sync occurs when task completes
- Location:
apps/web-server/server/services/agent_service.py:207-303
Running Backend Scripts from Web Server:
- Use service pattern (see
roadmap_service.pyas example) - Set
PYTHONPATHto include backend directory for imports to work - Set
cwdto backend directory when running scripts - Use
sys.executable(web server's Python) which shares dependencies - Parse stdout for phase patterns to emit WebSocket progress events
- Example phases:
PHASE 1:,PHASE 2:, etc. detected via regex
Keyboard Shortcuts:
- New terminal:
Ctrl+Shift+E(all platforms) - notCtrl+Twhich conflicts with browser - Close terminal:
Ctrl+W/Cmd+W
Paste and Text Handling (Fixed 2026-01-16):
- Issue: Copy-pasting text with images was losing the text content
- Root cause: Paste handlers were calling
e.preventDefault()to process images, blocking browser's natural text paste - Fix: Removed
e.preventDefault()- let browser handle text naturally while processing images in parallel - Files:
TaskCreationWizard.tsx,TaskEditDialog.tsx- both paste handlers updated - Result: Text-only, image-only, and mixed content pastes all work correctly
Task Description Truncation (Fixed 2026-01-16):
- Issue: Multi-paragraph task descriptions truncated to 500 characters in UI
- Root cause: Backend
load_spec_metadata()was loading fromspec.mdwith[:500]limit - Fix: Load description from
requirements.jsonfirst (complete user input), removed character limit - File:
apps/web-server/server/routes/tasks.py:216-243 - Result: Full task descriptions load correctly in all views (list, detail, edit)
As a standalone CLI tool:
cd apps/backend
python run.py --spec 001With the Web interface:
# Start backend (port 3101)
cd apps/web-server && source .venv/bin/activate && python -m server.main
# Start frontend (port 3100)
cd apps/frontend-web && npm run devProject data storage:
.magestic-ai/specs/- Per-project data (specs, plans, QA reports, memory) - gitignored~/.magestic-ai/- Web interface data (projects, settings, token) - for web UI only