claude: run /analyze in a forked subagent#2511
Open
echarrod wants to merge 1 commit into
Open
Conversation
/analyze is explicitly read-only and produces a compact analysis report from heavy artefact reads (spec.md, plan.md, tasks.md). It matches the canonical use case for context: fork — bulk inputs that collapse to a short summary, no need for conversation history. Forking keeps the artefact contents out of the main conversation context, which is the concern raised in github#752. Done as a per-command opt-in via FORK_CONTEXT_COMMANDS so other spec-kit commands (which are interactive or have side effects) are unaffected. Refs github#752
Collaborator
|
Please deliver this as a preset as per https://github.com/github/spec-kit/tree/main/presets |
Contributor
Author
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? |
Collaborator
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
context: fork+agent: general-purposeto the generated/analyzeClaude skill so it runs in an isolated subagent context.Refs #752 — scoped narrowly to
/analyzerather than every command, because most spec-kit commands are interactive or have side effects and rely on conversation continuity.Why
/analyzespecifically/analyzeis the strongest fit forcontext: forkin the spec-kit command set:STRICTLY READ-ONLY: Do not modify any files.$ARGUMENTS.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-purposeoverExploreClaude Code's
Exploreagent description warns it's unsuitable for "cross-file consistency checks, design-doc auditing, or open-ended analysis" — which is exactly what/analyzedoes.general-purposehas 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_COMMANDSmapping mirroring the existing per-commandARGUMENT_HINTSpattern, withanalyzeas 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 overridesClaudeIntegration.setup(), after argument-hint injection, look up the stem in this mapping and inject each key/value via the existing_inject_frontmatter_flaghelper (idempotent, so re-running setup is safe)context: forkis Claude-Code-specific frontmatterTests
Four new 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 keysFull suite:
2866 passed, 34 skippedlocally.Test plan for reviewers
uv run pytest tests/integrations/test_integration_claude.py -v— all 34 tests pass (30 existing + 4 new)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/speckit-analyzein a populated spec-kit project — output should be a single summarised report; the artefact contents should not appear in the main conversation