mirror of
https://github.com/codeaashu/claude-code.git
synced 2026-04-08 22:28:48 +03:00
3.6 KiB
3.6 KiB
Prompt 10: Wire Up System Prompt, Context Gathering & Memory System
Context
You are working in /workspaces/claude-code. The CLI constructs a detailed system prompt before each conversation. This prompt includes:
- Static instructions — core behavior rules (from
src/constants/prompts.ts) - Dynamic context — OS, shell, git status, working directory (from
src/context.ts) - Tool descriptions — auto-generated from tool schemas
- Memory — persistent
.claude.mdfiles (fromsrc/memdir/) - User context — config, preferences, project settings
Key Files
src/constants/prompts.ts— System prompt constructionsrc/constants/system.ts— System identity stringssrc/context.ts— OS/shell/git context collectionsrc/context/— Additional context modulessrc/memdir/— Memory directory system (reads.claude.md,CLAUDE.mdfiles)src/utils/messages.ts— Message construction helpers
Task
Part A: Trace the system prompt construction
Read src/constants/prompts.ts and map:
- What is
getSystemPrompt()'s signature and return type? - What sections does the system prompt contain?
- How are tools described in the prompt?
- What model-specific variations exist?
- Where does the
MACRO.ISSUES_EXPLAINERreference resolve to?
Part B: Fix the context gathering
Read src/context.ts and:
- Understand
getSystemContext()andgetUserContext() - These collect OS info, shell version, git status, etc.
- Verify they work on Linux (this codebase was likely developed on macOS, so some paths may be macOS-specific)
- Fix any platform-specific issues
Part C: Wire up the memory system
Read src/memdir/ directory:
- How does it find
.claude.md/CLAUDE.mdfiles? - How is memory content injected into the system prompt?
- Does it support project-level, user-level, and session-level memory?
Verify it works by:
- Creating a test
CLAUDE.mdin the project root - Running the system prompt builder
- Checking the memory appears in the output
Part D: Create a prompt inspection script
Create scripts/test-prompt.ts:
// scripts/test-prompt.ts
// Dump the full system prompt that would be sent to the API
// Usage: bun scripts/test-prompt.ts
import './src/shims/preload.js'
async function main() {
// Import the prompt builder
const { getSystemPrompt } = await import('./src/constants/prompts.js')
// May need to pass tools list and model name
// Check the function signature
const prompt = await getSystemPrompt([], 'claude-sonnet-4-20250514')
console.log('=== SYSTEM PROMPT ===')
console.log(prompt.join('\n'))
console.log('=== END ===')
console.log(`\nTotal length: ${prompt.join('\n').length} characters`)
}
main().catch(err => {
console.error('Prompt test failed:', err)
process.exit(1)
})
Part E: Fix MACRO references in prompts
The prompt system references MACRO.ISSUES_EXPLAINER. Make sure our MACRO global (from src/shims/macro.ts) provides this value. If the prompt references other MACRO fields, add them too.
Part F: Context module audit
Check src/context/ for additional context modules:
- Project detection (language, framework)
- Git integration (branch, status, recent commits)
- Environment detection (CI, container, SSH)
Verify these work in our dev environment.
Verification
bun scripts/test-prompt.tsdumps a complete system prompt- The prompt includes: tool descriptions, OS context, memory content
- No
undefinedorMACRO.references in the output - Memory system reads
.claude.mdfrom the project root