15 मिनट में अपना पहला Claude Code सब-एजेंट कैसे बनाएं (सटीक टेम्पलेट अंदर)

@0x_rody
अंग्रेज़ी2 माह पहले · 31 मई 2026
1.1M
383
48
18
1.7K

TL;DR

यह गाइड बताती है कि कोड रिव्यू, टेस्टिंग और डॉक्यूमेंटेशन को संभालने के लिए मार्कडाउन टेम्पलेट्स का उपयोग करके विशेष Claude सब-एजेंट कैसे बनाएं, जिससे कॉन्टेक्स्ट विंडो का उपयोग ऑप्टिमाइज़ हो और API लागत कम हो सके।

आप 15 मिनट से भी कम समय में एक कोड रिव्यूअर, टेस्ट राइटर, सिक्योरिटी स्कैनर या डॉक्यूमेंटेशन जनरेटर बना सकते हैं।

हर एक एक मार्कडाउन फ़ाइल है जिसमें ऊपर निर्देश और नीचे एक प्रॉम्प्ट होता है।

जो कार्य आप हर दिन मैन्युअल करते हैं, वे अपने आप चलने लगते हैं।

यहाँ 5 रेडी-टू-यूज़ टेम्पलेट हैं जिन्हें आप अभी कॉपी कर सकते हैं 👇

rody - inline image

एक सबएजेंट वास्तव में क्या है (30 सेकंड)

सबएजेंट एक अलग Claude इंस्टेंस है जो आपके सेशन के अंदर चलता है। इसे अपना खुद का कॉन्टेक्स्ट विंडो मिलता है, यह एक फ़ोकस्ड कार्य करता है, और केवल सारांश वापस भेजता है।

आपका मुख्य सेशन साफ़ रहता है।

सबएजेंट के बिना: Claude 40 फ़ाइलें पढ़ता है, पैटर्न खोजता है, कोड जनरेट करता है, उसकी समीक्षा करता है, सभी एक ही कॉन्टेक्स्ट में टेस्ट चलाता है। मैसेज 20 तक यह ऑटोकम्पैक्ट कर रहा होता है और चीज़ें भूल जाता है।

सबएजेंट के साथ: मुख्य सेशन "इस कोड की समीक्षा करें" को एक रिव्यूअर सबएजेंट को सौंप देता है। रिव्यूअर अपने कॉन्टेक्स्ट में काम करता है, "3 समस्याएं मिलीं" लौटाता है, और मुख्य सेशन बिना शोर के जारी रहता है।

इन्हें कहाँ रखें: ~/.claude/agents/ → हर प्रोजेक्ट में उपलब्ध (व्यक्तिगत) .claude/agents/ → केवल इस प्रोजेक्ट में (git के ज़रिए टीम के साथ साझा किया जाता है)

rody - inline image

एक सबएजेंट फ़ाइल की संरचना

हर सबएजेंट एक मार्कडाउन फ़ाइल है जिसके शीर्ष पर YAML फ्रंटमैटर होता है:

markdown
1---
2name: agent-name
3description: When to use this agent. Be specific.
4model: claude-sonnet-4-5-20250929
5tools:
6 - Read
7 - Grep
8 - Glob
9 - Bash
10---
11
12You are a [role]. Your job is to [specific task].
13
14When invoked:
151. Do [step 1]
162. Do [step 2]
173. Return [specific output format]

name — जिसे आप @agent-name से कॉल करते हैं

description — Claude यह तय करने के लिए पढ़ता है कि कब ऑटो-डेलिगेट करना है। इसे ट्रिगर शर्तों की तरह लिखें: "इस एजेंट का उपयोग तब करें जब उपयोगकर्ता कोड समीक्षा के लिए कहे"

model — फ़ोकस्ड कार्यों के लिए Sonnet पर रूट करें (Opus से 5 गुना सस्ता)

tools — यह सीमित करें कि एजेंट क्या एक्सेस कर सकता है। रिव्यूअर के लिए केवल पढ़ना, लेखकों के लिए पूर्ण एक्सेस।

फ्रंटमैटर के नीचे का मार्कडाउन भाग सिस्टम प्रॉम्प्ट है। यहाँ आप एजेंट को बताते हैं कि वास्तव में कैसे व्यवहार करना है।

टेम्पलेट 1: कोड रिव्यूअर (5 मिनट)

.claude/agents/reviewer.md बनाएँ:

markdown
1---
2name: reviewer
3description: Expert code review. Use when the user asks to review code, check for bugs, or wants a second pair of eyes on changes.
4model: claude-sonnet-4-5-20250929
5tools:
6 - Read
7 - Grep
8 - Glob
9 - Bash
10---
11
12You are a senior code reviewer. Your job is to find bugs, security issues, and quality problems.
13
14When invoked:
151. Run `git diff HEAD~1` to see recent changes
162. Read the modified files completely
173. Check for:
18 - Logic errors and off-by-one mistakes
19 - Missing null/undefined checks
20 - Security issues (hardcoded secrets, injection, XSS)
21 - Performance problems (N+1 queries, blocking calls)
22 - Naming and readability issues
23
24Output format:
25## Review Summary
26[1-2 sentence overview]
27
28## Issues Found
29**CRITICAL:** [issues that will cause bugs in production]
30**WARNING:** [issues that should be fixed before merge]
31**INFO:** [style and readability suggestions]
32
33If no issues found, say "Code looks good" and explain why.
34Do NOT suggest changes that aren't improvements.

इसका उपयोग करें:

text
1check the last commit@reviewer

या जब आप "इस कोड की समीक्षा करें" कहते हैं तो Claude अपने आप डेलिगेट कर देता है।

टेम्पलेट 2: टेस्ट राइटर (5 मिनट)

.claude/agents/test-writer.md बनाएँ:

text
1---
2name: test-writer
3description: Write tests for code. Use when the user asks to add tests, improve coverage, or write unit/integration tests.
4model: claude-sonnet-4-5-20250929
5tools:
6 - Read
7 - Grep
8 - Glob
9 - Write
10 - Bash
11---
12
13You are a test engineer. Your job is to write thorough tests that match the existing test style in the project.
14
15When invoked:
161. Find existing tests in the project to match framework, imports, and assertion style
172. Read the file or module to be tested
183. Write tests covering:
19 - Happy path with expected inputs
20 - Edge cases: empty, null, zero, max values
21 - Error cases: invalid inputs, timeouts, missing data
22 - Async behavior if applicable
234. Run the tests: `npm test` or equivalent
245. Fix any failures before returning
25
26Output only the test file path and a summary of what's covered.
27Do NOT change the source code, only write tests.

इसका उपयोग करें:

text
1-writer write tests for src/lib/auth/session.ts@test

टेम्पलेट 3: डॉक्यूमेंटेशन जनरेटर (5 मिनट)

.claude/agents/doc-writer.md बनाएँ:

text
1---
2name: doc-writer
3description: Generate documentation. Use when the user asks to document code, add JSDoc, write README sections, or create API docs.
4model: claude-sonnet-4-5-20250929
5tools:
6 - Read
7 - Grep
8 - Glob
9 - Write
10---
11
12You are a documentation specialist. Your job is to write clear, concise documentation that matches the project's existing style.
13
14When invoked:
151. Read the files or module to document
162. Check for existing documentation style in the project
173. For functions: add description, params with types, return value, example usage
184. For complex logic: add inline comments explaining WHY, not WHAT
195. For APIs: document method, path, request/response shapes, auth requirements
20
21Rules:
22- Match the existing documentation style exactly
23- Be concise. Skip self-explanatory code.
24- Never change functionality, only add documentation
25- If the code is unclear, document what it does AND flag it for refactoring

इसका उपयोग करें:

text
1-writer document the entire src/api/ folder@doc

टेम्पलेट 4: सिक्योरिटी स्कैनर (5 मिनट)

.claude/agents/security.md बनाएँ:

markdown
1---
2name: security
3description: Security audit. Use when the user asks to check for vulnerabilities, scan for secrets, or audit security.
4model: claude-sonnet-4-5-20250929
5tools:
6 - Read
7 - Grep
8 - Glob
9 - Bash
10---
11
12You are a security engineer. Your job is to find vulnerabilities in the codebase.
13
14When invoked:
151. Scan for hardcoded secrets:
16 `grep -rn "sk-\|api_key\|password\|secret\|token" --include="*.ts" --include="*.js" --include="*.py" . | grep -v node_modules | grep -v ".env.example"`
172. Check for SQL injection (string concatenation in queries)
183. Check for XSS (unsanitized user input in HTML)
194. Check for missing auth on protected routes
205. Run `npm audit` or equivalent for dependency vulnerabilities
216. Check if .env files or secrets are in .gitignore
22
23Output format:
24## Security Report
25
26**CRITICAL:** [exploitable vulnerabilities]
27**HIGH:** [serious issues to fix before deploy]
28**MEDIUM:** [should be fixed soon]
29**LOW:** [best practices not followed]
30
31For each issue: file, line, what's wrong, how to fix it.
32Do NOT fix issues, only report them.

इसका उपयोग करें:

text
1scan the entire codebase@security

टेम्पलेट 5: PR विवरण लेखक (5 मिनट)

.claude/agents/pr-writer.md बनाएँ:

text
1---
2name: pr-writer
3description: Write PR descriptions. Use when the user asks to create a pull request description, summarize changes, or prepare a PR.
4model: claude-sonnet-4-5-20250929
5tools:
6 - Read
7 - Grep
8 - Glob
9 - Bash
10---
11
12You are a PR description specialist. Your job is to write clear, structured PR descriptions ready to paste into GitHub.
13
14When invoked:
151. Run `git log main..HEAD --oneline` for commit list
162. Run `git diff main...HEAD --stat` for changed files
173. Read the key changed files to understand context
18
19Output exactly this format:
20
21## What
22[One paragraph: what this PR does]
23
24## Why
25[One paragraph: why this change is needed]
26
27## Changes
28[Bullet list grouped by area]
29
30## Testing
31[How this was tested]
32
33Nothing else. Ready to paste into GitHub.

इसका उपयोग करें:

text
1-writer summarize changes on this branch@pr

सबएजेंट को कैसे इनवोक करें

तीन तरीके:

text
11. @ उल्लेख (सबसे भरोसेमंद):
2 @reviewer check the last commit
3 @test-writer write tests for auth.ts
4 @security scan src/
5
62. ऑटो-डेलिगेशन (Claude description फ़ील्ड पढ़ता है):
7 "review this code" → Claude अपने आप @reviewer चुनता है
8 "write tests" → Claude अपने आप @test-writer चुनता है
9
103. /agents कमांड (प्रबंधित करें और ब्राउज़ करें):
11 /agents → एजेंट लाइब्रेरी खुलती है
12 Running टैब → सक्रिय सबएजेंट देखें
13 Library टैब → एजेंट ब्राउज़ करें, बनाएँ, संपादित करें

ऑटो-डेलिगेशन के काम करने के लिए, description फ़ील्ड को विशिष्ट बनाएं। "इस एजेंट का उपयोग तब करें जब उपयोगकर्ता कोड समीक्षा के लिए कहे" काम करता है। "कोड सामान" काम नहीं करता।

लागत का गणित

प्रत्येक सबएजेंट अपने खुद के कॉन्टेक्स्ट विंडो में चलता है। इसका मतलब टोकन हैं। लेकिन इसका यह भी मतलब है कि आपका मुख्य सेशन हल्का रहता है।

text
1Without subagents:
2- One session does everything
3- Context bloats to 200K+ tokens by message 20
4- Every subsequent message costs more
5- Autocompact loses important context
6
7With subagents:
8- Main session stays at ~30K tokens
9- Each subagent uses ~15-20K tokens in isolation
10- Summaries return to main session (500 tokens)
11- Total tokens might be similar but quality is higher
12- Route subagents to Sonnet → 5x cheaper per agent

असली बचत: सबएजेंट को Sonnet पर रूट करना जबकि आपका मुख्य सेशन Opus पर चलता है।

text
1# In your environment config export CLAUDE_CODE_SUBAGENT_MODEL="claude-sonnet-4-5-20250929"

कहाँ से शुरू करें

एक टेम्पलेट कॉपी करें। कोई भी एक। इसे .claude/agents/ में डालें। एक बार उपयोग करें।

यदि आप केवल एक ही आज़माना चाहते हैं: reviewer से शुरू करें। अपने अगले कोड परिवर्तन के बाद @reviewer check the last commit टाइप करें। आप कभी भी स्व-समीक्षा पर वापस नहीं जाएंगे।

पढ़ने के लिए धन्यवाद!

@0x_rody

rody - inline image
एक क्लिक में सहेजें

YouMind में वायरल लेखों की AI गहन पढ़ाई

स्रोत सहेजें, केंद्रित सवाल पूछें, तर्क का सारांश बनाएँ और एक वायरल लेख को एक ही AI वर्कस्पेस में दोबारा इस्तेमाल करने लायक नोट्स में बदलें।

YouMind देखें
क्रिएटर्स के लिए

अपने Markdown को एक साफ़-सुथरे 𝕏 आर्टिकल में बदलें

जब आप अपना लंबा कंटेंट पब्लिश करते हैं, तो इमेज, टेबल और कोड ब्लॉक को 𝕏 के लिए फ़ॉर्मेट करना मुश्किल होता है। YouMind पूरे Markdown ड्राफ़्ट को एक साफ़-सुथरे, पोस्ट के लिए तैयार 𝕏 आर्टिकल में बदल देता है।

Markdown से 𝕏 आज़माएँ

समझने के लिए और पैटर्न

हाल के वायरल लेख

और वायरल लेख देखें