all-for-claudecode 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,14 +6,14 @@
6
6
  },
7
7
  "metadata": {
8
8
  "description": "Automated pipeline for Claude Code — spec → plan → implement → review → clean",
9
- "version": "2.6.0"
9
+ "version": "2.7.0"
10
10
  },
11
11
  "plugins": [
12
12
  {
13
13
  "name": "afc",
14
14
  "source": "./",
15
15
  "description": "Automated pipeline for Claude Code. Automates the full development cycle: spec → plan → implement → review → clean.",
16
- "version": "2.6.0",
16
+ "version": "2.7.0",
17
17
  "category": "automation",
18
18
  "tags": ["pipeline", "automation", "spec", "plan", "implement", "review", "critic-loop"]
19
19
  }
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "afc",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Automated pipeline for Claude Code. Automates the full development cycle: spec → plan → implement → review → clean.",
5
5
  "author": { "name": "jhlee0409", "email": "relee6203@gmail.com" },
6
6
  "homepage": "https://github.com/jhlee0409/all-for-claudecode",
7
7
  "repository": "https://github.com/jhlee0409/all-for-claudecode",
8
8
  "license": "MIT",
9
9
  "keywords": ["pipeline", "automation", "spec", "plan", "implement", "review", "critic-loop"],
10
- "commands": "./commands/"
10
+ "commands": "./commands/",
11
+ "agents": "./agents/",
12
+ "hooks": "./hooks/hooks.json"
11
13
  }
package/README.md CHANGED
@@ -108,6 +108,7 @@ Performance: ✓ no N+1 queries
108
108
  | `/afc:implement` | Execute code implementation with CI gates |
109
109
  | `/afc:test` | Test strategy planning and test writing |
110
110
  | `/afc:review` | Code review with architecture/security scanning |
111
+ | `/afc:clean` | Pipeline artifact cleanup and codebase hygiene |
111
112
  | `/afc:research` | Technical research with persistent storage |
112
113
  | `/afc:debug` | Bug diagnosis and fix |
113
114
  | `/afc:init` | Project setup — detects stack and generates config |
@@ -171,7 +172,7 @@ Every hook fires automatically — no configuration needed after install.
171
172
  | `Notification` | Desktop alerts (macOS/Linux) |
172
173
  | `TaskCompleted` | CI gate (shell) + acceptance criteria verification (LLM) |
173
174
  | `SubagentStop` | Tracks subagent completion in pipeline log |
174
- | `UserPromptSubmit` | Injects Phase/Feature context + drift checkpoint during active pipeline |
175
+ | `UserPromptSubmit` | **Inactive**: detects intent keywords and suggests matching afc skill. **Active**: injects Phase/Feature context + drift checkpoint at threshold prompts |
175
176
  | `PermissionRequest` | Auto-allows CI commands during implement/review |
176
177
  | `ConfigChange` | Audits/blocks settings changes during active pipeline |
177
178
  | `TeammateIdle` | Prevents Agent Teams idle during implement/review |
@@ -259,7 +260,7 @@ No. Pure markdown commands + bash hook scripts. No npm packages are imported at
259
260
  Debug-based RCA: traces the error, forms a hypothesis, applies a targeted fix. Halts after 3 failed attempts with full diagnosis.
260
261
 
261
262
  ### Can I run individual phases?
262
- Yes. Each phase has its own command (`/afc:spec`, `/afc:plan`, `/afc:implement`, `/afc:review`). `/afc:auto` runs them all.
263
+ Yes. Each phase has its own command (`/afc:spec`, `/afc:plan`, `/afc:implement`, `/afc:review`, `/afc:clean`). `/afc:auto` runs them all.
263
264
 
264
265
  ### What are Critic Loops?
265
266
  Convergence-based quality checks after each phase. They evaluate output against criteria and auto-fix issues until stable. 4 verdicts: PASS, FAIL, ESCALATE (asks user), DEFER.
@@ -7,7 +7,7 @@ tools:
7
7
  - Grep
8
8
  - Glob
9
9
  - Bash
10
- - Task
10
+ - Agent
11
11
  - WebSearch
12
12
  model: sonnet
13
13
  memory: project
@@ -6,7 +6,7 @@ tools:
6
6
  - Grep
7
7
  - Glob
8
8
  - Bash
9
- - Task
9
+ - Agent
10
10
  - WebSearch
11
11
  disallowedTools:
12
12
  - Write
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:analyze
3
- description: "General-purpose code and component analysis"
3
+ description: "General-purpose code and component analysis — use when the user asks to analyze code, trace a flow, audit consistency, understand how something works, or inspect components"
4
4
  argument-hint: "<analysis target or question>"
5
5
  user-invocable: true
6
6
  context: fork
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:architect
3
- description: "Architecture analysis and design advice"
3
+ description: "Architecture analysis and design advice — use when the user asks about architecture, system design, layer boundaries, or wants structural design review"
4
4
  argument-hint: "[analysis target or design question]"
5
5
  context: fork
6
6
  agent: afc-architect
package/commands/auto.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:auto
3
- description: "Full auto pipeline"
3
+ description: "Full auto pipeline — use when the user asks to run the full afc pipeline automatically or automate the spec-to-clean cycle"
4
4
  argument-hint: "[feature description in natural language]"
5
5
  ---
6
6
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:checkpoint
3
- description: "Save session state"
3
+ description: "Save session state — use when the user asks to save progress, checkpoint the session, or preserve current work state"
4
4
  argument-hint: "[checkpoint message]"
5
5
  model: haiku
6
6
  allowed-tools:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:clarify
3
- description: "Resolve spec ambiguities"
3
+ description: "Resolve spec ambiguities — auto-triggered when requirements are unclear to ask clarifying questions before proceeding"
4
4
  argument-hint: "[focus area: security, performance, UI flow]"
5
5
  user-invocable: false
6
6
  allowed-tools:
@@ -0,0 +1,126 @@
1
+ ---
2
+ name: afc:clean
3
+ description: "Pipeline artifact cleanup and codebase hygiene — use when the user asks to clean up artifacts, remove pipeline files, or finalize after implementation"
4
+ argument-hint: "[feature name — defaults to current pipeline feature]"
5
+ model: haiku
6
+ ---
7
+
8
+ # /afc:clean — Pipeline Cleanup
9
+
10
+ > Runs the clean phase independently: artifact cleanup, dead code scan, CI verification, memory update, and pipeline flag release.
11
+ > Equivalent to Phase 5 of `/afc:auto`. Use after manually running spec/plan/implement/review phases.
12
+
13
+ ## Arguments
14
+
15
+ - `$ARGUMENTS` — (optional) Feature name to clean up. Defaults to the currently active pipeline feature.
16
+
17
+ ## Prerequisites
18
+
19
+ - Pipeline must be active (`afc_state_is_active`) OR a feature name must be provided
20
+ - If pipeline is active, the current phase should be `review` or later
21
+
22
+ ## Execution Steps
23
+
24
+ ### 1. Resolve Feature
25
+
26
+ ```bash
27
+ "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase clean
28
+ ```
29
+
30
+ - If pipeline is active: read feature from state
31
+ - If `$ARGUMENTS` provides a feature name: use that (for manual cleanup without active pipeline)
32
+ - If neither: exit with error — `"No active pipeline and no feature specified. Usage: /afc:clean [feature-name]"`
33
+
34
+ Set `PIPELINE_ARTIFACT_DIR` = `.claude/afc/specs/{feature}/`
35
+
36
+ ### 2. Artifact Cleanup (scope-limited)
37
+
38
+ - **Delete only the `.claude/afc/specs/{feature}/` directory created by the current pipeline**
39
+ - If other `.claude/afc/specs/` subdirectories exist, **do not delete them** (only inform the user of their existence)
40
+ - Do not leave pipeline intermediate artifacts in the codebase
41
+
42
+ ### 3. Dead Code Scan
43
+
44
+ - Detect unused imports from the implementation process (check with `{config.ci}`)
45
+ - Remove empty directories from moved/deleted files
46
+ - Detect unused exports (re-exports of moved code from original locations etc.)
47
+
48
+ ### 4. Final CI Gate
49
+
50
+ - Run `{config.ci}` final execution
51
+ - Auto-fix on failure (max 2 attempts)
52
+
53
+ ### 5. Memory Update
54
+
55
+ - Reusable patterns found during pipeline -> record in `.claude/afc/memory/`
56
+ - If there were `[AUTO-RESOLVED]` items -> record decisions in `.claude/afc/memory/decisions/`
57
+ - **If retrospective.md exists** -> record as patterns missed by the Plan phase Critic Loop in `.claude/afc/memory/retrospectives/` (reuse as RISK checklist items in future runs)
58
+ - **If review-report.md exists** -> copy to `.claude/afc/memory/reviews/{feature}-{date}.md` before .claude/afc/specs/ deletion
59
+ - **If research.md exists** and was not already persisted in Plan phase -> copy to `.claude/afc/memory/research/{feature}.md`
60
+ - **Agent memory consolidation**: check each agent's MEMORY.md line count -- if either exceeds 100 lines, invoke the respective agent to self-prune:
61
+ ```
62
+ Task("Memory cleanup: afc-architect", subagent_type: "afc:afc-architect",
63
+ prompt: "Your MEMORY.md exceeds 100 lines. Read it, prune old/redundant entries, and rewrite to under 100 lines following your size limit rules.")
64
+ ```
65
+ (Same pattern for afc-security if needed. Skip if both are under 100 lines.)
66
+ - **Memory rotation**: for each memory subdirectory, check file count and prune oldest files if over threshold:
67
+ | Directory | Threshold | Action |
68
+ |-----------|-----------|--------|
69
+ | `quality-history/` | 30 files | Delete oldest files beyond threshold |
70
+ | `reviews/` | 40 files | Delete oldest files beyond threshold |
71
+ | `retrospectives/` | 30 files | Delete oldest files beyond threshold |
72
+ | `research/` | 50 files | Delete oldest files beyond threshold |
73
+ | `decisions/` | 60 files | Delete oldest files beyond threshold |
74
+ - Sort by filename ascending (oldest first), delete excess
75
+ - Log: `"Memory rotation: {dir} pruned {N} files"`
76
+ - Skip directories that do not exist or are under threshold
77
+
78
+ ### 6. Quality Report
79
+
80
+ Generate `.claude/afc/memory/quality-history/{feature}-{date}.json` with pipeline metrics (if pipeline was active):
81
+ ```json
82
+ {
83
+ "feature": "{feature}",
84
+ "date": "{YYYY-MM-DD}",
85
+ "totals": { "changed_files": N }
86
+ }
87
+ ```
88
+ Create `.claude/afc/memory/quality-history/` directory if it does not exist.
89
+
90
+ ### 7. Checkpoint Reset
91
+
92
+ Clear `.claude/afc/memory/checkpoint.md` **and** `~/.claude/projects/{ENCODED_PATH}/memory/checkpoint.md` (pipeline complete = session goal achieved; `ENCODED_PATH` = project path with `/` replaced by `-`).
93
+
94
+ ### 8. Timeline Finalize
95
+
96
+ ```bash
97
+ "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" log pipeline-end "Pipeline complete: {feature}"
98
+ ```
99
+
100
+ ### 9. Release Pipeline Flag
101
+
102
+ ```bash
103
+ "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" end
104
+ ```
105
+
106
+ - Stop Gate Hook deactivated
107
+ - Change tracking log deleted
108
+ - Safety tag removed (successful completion)
109
+ - Phase rollback tags removed (handled automatically by pipeline end)
110
+
111
+ ### 10. Output Summary
112
+
113
+ ```
114
+ Clean complete: {feature}
115
+ ├─ Artifacts: {N} files deleted from .claude/afc/specs/{feature}/
116
+ ├─ Dead code: {N} items removed
117
+ ├─ CI: PASSED
118
+ ├─ Memory: {N} files persisted, {N} rotated
119
+ └─ Pipeline flag: released
120
+ ```
121
+
122
+ ## Notes
123
+
124
+ - This command is safe to run multiple times (idempotent -- skips already-deleted artifacts)
125
+ - If no pipeline is active and no feature is specified, the command exits with an informative error
126
+ - When run standalone (not as part of auto), the quality report captures only the information available at clean time
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:consult
3
- description: "Expert consultation — get advice from backend, infra, PM, design, marketing, legal, security, or tech advisor specialists"
3
+ description: "Expert consultation — use when the user asks for expert advice, wants to consult a specialist, or needs domain-specific guidance on backend, infra, PM, design, marketing, legal, or tech decisions"
4
4
  argument-hint: "[domain?] \"[question]\" [brief|deep]"
5
5
  model: sonnet
6
6
  ---
package/commands/debug.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:debug
3
- description: "Bug diagnosis and fix"
3
+ description: "Bug diagnosis and fix — use when the user reports a bug, error, crash, exception, broken behavior, or something not working and wants root-cause analysis and a targeted fix"
4
4
  argument-hint: "[bug description, error message, or reproduction steps]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:doctor
3
- description: "Diagnose project health and plugin setup"
3
+ description: "Diagnose project health and plugin setup — use when the user asks for a health check, wants to diagnose project issues, or verify plugin installation"
4
4
  argument-hint: "[--verbose]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:ideate
3
- description: "Explore and structure a product idea"
3
+ description: "Explore and structure a product idea — use when the user wants to brainstorm, ideate, explore what to build, or create a product brief from a rough concept"
4
4
  argument-hint: "[rough idea or problem statement]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:implement
3
- description: "Execute code implementation"
3
+ description: "Execute code implementation — use when the user asks to implement a feature, execute a planned refactor, modify code from a plan, or build something"
4
4
  argument-hint: "[task ID or phase specification]"
5
5
  ---
6
6
 
package/commands/init.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:init
3
- description: "Project initial setup"
3
+ description: "Project initial setup — use when the user asks to set up the project, initialize afc, configure the plugin, or detect the tech stack"
4
4
  argument-hint: "[additional context]"
5
5
  allowed-tools:
6
6
  - Read
@@ -260,6 +260,7 @@ User-only (not auto-triggered — inform user on request):
260
260
  - `afc:checkpoint` — inform user when session save is requested
261
261
  - `afc:resume` — inform user when session restore is requested
262
262
  - `afc:principles` — inform user when project principles management is requested
263
+ - `afc:clean` — inform user when pipeline cleanup is requested (artifact cleanup, dead code scan, pipeline flag release)
263
264
  - `afc:triage` — inform user when parallel PR/issue triage is requested
264
265
  - `afc:pr-comment` — inform user when posting PR review comments to GitHub is requested
265
266
  - `afc:release-notes` — inform user when generating release notes from git history is requested
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:launch
3
- description: "Generate release artifacts"
3
+ description: "Generate release artifacts — use when the user asks to prepare a release, bump version, publish a package, or create release tags"
4
4
  argument-hint: "[version tag or 'auto']"
5
5
  allowed-tools:
6
6
  - Read
package/commands/plan.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:plan
3
- description: "Implementation design"
3
+ description: "Implementation design — use when the user asks to plan, design an implementation, create a file change map, or figure out how to implement something"
4
4
  argument-hint: "[additional context or constraints]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:pr-comment
3
- description: "Post PR review comments to GitHub"
3
+ description: "Post PR review comments to GitHub — use when the user asks to comment on a PR, post review feedback, or submit structured PR review comments"
4
4
  argument-hint: "<PR number> [--severity critical,warning,info]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:principles
3
- description: "Manage project principles"
3
+ description: "Manage project principles — use when the user asks to add, remove, or view project coding principles and conventions"
4
4
  argument-hint: "[action: add, remove, init]"
5
5
  allowed-tools:
6
6
  - Read
package/commands/qa.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:qa
3
- description: "Project quality audit — detect gaps between structure and runtime behavior"
3
+ description: "Project quality audit — use when the user asks for a quality audit, QA check, test confidence assessment, or wants to detect gaps in error handling and code health"
4
4
  argument-hint: "[scope: all, tests, errors, coverage, or specific concern]"
5
5
  user-invocable: true
6
6
  context: fork
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:release-notes
3
- description: "Generate user-facing release notes from git history"
3
+ description: "Generate user-facing release notes from git history — use when the user asks to write release notes, summarize changes between versions, or generate a changelog"
4
4
  argument-hint: "[v1.0.0..v2.0.0 | v2.0.0 | --post]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:research
3
- description: "Technical research"
3
+ description: "Technical research — use when the user asks to research a topic, investigate a technology, compare libraries, or explore options before deciding"
4
4
  argument-hint: "[research topic]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:resume
3
- description: "Restore session"
3
+ description: "Restore session — use when the user asks to resume a previous session, restore saved state, or continue where they left off"
4
4
  argument-hint: "[no arguments]"
5
5
  model: haiku
6
6
  allowed-tools:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:review
3
- description: "Code review"
3
+ description: "Code review — use when the user asks to review code, analyze a PR diff, do a code review, or evaluate code quality and correctness"
4
4
  argument-hint: "[scope: file path, PR number, or staged]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:security
3
- description: "Security scan (read-only)"
3
+ description: "Security scan (read-only) — use when the user asks for a security scan, security review, vulnerability check, or threat assessment"
4
4
  argument-hint: "[scan scope: file/directory path or full]"
5
5
  context: fork
6
6
  agent: afc-security
package/commands/spec.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:spec
3
- description: "Generate feature specification"
3
+ description: "Generate feature specification — use when the user asks to write a spec, define requirements, create acceptance criteria, or specify a feature"
4
4
  argument-hint: "[feature description in natural language]"
5
5
  allowed-tools:
6
6
  - Read
package/commands/tasks.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:tasks
3
- description: "Task decomposition"
3
+ description: "Task decomposition — auto-invoked during implement phase to break down plan into executable tasks with dependency tracking"
4
4
  argument-hint: "[constraints/priority directives]"
5
5
  user-invocable: false
6
6
  allowed-tools:
package/commands/test.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:test
3
- description: "Test strategy planning and test writing"
3
+ description: "Test strategy planning and test writing — use when the user asks to write tests, add test coverage, improve coverage, create unit/integration/e2e tests, or plan a testing strategy"
4
4
  argument-hint: "[target: file path, feature name, or coverage]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:triage
3
- description: "Parallel triage of open PRs and issues"
3
+ description: "Parallel triage of open PRs and issues — use when the user asks to triage PRs, review open issues, or prioritize the backlog of pull requests and issues"
4
4
  argument-hint: "[scope: --pr, --issue, --all (default), or specific numbers]"
5
5
  allowed-tools:
6
6
  - Read
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: afc:validate
3
- description: "Artifact consistency validation (read-only)"
3
+ description: "Artifact consistency validation (read-only) — auto-invoked to verify spec, plan, and task artifacts are consistent with each other"
4
4
  argument-hint: "[validation scope: spec-plan, tasks-only]"
5
5
  user-invocable: false
6
6
  context: fork
package/hooks/hooks.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "description": "Event hooks for the all-for-claudecode pipeline — CI gates, safety guards, context injection, and workflow automation",
2
3
  "hooks": {
3
4
  "SessionStart": [
4
5
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "all-for-claudecode",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Claude Code plugin that automates the full dev cycle — spec, plan, implement, review, clean.",
5
5
  "bin": {
6
6
  "all-for-claudecode": "bin/cli.mjs"
@@ -6,6 +6,10 @@
6
6
  "required": ["hooks"],
7
7
  "additionalProperties": false,
8
8
  "properties": {
9
+ "description": {
10
+ "type": "string",
11
+ "description": "Human-readable description of the hook configuration"
12
+ },
9
13
  "hooks": {
10
14
  "type": "object",
11
15
  "patternProperties": {
@@ -45,9 +45,13 @@
45
45
  "type": "string",
46
46
  "description": "Path to commands directory"
47
47
  },
48
+ "agents": {
49
+ "type": "string",
50
+ "description": "Path to agents directory"
51
+ },
48
52
  "hooks": {
49
53
  "type": "string",
50
- "description": "Path to hooks directory"
54
+ "description": "Path to hooks configuration file"
51
55
  }
52
56
  }
53
57
  }
@@ -2,9 +2,8 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # UserPromptSubmit Hook: Two modes of operation:
5
- # 1. Pipeline INACTIVE: No action (routing handled by CLAUDE.md intent-based skill table)
5
+ # 1. Pipeline INACTIVE: Detect user intent from prompt and inject specific skill routing hint
6
6
  # 2. Pipeline ACTIVE: Inject Phase/Feature context + drift checkpoint at thresholds
7
- # Exit 0 immediately if no action needed (minimize overhead)
8
7
 
9
8
  # shellcheck source=afc-state.sh
10
9
  . "$(dirname "$0")/afc-state.sh"
@@ -15,30 +14,116 @@ cleanup() {
15
14
  }
16
15
  trap cleanup EXIT
17
16
 
18
- # Consume stdin (required -- pipe breaks if not consumed)
19
- cat > /dev/null
17
+ # Read stdin (contains user prompt JSON)
18
+ INPUT=$(cat)
20
19
 
21
- # --- Branch: Pipeline INACTIVE no action needed ---
22
- # Routing is handled by CLAUDE.md intent-based skill routing table.
23
- # The main model classifies user intent natively no hook-level keyword matching.
20
+ # --- Branch: Pipeline INACTIVE -> intent-based skill routing ---
21
+ # The model has CLAUDE.md routing table but static instructions lose effectiveness
22
+ # as context grows. Reading the actual prompt and suggesting a SPECIFIC skill
23
+ # is far more actionable than a generic "check routing table" reminder.
24
24
  if ! afc_state_is_active; then
25
+
26
+ # Extract prompt text from stdin JSON
27
+ USER_TEXT=""
28
+ if command -v jq >/dev/null 2>&1; then
29
+ USER_TEXT=$(printf '%s' "$INPUT" | jq -r '.prompt // empty' 2>/dev/null || true)
30
+ else
31
+ # shellcheck disable=SC2001
32
+ # Note: sed fallback truncates at first embedded escaped quote — acceptable for keyword matching
33
+ USER_TEXT=$(printf '%s' "$INPUT" | sed 's/.*"prompt"[[:space:]]*:[[:space:]]*"//;s/".*//' 2>/dev/null || true)
34
+ fi
35
+
36
+ # Skip if prompt is already an explicit slash command
37
+ if printf '%s' "$USER_TEXT" | grep -qE '^\s*/afc:' 2>/dev/null; then
38
+ exit 0
39
+ fi
40
+
41
+ # Normalize: lowercase + truncate for matching
42
+ LOWER=$(printf '%s' "$USER_TEXT" | tr '[:upper:]' '[:lower:]' | cut -c1-500)
43
+
44
+ # Early exit for empty prompts (context-only messages, malformed JSON)
45
+ if [ -z "$LOWER" ]; then
46
+ if command -v jq >/dev/null 2>&1; then
47
+ jq -n --arg c "[afc] If this request matches an afc skill, invoke it via Skill tool. See CLAUDE.md routing table." \
48
+ '{"hookSpecificOutput":{"additionalContext":$c}}'
49
+ else
50
+ printf '{"hookSpecificOutput":{"additionalContext":"[afc] If this request matches an afc skill, invoke it via Skill tool. See CLAUDE.md routing table."}}\n'
51
+ fi
52
+ exit 0
53
+ fi
54
+
55
+ # Intent detection: priority-ordered if/elif chain.
56
+ # Each pattern targets strong-signal phrases to minimize false positives.
57
+ # The model retains final authority — this is a hint, not enforcement.
58
+ SKILL=""
59
+ # High confidence: distinctive multi-word or rare keywords
60
+ if printf '%s' "$LOWER" | grep -qE '(bug|broken|debug|not working|crash|exception)' 2>/dev/null; then
61
+ SKILL="afc:debug"
62
+ elif printf '%s' "$LOWER" | grep -qE '(code review|pr review)' 2>/dev/null; then
63
+ SKILL="afc:review"
64
+ elif printf '%s' "$LOWER" | grep -qE '(write test|add test|test coverage|improve coverage)' 2>/dev/null; then
65
+ SKILL="afc:test"
66
+ elif printf '%s' "$LOWER" | grep -qE '(security scan|security review|security audit|vulnerabilit)' 2>/dev/null; then
67
+ SKILL="afc:security"
68
+ elif printf '%s' "$LOWER" | grep -qE '(architecture|architect|system design)' 2>/dev/null; then
69
+ SKILL="afc:architect"
70
+ elif printf '%s' "$LOWER" | grep -qE '(doctor|health check|diagnose.*project)' 2>/dev/null; then
71
+ SKILL="afc:doctor"
72
+ elif printf '%s' "$LOWER" | grep -qE '(quality audit|qa audit|project quality)' 2>/dev/null; then
73
+ SKILL="afc:qa"
74
+ elif printf '%s' "$LOWER" | grep -qE '(new release|version bump|changelog|publish.*package)' 2>/dev/null; then
75
+ SKILL="afc:launch"
76
+ # Medium confidence: still distinctive but broader
77
+ elif printf '%s' "$LOWER" | grep -qE '(specification|requirements|acceptance criteria)' 2>/dev/null; then
78
+ SKILL="afc:spec"
79
+ elif printf '%s' "$LOWER" | grep -qE '(brainstorm|ideate|what to build|product brief)' 2>/dev/null; then
80
+ SKILL="afc:ideate"
81
+ elif printf '%s' "$LOWER" | grep -qE '(expert advice)' 2>/dev/null; then
82
+ SKILL="afc:consult"
83
+ elif printf '%s' "$LOWER" | grep -qE '(analyz|trace.*flow|how does.*work)' 2>/dev/null; then
84
+ SKILL="afc:analyze"
85
+ elif printf '%s' "$LOWER" | grep -qE '(research|investigat|compare.*lib)' 2>/dev/null; then
86
+ SKILL="afc:research"
87
+ # Lower confidence: common verbs
88
+ elif printf '%s' "$LOWER" | grep -qE '(implement|add feature|refactor|modify.*code)' 2>/dev/null; then
89
+ SKILL="afc:implement"
90
+ elif printf '%s' "$LOWER" | grep -qE '(review)' 2>/dev/null; then
91
+ SKILL="afc:review"
92
+ elif printf '%s' "$LOWER" | grep -qE '(spec[^a-z]|spec$)' 2>/dev/null; then
93
+ SKILL="afc:spec"
94
+ elif printf '%s' "$LOWER" | grep -qE '(plan[^a-z]|plan$)' 2>/dev/null; then
95
+ SKILL="afc:plan"
96
+ fi
97
+
98
+ # Build output (no TASK HYGIENE in inactive mode — stop-gate handles cleanup scope)
99
+ if [ -n "$SKILL" ]; then
100
+ HINT="[afc:route -> ${SKILL}] Detected intent from user prompt. Invoke /${SKILL} via Skill tool."
101
+ else
102
+ HINT="[afc] If this request matches an afc skill, invoke it via Skill tool. See CLAUDE.md routing table."
103
+ fi
104
+
105
+ if command -v jq >/dev/null 2>&1; then
106
+ jq -n --arg c "$HINT" '{"hookSpecificOutput":{"additionalContext":$c}}'
107
+ else
108
+ printf '{"hookSpecificOutput":{"additionalContext":"%s"}}\n' "$HINT"
109
+ fi
25
110
  exit 0
26
111
  fi
27
112
 
28
- # --- Branch: Pipeline ACTIVE existing Phase/Feature context ---
113
+ # --- Branch: Pipeline ACTIVE -> existing Phase/Feature context ---
29
114
 
30
- # Read Feature/Phase + JSON-safe processing (strip special characters)
115
+ # Read Feature/Phase + JSON-safe processing (strip special characters + newlines)
31
116
  FEATURE="$(afc_state_read feature || echo '')"
32
- FEATURE="$(printf '%s' "$FEATURE" | tr -d '"' | cut -c1-100)"
117
+ FEATURE="$(printf '%s' "$FEATURE" | tr -d '"\n\r' | cut -c1-100)"
33
118
  PHASE="$(afc_state_read phase || echo 'unknown')"
34
- PHASE="$(printf '%s' "$PHASE" | tr -d '"' | cut -c1-100)"
119
+ PHASE="$(printf '%s' "$PHASE" | tr -d '"\n\r' | cut -c1-100)"
35
120
 
36
121
  # Increment per-phase prompt counter + pipeline-wide total
37
122
  CALL_COUNT=$(afc_state_increment promptCount 2>/dev/null || echo 0)
38
123
  afc_state_increment totalPromptCount >/dev/null 2>&1 || echo "[afc:prompt-submit] totalPromptCount increment failed" >&2
39
124
 
40
125
  # Build context message
41
- CONTEXT="[Pipeline: ${FEATURE}] [Phase: ${PHASE}]"
126
+ CONTEXT="[Pipeline: ${FEATURE}] [Phase: ${PHASE}] [TASK HYGIENE: Mark completed tasks via TaskUpdate(status: completed) -- do not leave stale tasks]"
42
127
 
43
128
  # Drift checkpoint: inject plan constraints at every N prompts during implement/review
44
129
  # AFC_DRIFT_THRESHOLD sourced from afc-state.sh (SSOT)
@@ -53,7 +138,7 @@ fi
53
138
 
54
139
  # Output additionalContext to stdout (injected into Claude context)
55
140
  # Use jq for safe JSON encoding; printf fallback strips remaining quotes
56
- if command -v jq &> /dev/null; then
141
+ if command -v jq >/dev/null 2>&1; then
57
142
  jq -n --arg c "$CONTEXT" '{"hookSpecificOutput":{"additionalContext":$c}}'
58
143
  else
59
144
  SAFE_CONTEXT="${CONTEXT//\\/\\\\}"
@@ -30,9 +30,11 @@ ENCODED_PATH="${PROJECT_PATH//\//-}"
30
30
  MEMORY_DIR="$HOME/.claude/projects/$ENCODED_PATH/memory"
31
31
  CHECKPOINT="$MEMORY_DIR/checkpoint.md"
32
32
  OUTPUT=""
33
+ PIPELINE_ACTIVE=0
33
34
 
34
35
  # 1. Check for active pipeline
35
36
  if afc_state_is_active; then
37
+ PIPELINE_ACTIVE=1
36
38
  FEATURE=$(afc_state_read feature || true)
37
39
  OUTPUT="[AFC PIPELINE ACTIVE] Feature: $FEATURE"
38
40
 
@@ -77,17 +79,18 @@ if [ -f "$PLUGIN_ROOT/package.json" ]; then
77
79
  fi
78
80
  fi
79
81
 
80
- # 2. Check if checkpoint exists (project-local first, fallback to auto-memory)
82
+ # 2. Auto-memory checkpoint cleanup (prevent stale context pollution)
83
+ # Auto-memory files are auto-loaded into every conversation by Claude Code.
84
+ # Stale checkpoints from previous sessions can confuse the model.
85
+ # Only remove auto-memory when project-local copy also exists (prevents stranded checkpoint data loss).
81
86
  LOCAL_CHECKPOINT="$PROJECT_DIR/.claude/afc/memory/checkpoint.md"
82
- CHECKPOINT_FILE=""
83
- if [ -f "$LOCAL_CHECKPOINT" ]; then
84
- CHECKPOINT_FILE="$LOCAL_CHECKPOINT"
85
- elif [ -f "$CHECKPOINT" ]; then
86
- CHECKPOINT_FILE="$CHECKPOINT"
87
+ if [ "$PIPELINE_ACTIVE" -eq 0 ] && [ -f "$CHECKPOINT" ] && [ -f "$LOCAL_CHECKPOINT" ]; then
88
+ rm -f "$CHECKPOINT"
87
89
  fi
88
90
 
89
- if [ -n "$CHECKPOINT_FILE" ]; then
90
- RAW_LINE=$(grep 'Auto-generated:' "$CHECKPOINT_FILE" 2>/dev/null || echo "")
91
+ # 3. Check if project-local checkpoint exists (for user notification only)
92
+ if [ -f "$LOCAL_CHECKPOINT" ]; then
93
+ RAW_LINE=$(grep 'Auto-generated:' "$LOCAL_CHECKPOINT" 2>/dev/null || echo "")
91
94
  FIRST_LINE=$(printf '%s\n' "$RAW_LINE" | head -1)
92
95
  CHECKPOINT_DATE="${FIRST_LINE##*Auto-generated: }"
93
96
  if [ -n "$CHECKPOINT_DATE" ]; then
@@ -99,7 +102,7 @@ if [ -n "$CHECKPOINT_FILE" ]; then
99
102
  fi
100
103
  fi
101
104
 
102
- # 3. Check for safety tag
105
+ # 4. Check for safety tag
103
106
  HAS_SAFETY_TAG=$(cd "$PROJECT_DIR" 2>/dev/null && git tag -l 'afc/pre-*' 2>/dev/null | head -1 || echo "")
104
107
  if [ -n "$HAS_SAFETY_TAG" ]; then
105
108
  if [ -n "$OUTPUT" ]; then