CLI Reference

ctx CLI¶
This is a 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/) |
--no-color |
Disable colored output |
--allow-outside-cwd |
Allow context directory outside current working directory |
The
NO_COLOR=1environment variable also disables colored output.
Commands¶
| Command | Description |
|---|---|
ctx init |
Initialize .context/ directory with templates |
ctx status |
Show context summary (files, tokens, drift) |
ctx agent |
Print token-budgeted context packet for AI consumption |
ctx load |
Output assembled context in read order |
ctx add |
Add a task, decision, learning, or convention |
ctx complete |
Mark a task as done |
ctx drift |
Detect stale paths, secrets, missing files |
ctx sync |
Reconcile context with codebase state |
ctx compact |
Archive completed tasks, clean up files |
ctx tasks |
Task archival and snapshots |
ctx permissions |
Permission snapshots (golden image) |
ctx decisions |
Reindex DECISIONS.md |
ctx learnings |
Reindex LEARNINGS.md |
ctx recall |
Browse and export AI session history |
ctx journal |
Generate static site from journal entries |
ctx serve |
Serve static site locally |
ctx watch |
Auto-apply context updates from AI output |
ctx hook |
Generate AI tool integration configs |
ctx loop |
Generate autonomous loop script |
ctx pad |
Encrypted scratchpad for sensitive one-liners |
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 and PROMPT.md | |
--ralph |
Agent works autonomously without asking questions |
Creates:
.context/directory with all template files.claude/settings.local.jsonwith pre-approved ctx permissionsPROMPT.mdwith session prompt (autonomous mode with--ralph)IMPLEMENTATION_PLAN.mdwith high-level project directionCLAUDE.mdwith bootstrap instructions (or merges into existing)
Claude Code hooks and skills are provided by the ctx plugin (see Integrations).
Example:
# Collaborative mode (agent asks questions when unclear)
ctx init
# Autonomous mode (agent works independently)
ctx init --ralph
# Minimal setup (just core files)
ctx init --minimal
# Force overwrite existing
ctx init --force
# Merge into existing files
ctx init --merge
ctx status¶
Show the current context summary.
Flags:
| Flag | Short | Description |
|---|---|---|
--json |
Output as JSON | |
--verbose |
-v |
Include file contents summary |
Output:
- 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 | Default | Description |
|---|---|---|
--budget |
8000 | Token budget for context packet |
--format |
md | Output format: md or json |
--cooldown |
10m | Suppress repeated output within this duration |
--session |
(none) | Session ID for cooldown isolation (e.g., $PPID) |
Output:
- 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
# With cooldown (outputs once, then silent for 10m)
ctx agent --budget 4000 --session $PPID
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 | Short | Description |
|---|---|---|
--priority <level> |
-p |
Priority for tasks: high, medium, low |
--section <name> |
-s |
Target section within file |
--context |
-c |
Context (required for decisions and learnings) |
--rationale |
-r |
Rationale for decisions (required for decisions) |
--consequences |
Consequences for decisions (required for decisions) | |
--lesson |
-l |
Key insight (required for learnings) |
--application |
-a |
How to apply going forward (required for learnings) |
--file |
-f |
Read content from file instead of argument |
Examples:
# Add a task
ctx add task "Implement user authentication"
ctx add task "Fix login bug" --priority high
# Record a decision (requires all ADR—Architectural Decision Record—fields)
ctx add decision "Use PostgreSQL for primary database" \
--context "Need a reliable database for production" \
--rationale "PostgreSQL offers ACID compliance and JSON support" \
--consequences "Team needs PostgreSQL training"
# Note a learning (requires context, lesson, and application)
ctx add learning "Vitest mocks must be hoisted" \
--context "Tests failed with undefined mock errors" \
--lesson "Vitest hoists vi.mock() calls to top of file" \
--application "Always place vi.mock() before imports in test files"
# Add to specific section
ctx add convention "Use kebab-case for filenames" --section "Naming"
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:
- 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 |
| 3 | Violations found |
ctx sync¶
Reconcile context with the 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
- Suggests documenting dependencies if package files exist
- Identifies stale or outdated context
Example:
ctx compact¶
Consolidate and clean up context files.
- Moves completed tasks older than 7 days to the archive
- Deduplicates the "learning"s with similar content
- Removes empty sections
Flags:
| Flag | Description |
|---|---|
--archive |
Create .context/archive/ for old content |
Example:
ctx completion¶
Generate shell autocompletion scripts.
Subcommands¶
| Shell | Command |
|---|---|
bash |
ctx completion bash |
zsh |
ctx completion zsh |
fish |
ctx completion fish |
powershell |
ctx completion powershell |
Installation¶
ctx tasks¶
Manage task archival and snapshots.
ctx tasks archive¶
Move completed tasks from TASKS.md to a timestamped archive file.
Flags:
| Flag | Description |
|---|---|
--dry-run |
Preview changes without modifying files |
Archive files are stored in .context/archive/ with timestamped names
(tasks-YYYY-MM-DD.md). Completed tasks (marked with [x]) are moved;
pending tasks ([ ]) remain in TASKS.md.
Example:
ctx tasks snapshot¶
Create a point-in-time snapshot of TASKS.md without modifying the original.
Arguments:
name: Optional name for the snapshot (defaults to "snapshot")
Snapshots are stored in .context/archive/ with timestamped names
(tasks-<name>-YYYY-MM-DD-HHMM.md).
Example:
ctx permissions¶
Manage Claude Code permission snapshots.
ctx permissions snapshot¶
Save .claude/settings.local.json as the golden image.
Creates .claude/settings.golden.json as a byte-for-byte copy of the
current settings. Overwrites if the golden file already exists.
The golden file is meant to be committed to version control and shared with the team.
Example:
ctx permissions restore¶
Replace settings.local.json with the golden image.
Prints a diff of dropped (session-accumulated) and restored permissions. No-op if the files already match.
Example:
ctx permissions restore
# Dropped 3 session permission(s):
# - Bash(cat /tmp/debug.log:*)
# - Bash(rm /tmp/test-*:*)
# - Bash(curl https://example.com:*)
# Restored from golden image.
ctx decisions¶
Manage the DECISIONS.md file.
ctx decisions reindex¶
Regenerate the quick-reference index at the top of DECISIONS.md.
The index is a compact table showing the date and title for each decision, allowing AI tools to quickly scan entries without reading the full file.
Use this after manual edits to DECISIONS.md or when migrating existing files to use the index format.
Example:
ctx learnings¶
Manage the LEARNINGS.md file.
ctx learnings reindex¶
Regenerate the quick-reference index at the top of LEARNINGS.md.
The index is a compact table showing the date and title for each learning, allowing AI tools to quickly scan entries without reading the full file.
Use this after manual edits to LEARNINGS.md or when migrating existing files to use the index format.
Example:
ctx recall¶
Browse and search AI session history from Claude Code and other tools.
ctx recall list¶
List all parsed sessions.
Flags:
| Flag | Short | Description |
|---|---|---|
--limit |
-n |
Maximum sessions to display (default: 20) |
--project |
-p |
Filter by project name |
--tool |
-t |
Filter by tool (e.g., claude-code) |
--all-projects |
Include sessions from all projects |
Sessions are sorted by date (newest first) and display slug, project, start time, duration, turn count, and token usage.
Example:
ctx recall list
ctx recall list --limit 5
ctx recall list --project ctx
ctx recall list --tool claude-code
ctx recall show¶
Show details of a specific session.
Flags:
| Flag | Description |
|---|---|
--latest |
Show the most recent session |
--full |
Show full message content |
--all-projects |
Search across all projects |
The session ID can be a full UUID, partial match, or session slug name.
Example:
ctx recall show abc123
ctx recall show gleaming-wobbling-sutherland
ctx recall show --latest
ctx recall show --latest --full
ctx recall export¶
Export sessions to editable journal files in .context/journal/.
Flags:
| Flag | Description |
|---|---|
--all |
Export all sessions |
--all-projects |
Export from all projects |
--force |
Overwrite existing files completely (discard frontmatter) |
--skip-existing |
Skip files that already exist |
Exported files include session metadata, tool usage summary, and the full conversation. When re-exporting, YAML frontmatter from enrichment (topics, type, outcome, etc.) is preserved by default; only the conversation content is regenerated.
The journal/ directory should be gitignored (like sessions/) since it
contains raw conversation data.
Example:
ctx recall export abc123 # Export one session
ctx recall export --all # Export/update all sessions
ctx recall export --all --skip-existing # Skip files that already exist
ctx recall export --all --force # Overwrite completely (lose frontmatter)
ctx journal¶
Analyze and synthesize exported session files.
ctx journal site¶
Generate a static site from journal entries in .context/journal/.
Flags:
| Flag | Short | Description |
|---|---|---|
--output |
-o |
Output directory (default: .context/journal-site) |
--build |
Run zensical build after generating | |
--serve |
Run zensical serve after generating |
Creates a zensical-compatible site structure with an index page listing
all sessions by date, and individual pages for each journal entry.
Requires zensical to be installed for --build or --serve:
Example:
ctx journal site # Generate in .context/journal-site/
ctx journal site --output ~/public # Custom output directory
ctx journal site --build # Generate and build HTML
ctx journal site --serve # Generate and serve locally
ctx journal obsidian¶
Generate an Obsidian vault from journal entries in .context/journal/.
Flags:
| Flag | Short | Description |
|---|---|---|
--output |
-o |
Output directory (default: .context/journal-obsidian) |
Creates an Obsidian-compatible vault with:
- Wikilinks (
[[target|display]]) for all internal navigation - MOC pages (Map of Content) for topics, key files, and session types
- Related sessions footer linking entries that share topics
- Transformed frontmatter (
topics→tagsfor Obsidian integration) - Minimal
.obsidian/config enforcing wikilink mode
No external dependencies are required: Open the output directory as an Obsidian vault directly.
Example:
ctx journal obsidian # Generate in .context/journal-obsidian/
ctx journal obsidian --output ~/vaults/ctx # Custom output directory
ctx serve¶
Serve a static site locally via zensical.
If no directory is specified, serves the journal site (.context/journal-site).
Requires zensical to be installed:
Example:
ctx serve # Serve journal site
ctx serve .context/journal-site # Serve specific directory
ctx serve ./docs # Serve docs folder
ctx watch¶
Watch for AI output and auto-apply context updates.
Parses <context-update> XML commands from AI output and applies
them to context files.
Flags:
| Flag | Description |
|---|---|
--log <file> |
Log file to watch (default: stdin) |
--dry-run |
Preview updates without applying |
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 |
Redirects to plugin install instructions |
cursor |
Cursor IDE |
aider |
Aider CLI |
copilot |
GitHub Copilot |
windsurf |
Windsurf IDE |
Claude Code uses the plugin system
Claude Code integration is now provided via the ctx plugin.
Running ctx hook claude-code prints plugin install instructions.
Example:
ctx loop¶
Generate a shell script for running an autonomous loop.
An autonomous loop continuously runs an AI assistant with the same prompt until a completion signal is detected, enabling iterative development where the AI builds on its previous work.
Flags:
| Flag | Short | Description | Default |
|---|---|---|---|
--tool <tool> |
-t |
AI tool: claude, aider, or generic |
claude |
--prompt <file> |
-p |
Prompt file to use | PROMPT.md |
--max-iterations <n> |
-n |
Maximum iterations (0 = unlimited) | 0 |
--completion <signal> |
-c |
Completion signal to detect | SYSTEM_CONVERGED |
--output <file> |
-o |
Output script filename | loop.sh |
Example:
# Generate loop.sh for Claude Code
ctx loop
# Generate for Aider with custom prompt
ctx loop --tool aider --prompt TASKS.md
# Limit to 10 iterations
ctx loop --max-iterations 10
# Output to custom file
ctx loop -o my-loop.sh
Usage:
See Autonomous Loops for detailed workflow documentation.
ctx pad¶
Encrypted scratchpad for sensitive one-liners that travel with the project.
When invoked without a subcommand, lists all entries.
ctx pad add¶
Append a new entry to the scratchpad.
Example:
ctx pad show¶
Output the raw text of an entry by number.
Arguments:
n: 1-based entry number
Example:
ctx pad rm¶
Remove an entry by number.
Arguments:
n: 1-based entry number
ctx pad edit¶
Replace, append to, or prepend to an entry.
Arguments:
n: 1-based entry numbertext: Replacement text (mutually exclusive with--append/--prepend)
Flags:
| Flag | Description |
|---|---|
--append |
Append text to the end of the entry |
--prepend |
Prepend text to the beginning of entry |
Example:
ctx pad mv¶
Move an entry from one position to another.
Arguments:
from: Source position (1-based)to: Destination position (1-based)
ctx pad resolve¶
Show both sides of a merge conflict in the encrypted scratchpad.
Exit Codes¶
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error / warnings (e.g. drift) |
| 2 | Context not found |
| 3 | Violations found (e.g. drift) |
| 4 | File operation error |
Environment Variables¶
| Variable | Description |
|---|---|
CTX_DIR |
Override default context directory path |
CTX_TOKEN_BUDGET |
Override default token budget |
NO_COLOR |
Disable colored output when set |
Configuration File¶
Optional .contextrc (YAML format) at project root:
# .contextrc
context_dir: .context # Context directory name
token_budget: 8000 # Default token budget
priority_order: # File loading priority
- TASKS.md
- DECISIONS.md
- CONVENTIONS.md
auto_archive: true # Auto-archive old items
archive_after_days: 7 # Days before archiving
scratchpad_encrypt: true # Encrypt scratchpad (default: true)
allow_outside_cwd: false # Skip boundary check (default: false)
| Field | Type | Default | Description |
|---|---|---|---|
context_dir |
string |
.context |
Context directory name (relative to project root) |
token_budget |
int |
8000 |
Default token budget for ctx agent |
priority_order |
[]string |
(all files) | File loading priority for context packets |
auto_archive |
bool |
false |
Auto-archive completed tasks |
archive_after_days |
int |
7 |
Days before completed tasks are archived |
scratchpad_encrypt |
bool |
true |
Encrypt scratchpad with AES-256-GCM |
allow_outside_cwd |
bool |
false |
Skip boundary check for external context dirs |
Priority order: CLI flags > Environment variables > .contextrc > Defaults
All settings are optional. Missing values use defaults.