Tech Stack
| Component | Technology | Role |
|---|---|---|
| Language | Swift | Application logic, concurrency with actors |
| UI Framework | SwiftUI + @Observable | Reactive interface, state management via AppState |
| Terminal | SwiftTerm | Terminal emulation for each agent’s Claude Code session |
| Layout | NSSplitViewController | Three-panel split view (sidebar, canvas, detail) |
| File Watching | DispatchSource | Event-driven monitoring of agent files — no polling |
| Process Management | Foundation.Process | Spawning Claude Code processes via PTY |
| Auto-Updates | Sparkle | Background update checks and installation |
Process Management
Each agent runs as an independent Claude Code process:- Spawn —
Foundation.Processlaunchesclaudewith the agent’s working directory, model, and permission flags. - PTY bridge — A pseudo-terminal connects the process to a SwiftTerm terminal view, providing full terminal emulation (colors, cursor movement, scrollback).
- Display — The SwiftTerm view renders inside the Detail Panel when an agent desk is selected.
Event-Driven File Watching
Pentagon usesDispatchSource.makeFileSystemObjectSource to monitor agent directories for changes. There is no polling.
When a file changes in ~/.pentagon/agents/{id}/, the corresponding DispatchSource fires a callback. Pentagon watches these files per agent:
| File | Triggers |
|---|---|
status.json | StatusEngine state transition — updates desk ring color and animation |
report.json | Updates the agent’s self-reported summary in the Detail Panel |
TASKS.md | TaskEngine parses checkboxes and updates progress indicators |
MEMORY.md | Refreshes the Memory tab in the Detail Panel |
SOUL.md | Refreshes the Soul tab in the Detail Panel |
heartbeat-config.json | HeartbeatScheduler picks up new restart configuration |
Hook Injection
Pentagon injects hooks into Claude Code so that agent activity is reported back to the app. This is the primary mechanism for status tracking.How It Works
-
HookInjector generates five shell scripts in
~/.pentagon/hooks/:session-start.shagent-stop.shtool-activity.shpost-tool.shsession-end.sh
-
Each script writes a
status.jsonfile atomically (write to temp file, thenmv) to the agent’s directory at~/.pentagon/agents/{id}/status.json. -
HookInjector creates a
.claude/settings.local.jsonfile in the agent’s working directory that registers these scripts as Claude Code hooks. -
Pentagon’s
DispatchSourcewatcher detects thestatus.jsonchange and feeds the event into the StatusEngine.
Hook Events
| Hook Event | Script | Signal |
|---|---|---|
SessionStart | session-start.sh | sessionStarted |
Stop | agent-stop.sh | stopRequested |
PreToolUse (sync) | tool-activity.sh | toolUsed |
PostToolUse (async) | post-tool.sh | toolUsed |
SessionEnd | session-end.sh | sessionEnded |
Claude Code Integration
CLI Discovery
Pentagon searches for theclaude binary in this order:
/usr/local/bin/claude/opt/homebrew/bin/claude~/.npm-global/bin/claude$PATHlookup
Environment
Environment variables from your shell profile are passed through to Claude Code processes. Pentagon adds agent-specific configuration (model, permissions) via command-line flags.System Prompt
Pentagon generates a system prompt for each agent that includes:- The agent’s name and identity from SOUL.md
- Current tasks from TASKS.md
- Memory context from MEMORY.md
- Pod and team context if the agent belongs to a group
Git Worktree Management
TheGitWorktree Swift helper manages branch isolation across agents:
- First agent in a repository works on your existing branch. No worktree is created.
- Subsequent agents in the same repository each get an isolated git worktree with a dedicated branch.
- When an agent is deleted, its worktree is cleaned up automatically.
StatusEngine
The StatusEngine is a centralized state machine that determines every agent’s current status. All state transitions flow through a single function:StatusEngine.apply().
Inputs to the StatusEngine come from two sources:
- Hook signals — parsed from
status.jsonwritten by hook scripts - User actions — pause, resume, respawn commands from the UI
Related Pages
- StatusEngine — state machine details, signals, and transitions
- Agent File System — complete file and directory reference
- Agents — agent lifecycle and behavior
- Configuration — setup and preferences