feat(claude): run /analyze in a forked subagent
Summary
Adds context: fork + agent: general-purpose to the generated /analyze Claude skill so it runs in an isolated subagent context.
Refs #752 — scoped narrowly to /analyze rather than every command, because most spec-kit commands are interactive or have side effects and rely on conversation continuity.
Why /analyze specifically
/analyze is the strongest fit for context: fork in the spec-kit command set:
- Explicitly read-only. The template states
STRICTLY READ-ONLY: Do not modify any files. - Heavy inputs that collapse to a short report. Loads spec.md, plan.md, tasks.md, and the constitution; emits a compact findings table.
- No conversation history needed. The task is fully described by the skill content and
$ARGUMENTS. - Matches the docs' canonical example. Run skills in a subagent shows exactly this pattern.
Net effect: the artefact contents stay inside the subagent. The main session only sees the report — the user keeps a clean conversation context for follow-up work, which is the concern raised in #752.
Why general-purpose over Explore
Claude Code's Explore agent description warns it's unsuitable for "cross-file consistency checks, design-doc auditing, or open-ended analysis" — which is exactly what /analyze does. general-purpose has the same read-only tool surface without that caveat.
Why per-command opt-in (not a global flag)
Other spec-kit commands aren't safe to fork:
/specify,/plan,/tasks,/implement,/clarify,/checklist,/constitution,/taskstoissues— all interactive, accept follow-up turns, or write files based on conversation context. Forking would break them.
So this PR introduces a FORK_CONTEXT_COMMANDS mapping mirroring the existing per-command ARGUMENT_HINTS pattern, with analyze as the single entry. New commands can opt in if they fit the same criteria.
Implementation
FORK_CONTEXT_COMMANDS: dict[str, dict[str, str]]— stem → frontmatter overrides.- The per-command frontmatter injection (both
argument-hintand fork context) lives inClaudeIntegration.post_process_skill_content()— the single method every skill-generation path calls (setup(), preset overrides, and extensions). It derives the command stem from the frontmattername:and injects each key/value via the idempotent_inject_frontmatter_flag/inject_argument_hinthelpers. This means a preset or extension that regeneratesspeckit-analyzekeepscontext: forkinstead of silently dropping it — previously the injection lived only insetup(), so those paths bypassed it.setup()is now just the post-process loop. - Non-Claude integrations are untouched —
context: forkis Claude-Code-specific frontmatter.
Tests
Seven tests under TestClaudeForkContext:
test_analyze_skill_runs_in_forked_subagent— speckit-analyze hascontext: fork+agent: general-purposetest_other_skills_do_not_fork— no other speckit-* skill gainscontextoragenttest_fork_flags_inside_frontmatter— keys land in frontmatter, not bodytest_fork_injection_idempotent— re-running setup doesn't duplicate keystest_fork_context_injected_via_post_process— the preset/extension path (post_process_skill_content) also injects fork context + argument-hinttest_post_process_no_fork_for_other_skills— non-fork skills gain nothing via that pathtest_post_process_fork_idempotent— re-running post_process doesn't duplicate keys
Test plan for reviewers
uv run --extra test python -m pytest tests/integrations/test_integration_claude.py -v— 37 tests pass (30 existing + 7 fork-context)uv run specify init test-proj --ai claude --script sh --no-git --ignore-agent-toolsand inspecttest-proj/.claude/skills/speckit-analyze/SKILL.md— frontmatter should containcontext: forkandagent: general-purpose- Run
/speckit-analyzein a populated spec-kit project — output should be a single summarised report; the artefact contents should not appear in the main conversation
Please deliver this as a preset as per https://github.com/github/spec-kit/tree/main/presets
Please deliver this as a preset as per https://github.com/github/spec-kit/tree/main/presets
Hi @mnriem, my thinking was that this would be useful behaviour to all, regardless of whether you've opted in to the preset or not. Are you concerned with it becoming default behaviour?
It is a matter of traceability. Not every one would want sub agents to get triggered automatically. Hence why it would be better as a preset so one can opt into it. And also making sure that the core stays agnostic as much as possible
Pushed ebf98c1 to close a gap in this change: the fork-context (and argument-hint) frontmatter was injected only in ClaudeIntegration.setup(), so skills generated through post_process_skill_content() directly - presets and extensions - bypassed it. A preset overriding speckit-analyze, for example, would silently drop context: fork.
The per-command injection now lives in post_process_skill_content() - the one method every generation path calls - keyed off the frontmatter name:, so setup(), presets, and extensions stay consistent. setup() is now just the post-process loop. Added 3 regression tests for the post_process path (injection applied, non-fork skills untouched, idempotency).
Please resolve conflicts
Please resolve conflicts
Resolved now 👍
Please address Copilot feedback
Hi @mnriem, addressed now 🙏
Thank you!