Developer Documentation
Everything you need to implement deterministic AI change management in your workflow
Getting Started
Get CodeContext running in your development environment in under 5 minutes. This guide covers installation, authentication, and your first AI-driven code change.
Installation
Install the CodeContext CLI globally via npm:
# Install globally
npm install -g @codecontext/cli
# Verify installation
codecontext --version
# Output: codecontext/1.0.0 darwin-arm64 node-v18.17.0Your First Campaign
Initialize CodeContext in your repository and run your first deterministic AI campaign:
# Initialize in your repo
cd your-project
codecontext init
# This creates:
# - .codecontext/config.yaml (configuration)
# - .codecontext/policies/ (OPA rules)
# - .codecontext/evidence/ (Evidence Packs storage)Now create and run a campaign:
# Plan a campaign (dry run)
codecontext campaign plan "Add error handling to all API endpoints" \
--scope "src/api/**/*.js" \
--budget-tokens 50000 \
--budget-dollars 5
# Review the plan
codecontext campaign review
# Apply the changes
codecontext campaign apply --with-testsConfiguration
The .codecontext/config.yaml file controls all aspects of CodeContext behavior:
# .codecontext/config.yaml
version: 1.0
organization:
id: "org_abc123"
name: "Acme Corp"
models:
primary: "gpt-4-turbo"
fallback: "claude-3-opus"
region: "us-east-1"
policies:
enforce: true
fail_closed: true
paths:
- ".codecontext/policies/*.rego"
- ".github/policies/*.rego"
budgets:
default_tokens: 100000
default_dollars: 10
max_per_campaign: 500000
evidence:
retention_days: 90
sign_with_gpg: true
include_test_logs: trueAuthentication
Use API keys in the Authorization header:
curl https://api.codecontext.ai/v1/campaigns \
-H "Authorization: Bearer cc_live_abc123..." \
-H "Content-Type: application/json"Core Concepts
Understand the fundamental building blocks of CodeContext's deterministic AI architecture.
Campaigns
A campaign is a planned, reviewable, and reversible set of code changes. Each campaign:
- Has a clear objective and scope
- Enforces budget limits (tokens and cost)
- Produces deterministic results (same input → same output)
- Generates an Evidence Pack for audit
- Can be atomically rolled back
Context Capsules™
Context Capsules are the privacy-preserving representation of your code that never contains raw source:
Capsule Structure
{
"version": "1.0",
"ast": { /* Abstract syntax tree representation */ },
"symbols": { /* Symbol table with types and references */ },
"imports": { /* Dependency graph */ },
"metadata": { "file_count": 42, "total_lines": 8453, "complexity": 127 }
}Evidence Packs™
Every campaign produces a cryptographically signed Evidence Pack containing the complete audit trail:
| Component | Description | Format |
|---|---|---|
| Prompts | Redacted prompts sent to models | JSON |
| Responses | Model outputs with metadata | JSON |
| Diffs | Git-style unified diffs | Patch |
| Policy Results | OPA evaluation outcomes | JSON |
| Test Logs | Test execution results | JSON/Text |
| Metrics | Tokens, cost, CO₂ emissions | JSON |
| Signature | GPG/SHA-256 signature | Binary |
Policy Engine
Define governance with OPA/Rego. All AI actions are validated against your policies and fail closed on violations with detailed reasons.
CLI Reference
Complete command reference for the CodeContext CLI with examples and options.
codecontext init
Initialize CodeContext in a repository:
codecontext init [options]
Options:
--org-id <id> Organization ID
--model <model> Default model (gpt-4-turbo, claude-3-opus)
--region <region> Processing region (us-east-1, eu-west-1)
--air-gapped Enable air-gapped mode (no internet)
--skip-git-hooks Don't install git hooks
Examples:
codecontext init --org-id org_abc123
codecontext init --model claude-3-opus --region eu-west-1codecontext campaign
Manage AI campaigns:
codecontext campaign <command> [options]
Commands:
plan <objective> Create a campaign plan
review [id] Review pending campaign
apply [id] Apply campaign changes
rollback <id> Rollback a campaign
list List all campaigns
status <id> Get campaign status
Options (plan):
--scope <pattern> File scope (glob pattern)
--exclude <pattern> Exclude files
--budget-tokens <n> Max tokens to use
--budget-dollars <n> Max cost in USD
--model <model> Override default model
--policy <file> Additional policy file
Examples:
codecontext campaign plan "Add TypeScript types" --scope "src/**/*.js"
codecontext campaign apply --with-tests --auto-commit
codecontext campaign rollback campaign_xyz789codecontext policy
Create, lint, and test OPA/Rego policies that gate AI operations. (Full command reference in the Security docs; examples coming soon.)
codecontext rollback
Revert a campaign atomically using the captured snapshot. Supports partial and full rollbacks.
API Reference
RESTful API for programmatic access to CodeContext. All endpoints require authentication.
Authentication
Use API keys in the Authorization header:
curl https://api.codecontext.ai/v1/campaigns \
-H "Authorization: Bearer cc_live_abc123..." \
-H "Content-Type: application/json"Campaigns API
Create a new campaign
Request Body
| Parameter | Type | Description |
|---|---|---|
| objective required | string | Campaign objective description |
| scope required | string[] | File patterns to include |
| budget | object | Token and dollar limits |
| policies | string[] | Policy IDs to enforce |
Example Request
{
"objective": "Add comprehensive error handling",
"scope": ["src/api/**/*.ts"],
"budget": { "tokens": 100000, "dollars": 10 },
"policies": ["no-pii", "security-best-practices"]
}Get campaign details and status
Response
{
"id": "campaign_xyz789",
"status": "completed",
"objective": "Add comprehensive error handling",
"created_at": "2025-03-15T10:30:00Z",
"completed_at": "2025-03-15T10:35:42Z",
"metrics": {
"files_changed": 23,
"tokens_used": 87432,
"cost_usd": 8.74,
"co2_kg": 0.043
},
"evidence_pack_url": "https://..."
}Policies API
Endpoints to manage and version Rego policies. (Endpoints documented in /docs/security and OpenAPI spec.)
Evidence API
Fetch Evidence Packs and associated artifacts. Supports signed URLs and region‑scoped access.
CI/CD Integrations
Run CodeContext campaigns automatically in your CI/CD pipeline with full policy enforcement.
GitHub Actions
Add CodeContext to your GitHub Actions workflow:
# .github/workflows/codecontext.yml
name: CodeContext AI Campaign
on:
workflow_dispatch:
inputs:
objective:
description: 'Campaign objective'
required: true
scope:
description: 'File scope pattern'
default: 'src/**/*.ts'
jobs:
campaign:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup CodeContext
uses: codecontext/setup-action@v1
with:
api-key: ${{ secrets.CODECONTEXT_API_KEY }}
- name: Plan Campaign
run: |
codecontext campaign plan \
"${{ github.event.inputs.objective }}" \
--scope "${{ github.event.inputs.scope }}" \
--budget-tokens 100000
- name: Apply Changes
run: codecontext campaign apply --with-tests
- name: Upload Evidence Pack
uses: actions/upload-artifact@v3
with:
name: evidence-pack
path: .codecontext/evidence/*.jsonGitLab CI
Configure CodeContext in GitLab CI/CD:
# .gitlab-ci.yml
stages:
- plan
- apply
variables:
CODECONTEXT_API_KEY: ${CODECONTEXT_API_KEY}
plan_campaign:
stage: plan
script:
- npm install -g @codecontext/cli
- codecontext campaign plan "$OBJECTIVE" --scope "$SCOPE"
artifacts:
paths:
- .codecontext/campaigns/
apply_campaign:
stage: apply
when: manual
script:
- codecontext campaign apply --with-tests
artifacts:
paths:
- .codecontext/evidence/Jenkins
Pipeline example with a manual approval step before applying changes:
// Jenkinsfile (Declarative)
pipeline {
agent any
environment {
CODECONTEXT_API_KEY = credentials('cc-api-key')
}
stages {
stage('Plan') {
steps {
sh 'npm install -g @codecontext/cli'
sh 'codecontext campaign plan "Harden K8s manifests" --scope "k8s/**/*.yaml" --budget-tokens 75000'
}
}
stage('Apply') {
steps {
input message: 'Apply campaign?', ok: 'Apply'
sh 'codecontext campaign apply --with-tests'
archiveArtifacts artifacts: '.codecontext/evidence/*.json', fingerprint: true
}
}
}
}Azure DevOps
Minimal YAML example for Azure Pipelines:
# azure-pipelines.yml
trigger: none
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
- task: Bash@3
displayName: Install CLI
inputs:
targetType: inline
script: |
npm install -g @codecontext/cli
- task: Bash@3
displayName: Plan Campaign
inputs:
targetType: inline
script: |
codecontext campaign plan "Upgrade dependencies + SBOM" --scope "src/**" --budget-tokens 100000
- task: Bash@3
displayName: Apply Changes
inputs:
targetType: inline
script: |
codecontext campaign apply --with-testsVideo Tutorials
Watch step-by-step tutorials to master CodeContext features.
Join our developer community on Discord, check out our GitHub discussions, or contact support: