CLI Reference¶
Complete reference for all ctx commands.
Global Options¶
All commands support these flags:
| Flag | Description |
|---|---|
--help |
Show command help |
--version |
Show version |
--context-dir <path> |
Override context directory (default: .context) |
--quiet |
Suppress non-essential output |
--no-color |
Disable colored output |
Commands¶
ctx init¶
Initialize a new .context/ directory with template files.
Flags:
| Flag | Short | Description |
|---|---|---|
--force |
-f |
Overwrite existing context files |
--minimal |
-m |
Only create essential files (TASKS.md, DECISIONS.md, CONSTITUTION.md) |
--merge |
Auto-merge ctx content into existing CLAUDE.md |
What it creates:
.context/directory with all template files.claude/hooks/with auto-save script (for Claude Code).claude/settings.local.jsonwith hook configurationCLAUDE.mdwith bootstrap instructions (or merges into existing)
Example:
# Standard initialization
ctx init
# Minimal setup (just core files)
ctx init --minimal
# Force overwrite existing
ctx init --force
# Merge into existing CLAUDE.md
ctx init --merge
ctx status¶
Show current context summary.
Flags:
| Flag | Short | Description |
|---|---|---|
--json |
Output as JSON | |
--verbose |
-v |
Include file contents summary |
Output includes:
- Context directory path
- Total files and token estimate
- Status of each file (loaded, empty, missing)
- Recent activity (modification times)
- Drift warnings if any
Example:
ctx agent¶
Print an AI-ready context packet optimized for LLM consumption.
Flags:
| Flag | Description |
|---|---|
--budget <tokens> |
Token budget (default: 8000) |
--format md\|json |
Output format (default: md) |
Output includes:
- Read order for context files
- Constitution rules (never truncated)
- Current tasks
- Key conventions
- Recent decisions
Example:
# Default (8000 tokens, markdown)
ctx agent
# Custom budget
ctx agent --budget 4000
# JSON format
ctx agent --format json
Use case: Copy-paste into AI chat, pipe to system prompt, or use in hooks.
ctx load¶
Load and display assembled context as AI would see it.
Flags:
| Flag | Description |
|---|---|
--budget <tokens> |
Token budget for assembly (default: 8000) |
--raw |
Output raw file contents without assembly |
Example:
ctx add¶
Add a new item to a context file.
Types:
| Type | Target File |
|---|---|
task |
TASKS.md |
decision |
DECISIONS.md |
learning |
LEARNINGS.md |
convention |
CONVENTIONS.md |
Flags:
| Flag | Description |
|---|---|
--priority <level> |
Priority for tasks: high, medium, low |
--section <name> |
Target section within file |
--edit |
Open editor for full entry |
Examples:
# Add a task
ctx add task "Implement user authentication"
ctx add task "Fix login bug" --priority high
# Record a decision
ctx add decision "Use PostgreSQL for primary database"
# Note a learning
ctx add learning "Vitest mocks must be hoisted"
# Add to specific section
ctx add learning "Always use --no-gpg-sign" --section "Git"
ctx complete¶
Mark a task as completed.
Arguments:
task-id-or-text: Task number or partial text match
Examples:
ctx drift¶
Detect stale or invalid context.
Flags:
| Flag | Description |
|---|---|
--json |
Output machine-readable JSON |
--fix |
Auto-fix simple issues |
Checks performed:
- Path references in ARCHITECTURE.md and CONVENTIONS.md exist
- Task references are valid
- Constitution rules aren't violated (heuristic)
- Staleness indicators (old files, many completed tasks)
Example:
Exit codes:
| Code | Meaning |
|---|---|
| 0 | All checks passed |
| 1 | Warnings found |
| 2 | Violations found |
ctx sync¶
Reconcile context with current codebase state.
Flags:
| Flag | Description |
|---|---|
--dry-run |
Show what would change without modifying |
What it does:
- Scans codebase for structural changes
- Compares with ARCHITECTURE.md
- Checks DEPENDENCIES.md against package.json/go.mod
- Identifies stale or outdated context
Example:
ctx compact¶
Consolidate and clean up context files.
Flags:
| Flag | Description |
|---|---|
--archive |
Create .context/archive/ for old content |
What it does:
- Moves completed tasks older than 7 days to archive
- Deduplicates learnings with similar content
- Removes empty sections
Example:
ctx watch¶
Watch for AI output and auto-apply context updates.
Flags:
| Flag | Description |
|---|---|
--log <file> |
Log file to watch (default: stdin) |
--dry-run |
Preview updates without applying |
--auto-save |
Periodically save session snapshots |
What it does:
Parses <context-update> XML commands from AI output and applies them to context files.
Example:
# Watch stdin
ai-tool | ctx watch
# Watch a log file
ctx watch --log /path/to/ai-output.log
# Preview without applying
ctx watch --dry-run
ctx hook¶
Generate AI tool integration configuration.
Supported tools:
| Tool | Description |
|---|---|
claude-code |
Claude Code CLI |
cursor |
Cursor IDE |
aider |
Aider CLI |
copilot |
GitHub Copilot |
windsurf |
Windsurf IDE |
Example:
ctx session¶
Manage session snapshots.
ctx session save¶
Save current context snapshot.
Flags:
| Flag | Description |
|---|---|
--type <type> |
Session type: feature, bugfix, refactor, session |
Example:
ctx session list¶
List saved sessions.
Output: Table of sessions with index, date, topic, and type.
ctx session load¶
Load and display a previous session.
Arguments:
index: Numeric index fromsession listdate: Date pattern (e.g.,2026-01-21)topic: Topic keyword match
Example:
ctx session load 1 # by index
ctx session load 2026-01-21 # by date
ctx session load auth # by topic
ctx session parse¶
Parse JSONL transcript to readable markdown.
Flags:
| Flag | Description |
|---|---|
--extract |
Extract decisions and learnings from transcript |
Example:
ctx session parse ~/.claude/projects/.../transcript.jsonl
ctx session parse transcript.jsonl --extract
Exit Codes¶
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Context not found |
| 3 | Invalid arguments |
| 4 | File operation error |
Environment Variables¶
| Variable | Description |
|---|---|
CTX_DIR |
Override default context directory path |
NO_COLOR |
Disable colored output when set |
Configuration File¶
Optional .contextrc or context.config.js at project root: