Skip to content

Your First Project

This guide walks you through a complete Contextia workflow from scratch. By the end, you will have initialized a project, written a spec, annotated your code, created and completed a task, and verified integrity with contextia check.

Install Contextia via uvx or pip:

Terminal window
pip install contextia
# or
uvx contextia --help

You need a project directory with some source code. For this guide, we will use a small Python project.

Navigate to your project root and run:

Terminal window
contextia init

Contextia detects your project language, creates the .contextia/ directory, and generates a starter config.yaml and identity.md.

.contextia/
config.yaml
system/
identity.md
specs/
norms/
rationale/
work/
tasks/

Open .contextia/config.yaml and review the auto-detected settings:

project:
name: my-app
languages:
- python
source_paths:
- src/
annotations:
prefix: "@"
comment_syntax:
python: "#"

Adjust source_paths to match where your code lives. The comment_syntax map tells the scanner how to find annotations in each language.

Create a spec using the scaffolding command:

Terminal window
contextia new spec --id SPEC-001 --title "User authentication"

This creates .contextia/system/specs/SPEC-001.md with a template. Open it and fill in the behavioral contract:

---
id: SPEC-001
title: User authentication
description: Handles user login, token issuance, and session validation.
status: draft
decisions:
- DEC-001
norms:
- NORM-SEC-001
paths:
- src/auth/
---
## Objective
Provide secure user authentication using JWT tokens.
## Behaviors
WHEN a user submits valid credentials
THEN the system issues a signed JWT with a 1-hour expiry.
WHEN a user submits invalid credentials
THEN the system returns a 401 status with no token.
WHEN a request includes an expired token
THEN the system returns a 401 status and the client must re-authenticate.

Specs often depend on architectural decisions. Create one:

Terminal window
contextia new decision --id DEC-001 --title "JWT for session tokens"

Edit .contextia/system/rationale/DEC-001.md:

---
id: DEC-001
title: JWT for session tokens
status: accepted
date: 2026-03-02
specs:
- SPEC-001
---
## Context
We need stateless session management for horizontal scaling.
## Decision
Use JWT (JSON Web Tokens) signed with RS256.
## Consequences
- Stateless: no session store required.
- Revocation requires a short expiry or a deny-list.

Open your source file and add annotations linking back to the spec:

src/auth/login.py
# @spec SPEC-001
# @decision DEC-001
def authenticate_user(username: str, password: str) -> Token:
"""Authenticate user and return a JWT token."""
user = find_user(username)
if user and verify_password(password, user.hashed_password):
return create_jwt(user.id)
raise AuthenticationError("Invalid credentials")

The @spec SPEC-001 annotation creates a traceable link from this function to the spec. The scanner picks these up during contextia refresh.

Tasks are work orders that reference specs. Create one:

Terminal window
contextia new task --id TASK-001 --title "Implement login endpoint" \
--specs SPEC-001

This creates .contextia/work/tasks/TASK-001.md:

---
id: TASK-001
title: Implement login endpoint
status: open
kind: feature
priority: high
specs:
- SPEC-001
---
## Description
Implement the `/auth/login` POST endpoint per SPEC-001.

Step 7: Activate the task and load context

Section titled “Step 7: Activate the task and load context”

When you (or an AI agent) begin working, activate the task:

Terminal window
contextia task activate TASK-001

This creates a working directory at .contextia/work/active/TASK-001/ with space for session logs and proposals.

Now assemble the full context for the task:

Terminal window
contextia context TASK-001

Contextia follows the links deterministically:

  1. Reads TASK-001 and finds specs: [SPEC-001].
  2. Reads SPEC-001 and finds decisions: [DEC-001], norms: [NORM-SEC-001].
  3. Loads each linked artifact.
  4. Assembles everything into a single context block.
── Task: TASK-001 — Implement login endpoint ──
── Spec: SPEC-001 — User authentication ──
── Decision: DEC-001 — JWT for session tokens ──
── Norm: NORM-SEC-001 — Security defaults ──

Run the integrity checker to verify all links resolve and annotations match:

Terminal window
contextia check

A clean run looks like this:

Checking .contextia/ integrity...
Specs: 1 found, 0 issues
Decisions: 1 found, 0 issues
Norms: 0 found, 0 issues
Tasks: 1 found, 0 issues
Annotations: 2 found, 0 orphans, 0 missing
All checks passed.

If a spec references a decision that does not exist, or an annotation points to a missing spec, check reports the issue with file path and line number.

After implementation is done, close the task:

Terminal window
contextia task complete TASK-001

This updates the task status to completed in its frontmatter and archives the working directory.

In this walkthrough you have:

  • Initialized a Contextia project with contextia init
  • Written a behavioral spec in WHEN/THEN format
  • Recorded an architectural decision with rationale
  • Annotated source code with @spec and @decision
  • Created and activated a task linked to the spec
  • Assembled deterministic context with contextia context
  • Verified integrity with contextia check
  • Completed and archived the task