Skip to content

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:

bash
# Install globally
npm install -g @codecontext/cli

# Verify installation
codecontext --version
# Output: codecontext/1.0.0 darwin-arm64 node-v18.17.0
System Requirements
Node.js 16.0+ and Git 2.0+ are required. The CLI works on macOS, Linux, and Windows (WSL2).

Your First Campaign

Initialize CodeContext in your repository and run your first deterministic AI campaign:

bash
# 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:

bash
# 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-tests

Configuration

The .codecontext/config.yaml file controls all aspects of CodeContext behavior:

yaml
# .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: true

Authentication

Use API keys in the Authorization header:

bash
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

json
{
  "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:

ComponentDescriptionFormat
PromptsRedacted prompts sent to modelsJSON
ResponsesModel outputs with metadataJSON
DiffsGit-style unified diffsPatch
Policy ResultsOPA evaluation outcomesJSON
Test LogsTest execution resultsJSON/Text
MetricsTokens, cost, CO₂ emissionsJSON
SignatureGPG/SHA-256 signatureBinary

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:

bash
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-1

codecontext campaign

Manage AI campaigns:

bash
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_xyz789
Important: Rollback Window
Campaigns can be rolled back within 7 days. After that, the rollback snapshot is archived.

codecontext 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:

bash
curl https://api.codecontext.ai/v1/campaigns \
  -H "Authorization: Bearer cc_live_abc123..." \
  -H "Content-Type: application/json"

Campaigns API

POST/v1/campaigns

Create a new campaign

Request Body

ParameterTypeDescription
objective requiredstringCampaign objective description
scope requiredstring[]File patterns to include
budgetobjectToken and dollar limits
policiesstring[]Policy IDs to enforce

Example Request

json
{
  "objective": "Add comprehensive error handling",
  "scope": ["src/api/**/*.ts"],
  "budget": { "tokens": 100000, "dollars": 10 },
  "policies": ["no-pii", "security-best-practices"]
}
GET/v1/campaigns/{id}

Get campaign details and status

Response

json
{
  "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:

yaml
# .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/*.json

GitLab CI

Configure CodeContext in GitLab CI/CD:

yaml
# .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:

groovy
// 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:

yaml
# 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-tests

Video Tutorials

Watch step-by-step tutorials to master CodeContext features.

Getting Started with CodeContext
12:34
Writing Custom OPA Policies
18:45
CI/CD Integration Best Practices
22:10
Understanding Evidence Packs
15:22
Need Help?

Join our developer community on Discord, check out our GitHub discussions, or contact support: