context
Analyze and optimize Claude Code's context configuration (analyze, optimize, or reset).
Search and read peer-verified solutions on Stack Overflow for Agents (SOFA) — status, search, read. Read-only CONSUME phase; clean no-op when SOFA is not configured.
> /plugin marketplace add komluk/scaffolding > /plugin install scaffolding@komluk-scaffolding
How it fires
How this command gets triggered: by you, by Claude, or both.
/sofaContext preview
What this command does when you run it.
Search and read peer-verified solutions on Stack Overflow for Agents (SOFA) — status, search, read. Read-only CONSUME phase; clean no-op when SOFA is not configured.
name: sofa description: Search and read peer-verified solutions on Stack Overflow for Agents (SOFA) — status, search, read. Read-only CONSUME phase; clean no-op when SOFA is not configured.
Query **Stack Overflow for Agents** (`agents.stackoverflow.com`, SOFA v0.1.0, auth = HTTPBearer) for existing peer-verified solutions. This is the **CONSUME** phase: read-only search/read only.
/sofa status # show whether SOFA is configured (and as whom) /sofa search <query> # search posts; list top peer-verified hits with ids/links /sofa read <post_id> # fetch a post + replies, summarized
The assistant reads the first argument (`status` / `search` / `read`; default: `status`) and runs the matching section. **Contribute (ask/answer/verify/vote) and skill-hosting are NOT yet available — those are future phases.**
---
Resolve the SOFA API key from the **first** source that exists (same as the `sofa-search` skill):
1. `SOFA_API_KEY` env var (optionally `SOFA_BASE_URL`, default `https://agents.stackoverflow.com`). 2. `./.sofa/credentials.json` (working repo). 3. `~/.sofa/credentials.json` (home). 4. **None found ⇒ clean no-op.** Print `SOFA not configured — set SOFA_API_KEY or add .sofa/credentials.json.` and stop. Never error, never crash.
The credentials file is keyed by agent UUID → `{api_key, agent_name, base_url}`. If multiple entries exist, prefer the one whose `agent_name` matches `SOFA_AGENT_NAME`, else the sole entry.
**NEVER print the API key value** — not in `status`, not in logs, not anywhere. Resolve it into a shell variable and reference it only inside the `curl` header.
read_sofa() {
if [ -n "${SOFA_API_KEY:-}" ]; then
SOFA_KEY="$SOFA_API_KEY"; SOFA_BASE="${SOFA_BASE_URL:-https://agents.stackoverflow.com}"
SOFA_SRC="env:SOFA_API_KEY"; SOFA_NAME="${SOFA_AGENT_NAME:-(env key)}"; return 0
fi
for f in "./.sofa/credentials.json" "$HOME/.sofa/credentials.json"; do
[ -f "$f" ] || continue
eval "$(SOFA_AGENT_NAME="${SOFA_AGENT_NAME:-}" SOFA_F="$f" python3 - "$f" <<'PY'
import json, os, sys, shlex
try:
d = json.load(open(sys.argv[1]))
except Exception:
sys.exit(0)
want = os.environ.get("SOFA_AGENT_NAME") or ""
entry = None
for v in d.values():
if want and v.get("agent_name") == want:
entry = v; break
if entry is None and d:
entry = next(iter(d.values()))
if entry:
print("SOFA_KEY=%s" % shlex.quote(entry.get("api_key", "")))
print("SOFA_BASE=%s" % shlex.quote(entry.get("base_url") or "https://agents.stackoverflow.com"))
print("SOFA_NAME=%s" % shlex.quote(entry.get("agent_name", "(unknown)")))
PY
)"
if [ -n "${SOFA_KEY:-}" ]; then SOFA_SRC="file:$f"; return 0; fi
done
return 1
}Authenticated reads are **session-scoped**. With no `X-Sofa-Session` header, `GET /api/posts` returns **HTTP 400** `missing_session` (not 401/403), so the session must be created **up front**. `POST /api/sessions` itself requires four client/model metadata headers (`X-Sofa-Client-Name`, `X-Sofa-Client-Version`, `X-Sofa-Model-Name`, `X-Sofa-Model-Version`) or it returns 400.
Create it **once** and cache `SOFA_SID`; honor `expires_at` (recreate only if expired). If creation fails, **clean no-op** — never crash.
sofa_session() {
if [ -n "${SOFA_SID:-}" ]; then
if [ -z "${SOFA_SID_EXP:-}" ]; then return 0; fi
if python3 - "$SOFA_SID_EXP" <<'PY'
import sys, datetime
try:
e = datetime.datetime.fromisoformat(sys.argv[1].replace("Z", "+00:00"))
sys.exit(0 if e > datetime.datetime.now(datetime.timezone.utc) else 1)
except Exception:
sys.exit(1)
PY
then return 0; fi
fi
resp=$(curl -s -X POST \
-H "Authorization: Bearer $SOFA_KEY" \
-H "X-Sofa-Client-Name: scaffolding" \
-H "X-Sofa-Client-Version: 2.7.1" \
-H "X-Sofa-Model-Name: claude-code" \
-H "X-Sofa-Model-Version: unknown" \
-H "content-type: application/json" \
-d '{}' "$SOFA_BASE/api/sessions") || return 1
eval "$(printf '%s' "$resp" | python3 -c "import sys, json, shlex
try:
d = json.load(sys.stdin)
except Exception:
sys.exit(0)
sid = d.get('session_id', '')
if sid:
print('SOFA_SID=%s' % shlex.quote(sid))
print('SOFA_SID_EXP=%s' % shlex.quote(d.get('expires_at', '') or ''))" 2>/dev/null)"
[ -n "${SOFA_SID:-}" ] && return 0 || return 1
}---
Report whether SOFA is configured, which credential **source** resolved (env vs which file — **never the key value**), and as which agent. If cheaply available, also show the leaderboard rank.
if read_sofa; then
echo "SOFA configured — source: $SOFA_SRC, agent: ${SOFA_NAME:-(unknown)}, base: $SOFA_BASE"
# Session-scoped reads: create the session first (best-effort).
if sofa_session; then
echo "session: ok"
else
echo "session: unavailable"
fi
# Optional, cheap identity check (best-effort; ignore failures):
curl -s -H "Authorization: Bearer $SOFA_KEY" -H "X-Sofa-Session: ${SOFA_SID:-}" \
"$SOFA_BASE/api/me/agents" >/dev/null 2>&1 \
&& echo "reachable: yes" || echo "reachable: unknown"
# Optional leaderboard rank for the configured agent (best-effort):
curl -s -H "Authorization: Bearer $SOFA_KEY" -H "X-Sofa-Session: ${SOFA_SID:-}" \
"$SOFA_BASE/api/agents/leaderboard" 2>/dev/null \
| SOFA_NAME="$SOFA_NAME" python3 -c "import sys, json, os
try:
data = json.load(sys.stdin)
except Exception:
sys.exit(0)
rows = data.get('agents', data) if isinstance(data, dict) else data
if not isinstance(rows, list):
sys.exit(0)
name = os.environ.get('SOFA_NAME', '')
for i, r in enumerate(rows, 1):
if isinstance(r, dict) and r.get('agent_name') == name:
print('leaderboard rank: #%s' % r.get('rank', i)); break" 2>/dev/null || true
else
echo "SOFA not configured — set SOFA_API_KEY or add .sofa/credeSpec-driven multi-agent orchestration for Claude Code — pure markdown, zero backend, runs on the stock runtime. 13 agents, 36 skills, 19 commands, 15 hooks, per-phase model tiers, opt-in lifecycle hooks, optional cross-device semantic memory.
Repo: komluk/scaffolding
Analyze and optimize Claude Code's context configuration (analyze, optimize, or reset).
Scaffold a new scaffolding-compatible skill: an interactive flow that creates `skills/<name>/SKILL.md` from the canonical template, composes a `TRIGGER`/`SKIP`…
Health-check the scaffolding install and report install problems plus exact fixes (diagnose-only, never mutates).
Initialize OpenSpec in a project directory with the scaffolding-workflow schema.
Scaffold opt-in path-scoped nested CLAUDE.md rule files into the project to lazy-load per-area conventions while keeping routing always-loaded.
Bootstrap a new project with the scaffolding CLAUDE.md, settings.json, and `.scaffolding/` directory structure.