Skip to content

Commit 25ad8aa

Browse files
josealekhineclaude
andcommitted
feat: add Claude Code slash commands for ctx operations
Create ctx skills as embedded templates that `ctx init` installs to .claude/commands/: - /ctx-save: Save context to session file - /ctx-status: Show context summary - /ctx-add-learning: Add a learning - /ctx-add-decision: Add a decision - /ctx-add-task: Add a task - /ctx-agent: Load full context packet - /ctx-archive: Archive completed tasks Skills use the standard Claude Code command format with YAML frontmatter. Also fix make install to work with sudo (build first, then sudo install). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d2279f9 commit 25ad8aa

12 files changed

Lines changed: 167 additions & 13 deletions

File tree

.context/LEARNINGS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,5 @@ Manual file reading is better for exploratory/memory questions:
277277
**Application**: No need to mandate one approach. Agents naturally pick appropriately:
278278
- "Do you remember?" → parallel file reads (need history)
279279
- "What should I work on?" → `ctx agent` (need tasks)
280+
281+
- **[2026-01-23]** Claude Code skills are markdown files in .claude/commands/ with YAML frontmatter (description, argument-hint, allowed-tools). Body is the prompt. Use code blocks with ! prefix for shell execution. $ARGUMENTS passes command args.

.context/TASKS.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@
6262
- [x] Update CONSTITUTION.md: archival is allowed, deletion is not
6363

6464
### Phase 9: Claude Slash Commands (Skills) `#priority:medium` `#area:cli`
65-
- [ ] Research how existing skills are registered (check ralph-loop pattern)
66-
- [ ] Create `/ctx-save` skill — calls `ctx session save`
67-
- [ ] Create `/ctx-status` skill — calls `ctx status`
68-
- [ ] Create `/ctx-add-learning` skill — calls `ctx add learning`
69-
- [ ] Create `/ctx-add-decision` skill — calls `ctx add decision`
70-
- [ ] Create `/ctx-add-task` skill — calls `ctx add task`
71-
- [ ] Create `/ctx-agent` skill — calls `ctx agent` (manual context load)
72-
- [ ] Create `/ctx-archive` skill — calls `ctx tasks archive`
65+
- [x] Research how existing skills are registered (check ralph-loop pattern)
66+
- [x] Create `/ctx-save` skill — calls `ctx session save`
67+
- [x] Create `/ctx-status` skill — calls `ctx status`
68+
- [x] Create `/ctx-add-learning` skill — calls `ctx add learning`
69+
- [x] Create `/ctx-add-decision` skill — calls `ctx add decision`
70+
- [x] Create `/ctx-add-task` skill — calls `ctx add task`
71+
- [x] Create `/ctx-agent` skill — calls `ctx agent` (manual context load)
72+
- [x] Create `/ctx-archive` skill — calls `ctx tasks archive`
7373
- [ ] Create `/ctx-loop` skill — calls `ctx loop` (generate Ralph loop script)
74-
- [ ] Update `ctx init` to create skill definitions in `.claude/commands/`
74+
- [x] Update `ctx init` to create skill definitions in `.claude/commands/`
7575

7676
### Phase 9b: Ralph Loop Integration `#priority:medium` `#area:cli`
7777
- [ ] Implement `ctx loop` command — generate a ready-to-use loop.sh script

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ dogfood:
101101
@test -n "$(TARGET)" || (echo "Usage: make dogfood TARGET=~/WORKSPACE/ctx-dogfood" && exit 1)
102102
./hack/start-dogfood.sh $(TARGET)
103103

104-
## install: Install to /usr/local/bin
105-
install: build
106-
sudo cp $(BINARY) /usr/local/bin/$(BINARY)
104+
## install: Install to /usr/local/bin (run as: make build && sudo make install)
105+
install:
106+
@test -f $(BINARY) || (echo "Binary not found. Run 'make build' first, then 'sudo make install'" && exit 1)
107+
cp $(BINARY) /usr/local/bin/$(BINARY)
108+
@echo "Installed ctx to /usr/local/bin/ctx"
107109

108110
## help: Show this help
109111
help:

internal/claude/embed.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"fmt"
1313
)
1414

15-
//go:embed tpl/auto-save-session.sh tpl/block-non-path-ctx.sh
15+
//go:embed tpl/auto-save-session.sh tpl/block-non-path-ctx.sh tpl/commands/*.md
1616
var FS embed.FS
1717

1818
// GetAutoSaveScript returns the auto-save session script.
@@ -33,6 +33,31 @@ func GetBlockNonPathCtxScript() ([]byte, error) {
3333
return content, nil
3434
}
3535

36+
// ListCommands returns the list of embedded command file names.
37+
func ListCommands() ([]string, error) {
38+
entries, err := FS.ReadDir("tpl/commands")
39+
if err != nil {
40+
return nil, fmt.Errorf("failed to read commands directory: %w", err)
41+
}
42+
43+
var names []string
44+
for _, entry := range entries {
45+
if !entry.IsDir() {
46+
names = append(names, entry.Name())
47+
}
48+
}
49+
return names, nil
50+
}
51+
52+
// GetCommand returns the content of a command file.
53+
func GetCommand(name string) ([]byte, error) {
54+
content, err := FS.ReadFile("tpl/commands/" + name)
55+
if err != nil {
56+
return nil, fmt.Errorf("failed to read command %s: %w", name, err)
57+
}
58+
return content, nil
59+
}
60+
3661
// SettingsHooks represents the hooks section of settings.local.json
3762
type SettingsHooks struct {
3863
PreToolUse []HookMatcher `json:"PreToolUse,omitempty"`
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: "Add a decision to DECISIONS.md"
3+
argument-hint: "\"decision text\""
4+
---
5+
6+
Add a new decision to the context.
7+
8+
```!
9+
ctx add decision $ARGUMENTS
10+
```
11+
12+
Confirm the decision was added.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: "Add a learning to LEARNINGS.md"
3+
argument-hint: "\"learning text\""
4+
---
5+
6+
Add a new learning to the context.
7+
8+
```!
9+
ctx add learning $ARGUMENTS
10+
```
11+
12+
Confirm the learning was added.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: "Add a task to TASKS.md"
3+
argument-hint: "\"task text\""
4+
---
5+
6+
Add a new task to the context.
7+
8+
```!
9+
ctx add task $ARGUMENTS
10+
```
11+
12+
Confirm the task was added.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: "Get AI-ready context packet"
3+
argument-hint: "[--budget N]"
4+
---
5+
6+
Load the full context packet for AI consumption.
7+
8+
```!
9+
ctx agent $ARGUMENTS
10+
```
11+
12+
This provides the complete context state optimized for AI assistants.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: "Archive completed tasks"
3+
argument-hint: "[--dry-run]"
4+
---
5+
6+
Move completed tasks from TASKS.md to the archive.
7+
8+
```!
9+
ctx tasks archive $ARGUMENTS
10+
```
11+
12+
Report how many tasks were archived.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: "Save current context to a session file"
3+
argument-hint: "[topic]"
4+
---
5+
6+
Save the current context state to `.context/sessions/`.
7+
8+
```!
9+
ctx session save $ARGUMENTS
10+
```
11+
12+
Report the saved session file path to the user.

0 commit comments

Comments
 (0)