basant307/AI_Governance_Project
045
1# Common workflows2 3> Learn about common workflows with Qwen Code.4 5Each task in this document includes clear instructions, example commands, and best practices to help you get the most from Qwen Code.6 7## Understand new codebases8 9### Get a quick codebase overview10 11Suppose you've just joined a new project and need to understand its structure quickly.12 13**1. Navigate to the project root directory**14 15```bash16cd /path/to/project17```18 19**2. Start Qwen Code**20 21```bash22qwen23```24 25**3. Ask for a high-level overview**26 27```28give me an overview of this codebase29```30 31**4. Dive deeper into specific components**32 33```34explain the main architecture patterns used here35```36 37```38what are the key data models?39```40 41```42how is authentication handled?43```44 45> [!tip]46>47> - Start with broad questions, then narrow down to specific areas48> - Ask about coding conventions and patterns used in the project49> - Request a glossary of project-specific terms50 51### Find relevant code52 53Suppose you need to locate code related to a specific feature or functionality.54 55**1. Ask Qwen Code to find relevant files**56 57```58find the files that handle user authentication59```60 61**2. Get context on how components interact**62 63```64how do these authentication files work together?65```66 67**3. Understand the execution flow**68 69```70trace the login process from front-end to database71```72 73> [!tip]74>75> - Be specific about what you're looking for76> - Use domain language from the project77 78## Fix bugs efficiently79 80Suppose you've encountered an error message and need to find and fix its source.81 82**1. Share the error with Qwen Code**83 84```85I'm seeing an error when I run npm test86```87 88**2. Ask for fix recommendations**89 90```91suggest a few ways to fix the @ts-ignore in user.ts92```93 94**3. Apply the fix**95 96```97update user.tsto add the null check you suggested98```99 100> [!tip]101>102> - Tell Qwen Code the command to reproduce the issue and get a stack trace103> - Mention any steps to reproduce the error104> - Let Qwen Code know if the error is intermittent or consistent105 106## Refactor code107 108Suppose you need to update old code to use modern patterns and practices.109 110**1. Identify legacy code for refactoring**111 112```113find deprecated API usage in our codebase114```115 116**2. Get refactoring recommendations**117 118```119suggest how to refactor utils.js to use modern JavaScript features120```121 122**3. Apply the changes safely**123 124```125refactor utils.js to use ES 2024 features while maintaining the same behavior126```127 128**4. Verify the refactoring**129 130```131run tests for the refactored code132```133 134> [!tip]135>136> - Ask Qwen Code to explain the benefits of the modern approach137> - Request that changes maintain backward compatibility when needed138> - Do refactoring in small, testable increments139 140## Use specialized subagents141 142Suppose you want to use specialized AI subagents to handle specific tasks more effectively.143 144**1. View available subagents**145 146```147/agents148```149 150This shows all available subagents and lets you create new ones.151 152**2. Use subagents automatically**153 154Qwen Code automatically delegates appropriate tasks to specialized subagents:155 156```157review my recent code changes for security issues158```159 160```161run all tests and fix any failures162```163 164**3. Explicitly request specific subagents**165 166```167use the code-reviewer subagent to check the auth module168```169 170```171have the debugger subagent investigate why users can't log in172```173 174**4. Create custom subagents for your workflow**175 176```177/agents178```179 180Then select "create" and follow the prompts to define:181 182- A unique identifier that describes the subagent's purpose (for example, `code-reviewer`, `api-designer`).183- When Qwen Code should use this agent184- Which tools it can access185- A system prompt describing the agent's role and behavior186 187> [!tip]188>189> - Create project-specific subagents in `.qwen/agents/` for team sharing190> - Use descriptive `description` fields to enable automatic delegation191> - Limit tool access to what each subagent actually needs192> - Know more about [Sub Agents](./features/sub-agents)193> - Know more about [Approval Mode](./features/approval-mode)194 195## Work with tests196 197Suppose you need to add tests for uncovered code.198 199**1. Identify untested code**200 201```202find functions in NotificationsService.swift that are not covered by tests203```204 205**2. Generate test scaffolding**206 207```208add tests for the notification service209```210 211**3. Add meaningful test cases**212 213```214add test cases for edge conditions in the notification service215```216 217**4. Run and verify tests**218 219```220run the new tests and fix any failures221```222 223Qwen Code can generate tests that follow your project's existing patterns and conventions. When asking for tests, be specific about what behavior you want to verify. Qwen Code examines your existing test files to match the style, frameworks, and assertion patterns already in use.224 225For comprehensive coverage, ask Qwen Code to identify edge cases you might have missed. Qwen Code can analyze your code paths and suggest tests for error conditions, boundary values, and unexpected inputs that are easy to overlook.226 227## Create pull requests228 229Suppose you need to create a well-documented pull request for your changes.230 231**1. Summarize your changes**232 233```234summarize the changes I've made to the authentication module235```236 237**2. Generate a pull request with Qwen Code**238 239```240create a pr241```242 243**3. Review and refine**244 245```246enhance the PR description with more context about the security improvements247```248 249**4. Add testing details**250 251```252add information about how these changes were tested253```254 255> [!tip]256>257> - Ask Qwen Code directly to make a PR for you258> - Review Qwen Code's generated PR before submitting259> - Ask Qwen Code to highlight potential risks or considerations260 261## Handle documentation262 263Suppose you need to add or update documentation for your code.264 265**1. Identify undocumented code**266 267```268find functions without proper JSDoc comments in the auth module269```270 271**2. Generate documentation**272 273```274add JSDoc comments to the undocumented functions in auth.js275```276 277**3. Review and enhance**278 279```280improve the generated documentation with more context and examples281```282 283**4. Verify documentation**284 285```286check if the documentation follows our project standards287```288 289> [!tip]290>291> - Specify the documentation style you want (JSDoc, docstrings, etc.)292> - Ask for examples in the documentation293> - Request documentation for public APIs, interfaces, and complex logic294 295## Reference files and directories296 297Use `@` to quickly include files or directories without waiting for Qwen Code to read them.298 299**1. Reference a single file**300 301```302Explain the logic in @src/utils/auth.js303```304 305This includes the full content of the file in the conversation.306 307**2. Reference a directory**308 309```310What's the structure of @src/components?311```312 313This provides a directory listing with file information.314 315**3. Reference MCP resources**316 317```318Show me the data from @github: repos/owner/repo/issues319```320 321This fetches data from connected MCP servers using the format @server: resource. See [MCP](./features/mcp) for details.322 323> [!tip]324>325> - File paths can be relative or absolute326> - @ file references add `QWEN.md` in the file's directory and parent directories to context327> - Directory references show file listings, not contents328> - You can reference multiple files in a single message (for example, "`@file 1.js` and `@file 2.js`")329 330## Resume previous conversations331 332Suppose you've been working on a task with Qwen Code and need to continue where you left off in a later session.333 334Qwen Code provides two options for resuming previous conversations:335 336- `--continue` to automatically continue the most recent conversation337- `--resume` to display a conversation picker338 339**1. Continue the most recent conversation**340 341```bash342qwen --continue343```344 345This immediately resumes your most recent conversation without any prompts.346 347**2. Continue in non-interactive mode**348 349```bash350qwen --continue -p "Continue with my task"351```352 353Use `-p` (or `--prompt`) with `--continue` to resume the most recent conversation in non-interactive mode, perfect for scripts or automation.354 355**3. Show conversation picker**356 357```bash358qwen --resume359```360 361This displays an interactive conversation selector with a clean list view showing:362 363- Session summary (or initial prompt)364- Metadata: time elapsed, message count, and git branch365 366Use arrow keys to navigate and press Enter to select a conversation. Press Esc to exit.367 368> [!tip]369>370> - Conversation history is stored locally on your machine371> - Use `--continue` for quick access to your most recent conversation372> - Use `--resume` when you need to select a specific past conversation373> - When resuming, you'll see the entire conversation history before continuing374> - The resumed conversation starts with the same model and configuration as the original375>376> **How it works**:377>378> 1. **Conversation Storage**: All conversations are automatically saved locally with their full message history379> 2. **Message Deserialization**: When resuming, the entire message history is restored to maintain context380> 3. **Tool State**: Tool usage and results from the previous conversation are preserved381> 4. **Context Restoration**: The conversation resumes with all previous context intact382>383> **Examples**:384>385> ```bash386> # Continue most recent conversation387> qwen --continue388>389> # Continue most recent conversation with a specific prompt390> qwen --continue -p "Show me our progress"391>392> # Show conversation picker393> qwen --resume394>395> # Continue most recent conversation in non-interactive mode396> qwen --continue -p "Run the tests again"397> ```398 399## Run parallel Qwen Code sessions with Git worktrees400 401Suppose you need to work on multiple tasks simultaneously with complete code isolation between Qwen Code instances.402 403**1. Understand Git worktrees**404 405Git worktrees allow you to check out multiple branches from the same repository into separate directories. Each worktree has its own working directory with isolated files, while sharing the same Git history. Learn more in the [official Git worktree documentation](https://git-scm.com/docs/git-worktree).406 407**2. Create a new worktree**408 409```bash410# Create a new worktree with a new branch411git worktree add ../project-feature-a -b feature-a412 413# Or create a worktree with an existing branch414git worktree add ../project-bugfix bugfix-123415```416 417This creates a new directory with a separate working copy of your repository.418 419**3. Run Qwen Code in each worktree**420 421```bash422# Navigate to your worktree423cd ../project-feature-a424 425# Run Qwen Code in this isolated environment426qwen427```428 429**4. Run Qwen Code in another worktree**430 431```bash432cd ../project-bugfix433qwen434```435 436**5. Manage your worktrees**437 438```bash439# List all worktrees440git worktree list441 442# Remove a worktree when done443git worktree remove ../project-feature-a444```445 446> [!tip]447>448> - Each worktree has its own independent file state, making it perfect for parallel Qwen Code sessions449> - Changes made in one worktree won't affect others, preventing Qwen Code instances from interfering with each other450> - All worktrees share the same Git history and remote connections451> - For long-running tasks, you can have Qwen Code working in one worktree while you continue development in another452> - Use descriptive directory names to easily identify which task each worktree is for453> - Remember to initialize your development environment in each new worktree according to your project's setup. Depending on your stack, this might include:454> - JavaScript projects: Running dependency installation (`npm install`, `yarn`)455> - Python projects: Setting up virtual environments or installing with package managers456> - Other languages: Following your project's standard setup process457 458## Use Qwen Code as a unix-style utility459 460### Add Qwen Code to your verification process461 462Suppose you want to use Qwen Code as a linter or code reviewer.463 464**Add Qwen Code to your build script:**465 466```json467// package.json468{469 ...470 "scripts": {471 ...472 "lint:Qwen Code": "qwen -p 'you are a linter. please look at the changes vs. main and report any issues related to typos. report the filename and line number on one line, and a description of the issue on the second line. do not return any other text.'"473 }474}475```476 477> [!tip]478>479> - Use Qwen Code for automated code review in your CI/CD pipeline480> - Customize the prompt to check for specific issues relevant to your project481> - Consider creating multiple scripts for different types of verification482 483### Pipe in, pipe out484 485Suppose you want to pipe data into Qwen Code, and get back data in a structured format.486 487**Pipe data through Qwen Code:**488 489```bash490cat build-error.txt | qwen -p 'concisely explain the root cause of this build error' > output.txt491```492 493> [!tip]494>495> - Use pipes to integrate Qwen-Code into existing shell scripts496> - Combine with other Unix tools for powerful workflows497> - Consider using --output-format for structured output498 499### Control output format500 501Suppose you need Qwen Code's output in a specific format, especially when integrating Qwen Code into scripts or other tools.502 503**1. Use text format (default)**504 505```bash506cat data.txt | qwen -p 'summarize this data' --output-format text > summary.txt507```508 509This outputs just Qwen Code's plain text response (default behavior).510 511**2. Use JSON format**512 513```bash514cat code.py | qwen -p 'analyze this code for bugs' --output-format json > analysis.json515```516 517This outputs a JSON array of messages with metadata including cost and duration.518 519**3. Use streaming JSON format**520 521```bash522cat log.txt | qwen -p 'parse this log file for errors' --output-format stream-json523```524 525This outputs a series of JSON objects in real-time as Qwen Code processes the request. Each message is a valid JSON object, but the entire output is not valid JSON if concatenated.526 527> [!tip]528>529> - Use `--output-format text` for simple integrations where you just need Qwen Code's response530> - Use `--output-format json` when you need the full conversation log531> - Use `--output-format stream-json` for real-time output of each conversation turn532 533## Ask Qwen Code about its capabilities534 535Qwen Code has built-in access to its documentation and can answer questions about its own features and limitations.536 537### Example questions538 539```540can Qwen Code create pull requests?541```542 543```544how does Qwen Code handle permissions?545```546 547```548what slash commands are available?549```550 551```552how do I use MCP with Qwen Code?553```554 555```556how do I configure Qwen Code for Amazon Bedrock?557```558 559```560what are the limitations of Qwen Code?561```562 563> [!note]564>565> Qwen Code provides documentation-based answers to these questions. For executable examples and hands-on demonstrations, refer to the specific workflow sections above.566 567> [!tip]568>569> - Qwen Code always has access to the latest Qwen Code documentation, regardless of the version you're using570> - Ask specific questions to get detailed answers571> - Qwen Code can explain complex features like MCP integration, enterprise configurations, and advanced workflows572 