git clone https://github.com/majorcontext/moat.git
cd moat
go build ./...# Unit tests (includes race detector) make test-unit # Single test make test-unit ARGS='-run TestName' # E2E tests (requires container runtime) go test -tags=e2e -v ./internal/e2e/ # With coverage (includes race detector) make coverage
golangci-lint run
cmd/moat/ CLI entry point (Cobra commands)
internal/
audit/ Tamper-proof audit logging with cryptographic verification
config/ moat.yaml parsing, mount string parsing
container/ Container runtime abstraction (Docker and Apple containers)
credential/ Secure credential storage (GitHub, Anthropic, AWS)
image/ Runtime-based image selection (node/python/go → base image)
log/ Structured logging (slog wrapper)
proxy/ TLS-intercepting proxy for credential injection
run/ Run lifecycle management (create/start/stop/destroy)
storage/ Per-run storage for logs, traces, network requests
Credential Injection:
moat grant github→ token from gh CLI, env var, or PAT prompt → stored encryptedmoat run --grant github→ proxy started → container traffic routed through proxy- Proxy intercepts HTTPS, injects
Authorizationheaders for matching hosts
Image Selection:
moat.yamldependenciesfield →image.Resolve()→node:X/python:X/golang:X/ubuntu:22.04
Observability:
- Container stdout →
storage.LogWriter→~/.moat/runs/<id>/logs.jsonl - Proxy requests →
storage.NetworkRequest→network.jsonl
Container Runtime Selection:
container.NewRuntime()auto-detects: Apple containers on macOS 15+ with Apple Silicon, otherwise Docker
Audit Logging:
- Events →
audit.Store.Append()→ hash-chained entries in SQLite moat audit <run-id>displays chain with verification--exportcreates portable proof bundle
The credential-injecting proxy binds to 0.0.0.0 on both Docker and Apple containers so container networks can reach it. Each run receives a cryptographically random 32-byte authentication token in HTTP_PROXY=http://moat:<token>@moat-proxy:<port>. The daemon uses the token to select that run's credentials and network policy; requests without a valid token are rejected.
The synthetic moat-proxy hostname resolves to the host gateway. Docker on Linux uses host-gateway mappings; Docker Desktop and Apple containers use addresses resolved during container initialization.
See proxy.go in the gatekeeper module for the full security model documentation.
Credential injection for Claude Code requires manual verification:
# 1. Grant Anthropic credentials moat grant anthropic # 2. Start Claude Code in a test directory moat claude ./examples/claude-code # 3. Verify Claude Code starts and can make API calls # - Claude should authenticate successfully # - Try a simple prompt to confirm API access works # 4. Check that the token was injected (not in environment) # In another terminal while Claude is running: moat run --grant anthropic -- env | grep -i anthropic # Should show ANTHROPIC_API_KEY=moat-proxy-injected (placeholder, not real token) # 5. Verify network trace shows API calls moat trace --network # Should show requests to api.anthropic.com with 200 status
# 1. Grant OpenAI credentials moat grant openai # 2. Start Codex in a test directory moat codex ./examples/agent-codex # 3. Verify Codex starts and can make API calls # - Codex should authenticate successfully # - Try a simple prompt to confirm API access works # 4. Check that the token was injected (not in environment) moat run --grant openai -- env | grep -i openai # Should show OPENAI_API_KEY=moat-proxy-injected (placeholder, not real token) # 5. Verify network trace shows API calls moat trace --network # Should show requests to api.openai.com with 200 status
# 1. Grant GitHub credentials moat grant github # 2. Test credential injection moat run --grant github -- curl -s https://api.github.com/user # Should return your GitHub user info # 3. Verify token is not in environment moat run --grant github -- env | grep -i token # Should show GH_TOKEN=moat-proxy-injected (placeholder, not real token) # 4. Verify network trace moat trace --network # Should show GET https://api.github.com/user with 200 status
For code style, error messages, documentation standards, and commit conventions, see CLAUDE.md.
Key points:
- Follow standard Go conventions and
go fmt - Use Conventional Commits format:
type(scope): description - Error messages should be actionable—tell users exactly what to do
- Documentation must match actual behavior
~/.moat/
config.yaml # Global settings
credentials/ # Encrypted tokens
proxy/ca/ # Generated CA certificate
runs/ # Per-run data
<run-id>/
metadata.json # Run configuration
logs.jsonl # Container output
network.jsonl # HTTP requests
traces.jsonl # OpenTelemetry spans
secrets.jsonl # Resolved secret names (not values)
audit.db # Tamper-proof audit database