How to Share Code With ChatGPT or Claude (and Get Better Answers)
Updated November 5, 2026 · 8 min read
AI assistants are excellent at reading, explaining and fixing code, but only if they receive it cleanly and with enough context. Pasting a messy fragment with "fix this" gets a guess. Pasting the right code, formatted, with the error and what you expected, gets a real answer. Here's how.
Three ways to give an AI your code
| Method | Best for | Tip |
|---|---|---|
| Paste in a code block | A function or a short file | Use triple backticks plus the language name |
| Upload files | Several files, long files | Name files clearly; say which one has the problem |
| Share a link | Agents, automations, shared conversations, or reusing the same code | Use a link to the raw text so the tool reads plain code |
Paste it properly
```javascript
function total(items) {
return items.reduce((sum, i) => sum + i.price * i.qty);
}
```
The backticks keep indentation and tell the model exactly where the code begins and ends. Adding the language name avoids confusion between similar-looking languages.
Give context: the five things to include
- The goal: "This should return the cart total."
- The code: the smallest complete piece that shows the problem.
- The exact error or wrong output, as text: "Returns [object Object]100".
- The environment: language and framework versions, browser, OS.
- What you've tried: so it doesn't suggest the same thing.
For the example above, the AI would quickly spot the missing starting value in
reduce(…, 0), because you told it what the output looks like.
Prompts that work
- "Explain what this function does, line by line, for a junior developer."
- "Find the bug. Show the fixed code and explain the cause in two sentences."
- "Review this for security issues and edge cases. List them by severity."
- "Refactor for readability without changing behaviour, and write unit tests for it."
- "Convert this Python to TypeScript, keeping the same function names."
Long code: links and files
Very long pastes can get truncated or mixed up with your question. Better options:
- Upload the files with the attachment button.
- Share a snippet link: paste the code into the
code sharing tool and give the AI the link to the
raw view (
/c/…/raw), which is plain text with nothing around it. Whether a chat can open links depends on the tool and its browsing settings; agents and automations usually can. - For whole projects, use a coding agent that works directly in your repository, such as Claude Code or Codex.
Code as screenshots? Only for UI
AI tools can read code from screenshots, but small fonts and wrapped lines cause misreadings. Send code as text. Use screenshots for what code produces, such as a broken layout (sharing screenshots with AI).
Remove these before sharing
- API keys, passwords, tokens and private keys.
- Connection strings and internal URLs.
- Customer or employee data in fixtures and logs.
- Anything your company's AI policy excludes.
Replace secrets with placeholders like process.env.API_KEY. Checklist:
how to share a config file
safely.
Always verify
AI-generated fixes can be confidently wrong. Run the code, run the tests, and read the change before committing. Ask the AI to explain its fix; if the explanation doesn't make sense, the fix might not either. For more on getting the most out of each assistant, see the ChatGPT guide and the Claude guide.
Paste code and get a link plus a raw-text view that AI tools and agents can read. Free, no account.
Frequently asked questions
Should I paste code into ChatGPT or upload a file?
For one function or a short file, paste it inside a code block. For several files or very long code, upload the files or share links, so nothing gets cut or mixed up.
How do I keep formatting when pasting code into an AI chat?
Wrap the code in triple backticks with the language name, for example ```python. This keeps indentation and tells the model where the code starts and ends.
How much code should I give the AI?
Give the smallest piece that shows the problem plus anything it depends on: the function, the error, relevant types or config. Too much unrelated code makes answers vaguer.
Is it safe to share company code with AI tools?
Follow your organisation's policy. Remove secrets and personal data, and check whether your AI plan uses conversations for training and how long data is kept.
Related articles
How to Share a Screenshot With ChatGPT, Claude and Other AI Tools
How to give a screenshot to ChatGPT, Claude and other AI tools: pasting and uploading, using image links with agents and APIs, prompts that get better answers, and what not to share.
Read More →How to Share Code Snippets Online Without Breaking the Formatting
Share code so indentation survives: why chat apps mangle code, how to share a clean link with line numbers and a raw view, how to choose between a snippet link, a gist and a screenshot, and what to remove first.
Read More →Claude Complete Guide: Shortcuts, Choosing a Model, Agents (Cowork and Claude Code) and Connectors
Shortcuts, slash commands and custom commands like /roadmap, setting the model and effort, Cowork and subagents, and adding connectors and MCP servers.
Read More →