The Code Context feature allows you to add your codebase as context to chat sessions. This helps AI assistants understand your code and provide more relevant responses.
Navigate to: http://localhost:8000/static/chat_sessions.html
Use your credentials to login
- Select or create a chat session
- Click the green "+ Add Code Context" button in the header
- Choose one of two options:
Best for: Public GitHub/GitLab repositories
- Click "Repository URL" card
- Enter your repository URL (e.g.,
https://github.com/username/repo) - Click "Add Repository"
- Done! A green badge will appear next to your chat title
Example URLs:
https://github.com/fastapi/fastapihttps://github.com/python/cpythonhttps://gitlab.com/username/project
Best for: Private code or local projects
- Click "Upload Zip File" card
- Click "Choose File" and select your zip file
- Click "Upload Zip"
- Done! The system will automatically:
- Extract code files
- Filter out binary files
- Store only relevant code
- Show you how many files were processed
Supported File Types:
- Python (
.py) - JavaScript/TypeScript (
.js,.ts,.jsx,.tsx) - Java (
.java) - C/C++ (
.c,.cpp,.h) - And 20+ more languages!
- Green Badge next to chat title showing "Repository" or "Zip"
- Context is Saved with your session
- Ready to Use - AI can reference your code in responses
- Click "+ Add Code Context" again
- Scroll to bottom of modal
- See "Current Context" section with:
- Context type
- Source (URL or filename)
- Number of files extracted
- "Remove Context" button
- Click "+ Add Code Context"
- Scroll down to "Current Context"
- Click "Remove Context" button
- Confirm removal
- Simply add new context (either URL or zip)
- New context automatically replaces the old one
- Use zip files for private or local code
- Use repository URLs for public GitHub/GitLab repos
- Compress only relevant code folders (not node_modules, etc.)
- Keep individual files under 1MB
- Don't include binary files (they'll be skipped anyway)
- Don't upload entire large projects (be selective)
- Don't include sensitive data in context
Scenario: You want to discuss your React project with an AI assistant
-
Prepare Code:
cd my-react-project zip -r my-project.zip src/ public/ package.json README.md -
Upload:
- Open chat sessions UI
- Create session named "React Project Discussion"
- Click "+ Add Code Context"
- Choose "Upload Zip File"
- Select
my-project.zip - Click "Upload Zip"
-
Chat:
- See "Zip" badge appear
- Start chatting about your code
- AI can reference your uploaded files
Solution: Make sure your file ends with .zip
Solution: URL must start with http:// or https://
Solution: Your zip might not contain supported file types. Check the supported extensions list.
Solution:
- Your zip might be too large
- Try zipping only essential files
- Remove large dependencies (node_modules, etc.)
-
Create a test zip:
# Create a test directory mkdir test-code cd test-code # Create sample files echo "print('Hello, World!')" > main.py echo "console.log('Hello!');" > app.js echo "# Test Project" > README.md # Zip it cd .. zip -r test-code.zip test-code/
-
Upload it:
- Open chat UI
- Create test session
- Upload the zip
- Should see "3 files" extracted
python3 test_context_feature.py- Login Screen → Enter credentials → Click Login
- Sessions List → Click "+ New Chat" → Enter title
- Chat View → Click green "+ Add Code Context" button
- Modal Opens → Two cards displayed
- Choose Option:
- Repository: Enter URL → Click "Add Repository"
- Zip: Click "Choose File" → Select zip → Click "Upload Zip"
- Success → Badge appears → Modal closes
- Verify → Click "+ Add Code Context" again → See "Current Context"
- Chat → Start sending messages with code context available
Q: Can I add multiple contexts to one session? A: No, each session can have one context. Adding new context replaces the old one.
Q: Is my code secure? A: Yes, context is stored in your database and only accessible to you.
Q: What if my repository is private? A: For now, use the zip upload option. GitHub integration coming soon!
Q: How large can my zip file be? A: Individual files are limited to 1MB. Total zip size should be reasonable (under 50MB recommended).
Q: Can I see the extracted files? A: The UI shows file count. Full file browser coming in future update.
Q: Does it work with GitLab/Bitbucket? A: Repository URL accepts any valid URL. Auto-fetching is not yet implemented but planned.
- Try both methods (URL and zip)
- Experiment with different code projects
- Use context in your chats
- Provide feedback for improvements!
- Check:
CODE_CONTEXT_FEATURE.mdfor detailed documentation - Run:
python3 test_context_feature.pyto verify setup - Review: Backend code in
app/routers/chat_sessions.py
Happy Coding! 🚀